cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

J-Link: Need help with Part

cbell
1-Newbie

J-Link: Need help with Part

I'm trying to set the material for the current model/part using:

part.RetrieveMaterial("steel");

The issue is defining part. Sample code I have found does something like this:

Part part;

this.part = part;

I can't get this to work. I've already retrieved session and model info, I just don't know about part info.
2 REPLIES 2

Hi Chris -

Since you only provided three lines of your code, I might not
understand your problem correctly. Having said that:

> The issue is defining part. Sample code I have found does something like
this:
>
> Part part;
> this.part = part;

If those are two lines are consecutive, then both part and
this.part point to null (nothing). Invoking any instance
methods from either part or this.part will throw an exception.

> I can't get this to work. I've already retrieved session
> and model info, I just don't know about part info.

I'm going to assume that you have the CURRENT model in Pro/E,
which your program expects to be part.

In the JLink API, Part extends Solid, and Solid extends Model.
In other words, anything that is a Part is also a Model, but
not vice-versa. So, if you have the active model already
assigned to the variable activeModel, and you want to make
sure it's a part, you can do something like this:

ModelType type ;

type = activeModel.GetType() ;

if ( type.equals( ModelType.MDL_PART )) {
this.part = ( Part ) activeModel ;
} else {
// Notify the user that the active model is not a part
}

Of course, you need to wrap this code on one or more try-catch
blocks. I hope this helps.

|+| M a r k |+|

Mark Stallard
Engineering Information Management
Integrated Solutions & Development
Integrated Defense Systems
Raytheon Company



(business)
+1.978.436.6016
(cell)
+1.617.331.5443
(tie line)
239.6016
-

880 Technology Drive
Billerica, MA 01821
www.raytheon.com


This message contains information that may be confidential and privileged.
Unless you are the addressee (or authorized to receive mail for the
addressee), you should not use, copy or disclose to anyone this message or
any information contained in this message. If you have received this
message in error, please so advise the sender by reply e-mail and delete
this message. Thank you for your cooperation.





cbell
1-Newbie
(To:cbell)

Thanks Mark. I'll give this a try. Another solution I got is:

Part part = (Part)model;

Which works but yours also checks for the correct type. Thanks.

In Reply to Mark Stallard:

In the JLink API, Part extends Solid, and Solid extends Model.
In other words, anything that is a Part is also a Model, but
not vice-versa. So, if you have the active model already
assigned to the variable activeModel, and you want to make
sure it's a part, you can do something like this:

ModelType type ;

type = activeModel.GetType() ;

if ( type.equals( ModelType.MDL_PART )) {
this.part = ( Part ) activeModel ;
} else {
// Notify the user that the active model is not a part
}





Top Tags