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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Translate the entire conversation x

Can I use material_param("custom") function when the "custom" material attribute may not exist?

N.Barnes
14-Alexandrite

Can I use material_param("custom") function when the "custom" material attribute may not exist?

Creo 10.0.8.0

In our material library I want to be able to add the common material designations as custom attributes in the material file.   THEN, I want to use a relation to automatically populate the material attribute MATL_SPEC with the material attribute when it exists.

 

But I have found then when the "custom" material property doesn't exist the relations fail.  I tried using the "exists()" function to check, but the equation fails before getting to the "exists()" function.

 

This is the equation I was trying to use.  When "custom" exists, it works, but if "custom" doesn't exist it fails.

if exists(material_param("custom"))
test=material_param("custom")
endif

NBarnes_0-1764090023069.png

 

Also, I've found then when "custom" does exist, I don't actually enter into the "do" part of the IF statement.

 

Is there another recommended work-around or relation function structure I can try?

4 REPLIES 4
KenFarley
21-Topaz II
(To:N.Barnes)

You have to think about the calling sequence of functions you're using:

Your IF statement  is using EXISTS( ) which needs a string argument.

The string argument you are attempting to use is what is returned by material_param("custom3").

material_param needs a valid parameter name. Attempting to pass it custom3 when that argument does not exist in the material definition results in an error.

That error probably results in the function returning nothing, or a numeric result, or it just causes execution to fail. Either way, the EXISTS() function is not getting anything good.

Even when you use a valid name for material_param(), the EXISTS() function is going to be returning a result indicating whether the value returned by it exists in the model. i.e. if the value of custom in the material is "APPLE", your IF statement is based on the value of EXISTS ( "APPLE" ). If there's no dimension or parameter in the model with the name "APPLE", your IF statement will not be executed. It's not evaluating whether the parameter exists in the material definition.

Voronov
4-Participant
(To:N.Barnes)

Try this:

IF material_param("custom3")!=""

....

ENDIF

Voronov
4-Participant
(To:Voronov)

My mistake. I misunderstood the question.

Voronov
4-Participant
(To:N.Barnes)

I created a simple application. It adds a custom function to relations: exists_mtrl_prm(). It takes an argument—the name of the parameter to be checked in the current material. It returns either its value, if it exists, or NULL, if the parameter doesn't exist. Any type is converted to a string.

emp_app.png

(Virus scan in progress ...)
Announcements
NEW Creo+ Topics: Real-time Collaboration

Top Tags