Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
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
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?
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.
Try this:
IF material_param("custom3")!=""
....
ENDIF
My mistake. I misunderstood the question.
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.
