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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Enumeration Values in Weblink

Mat
13-Aquamarine
13-Aquamarine

Enumeration Values in Weblink

When You use Weblink for Creo, You often have to use enumeration values like "pfcModelType".

To get the current type of a current model, You run something like

oSession = pfcCreate("MpfcCOMGlobal").GetProESession();

model_type = oSession.CurrentModel.Type;

This give You a number, where 0 stands for an assemble, 1 for a part and so on.

You could use this in Your code to controll some actions, like

if (model_type == 0) {

     // do something with this assembly

     }

if (model_type == 1) {

     // do something with this part

     }

Using this particular numbers in Your code can have some downsides. Firstly You can mix up the numbers. For instance You want to do something with a drawing, but Your code waits for an assembly to occur. The code also is not that human readable. A second developer might not be that familiar with those numbers. And lastly, in a new version of Creo there would be a chance, that the number changes (0 = part, 1 = assembly).

So it is better practise to use enumerations values as described in the API description. Where MDL_ASSEMBLY stands for an assemble, MDL_PART for a part and so on.

But a code like this would not work and would cause an error:

if (model_type == MDL_ASSEMBLY) {

     // do something with this assembly

     }

Because You would compare a number with an undefined object. It would also not be very helpful to pack MDL_ASSEMBLY in quotes.

To "convert" MDL_ASSEMBLY to a number, You have to run this to get the corresponding enumeration value:

pfcCreate("pfcMaterialPropertyType").MDL_ASSEMBLY;

So Your working code would look like this:

if (model_type == pfcCreate("pfcMaterialPropertyType").MDL_ASSEMBLY) {

     // do something with this assembly

     }

if (model_type == pfcCreate("pfcMaterialPropertyType").MDL_PART) {

     // do something with this part

     }

In general You can say that, if You want to get a certain enumeration value number, You have to run

var enumeration_value_number = pfcCreate(<<enumeration-type>>).<<enumeration-value>>;


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
0 REPLIES 0
Top Tags