Cancel
Showing results for 
Search instead for 
Did you mean: 

How to change the Color of UDF after instantiation ?

Experimenter
Experimenter

I want to change the color of UDF after instantiation with an expression .
I have tried using Child rule .
My observation is that the rule always uses the last value irrespective of the condidtion.
I have created an Expression

If ( Test =10 )
Then ( 10 )
Else (120 );

In the above case ,color 120 is assigned even if the Test value is 10 .
The color changes in the original part model in which the UDF is made but not after instantiation.
It is made in NX twelve.1.JPG2.JPG

3 REPLIES 3

Re: How to change the Color of UDF after instantiation ?

Siemens Phenom Siemens Phenom
Siemens Phenom

Your KF rule

 

If ( Test = 10 ) Then ( 10 ) Else (120 );

 

simply does not know what "Test" here refers to.

 

Try something like this instead:

 

If (ug_askExpressionValue_(ug_askCurrentWorkpart(),"Test") = 10) Then (10) Else (120);

 

Re: How to change the Color of UDF after instantiation ?

Experimenter
Experimenter

Hi Beetle,

Thanks for your help .
The color changes after instantiation but only once after the expression value of "Test" is changed .
When I change the value of the expression "Test" for the second time after instantiation then the color does not change.


I used the below code

If (ug_askExpressionValue_(ug_askCurrentWorkpart(),"Test") == 10 )
Then ( 10 )
Else ( 120 );

 

The color should change each time the value of "Test" is changed .

Re: How to change the Color of UDF after instantiation ?

Siemens Phenom Siemens Phenom
Siemens Phenom

When you instantiate an UDF, the referenced expression <Test> will be renamed with an index like <Test_5> but the KF rule still refers to <Test>.

And there is no "demand" to update the KF rule when you change the expression.

 

To overcome this, you may try to create the expression from KF instead and then reference the expression child rule directly before exporting the UDF from it.

 

(Child) SOLID_body: {
 Class, ug_body; 
 Feature, {ug_refObject("Extrude(3):C-29-4","")}; 
 Density, {7830.64}; 
 Color, If (TestExp:value: = 10) Then (10) Else (120); 
 Layer, 1; 
 Reference_Sets, {}; 
 Suppress?, FALSE; 
 Units, Grams_And_Millimeters; 
}; 

(Child) TestExp: {
 Class, ug_expression; 
 Name, "Test"; 
 value, 10; 
}; 

If you then edit the expession, it updates the connected KF rules, as well.

 

See also Add Child Rule Overview