Wednesday, September 26, 2007

2-way interaction between Expressions and Attributes

Using a little bit of Knowledge Fusion functions, it's easily possible to interact expressions with attributes, and vice versa.

Suppose you have 3 expressions called 'length', 'width' and 'height' and you'd like to automatically update the part attributes called ATTR_length, ATTR_height and ATTR_width accordingly.

(Why in the earth would I want to do that, you might ask- these values could well be part list columns, or some dirty ERP trick might be the case. Actually I need neither, but it's good to know that this can be done !)

In the Expressions window, you need to create a dummy number expression, say 'test'. This needs to be a number, not a string variable.

Then you need to set the value of 'test' using the following syntax :
  • test = ug_setPartAttrValue( "ATTR_length", stringValue(length) )
stringValue is another KF function to convert a numeric value into a string, which ug_setPartAttrValue requires.

You can also get the value of an existing attribute, and assign it to an expression. This time, the syntax is :
  • test2 = MakeNumber( ug_askPartAttrValue( "ATTR_width" ))
where test2 is the expression to be updated.

In order not to have lots of these dummy test variables, you could create a combined dummy, like:
  • test = ug_setPartAttrValue( "x", stringValue( p1) ) + ug_setPartAttrValue( "y", stringValue( p2) ) +ug_setPartAttrValue( "z", stringValue( p3) )

11 comments:

Frank Malone said...
This comment has been removed by the author.
Frank Malone said...

Wow!!! I've just discovered (today) your blog. Seems wonderfull.

I was searching for this functionality long time ago. And now I have discovered it is in your blog since september.

Do you know what license is needed to use this functionality?

Frank.

Hakan Sonmezler said...

Frank,
thanks for your encouraging comments!

Only gateway/modeling is enough for this functionality.

Google recently indexed my page, that's why you might not have come across before..

Frank Malone said...

Hi, I have tested the tricks, and I have a problem.

In the first case, the attribute is updated when the expression changes, but in the second, the expression is not updated when the attribute changes.

Any suggestions.

Thanks.

Hakan Sonmezler said...

Hi Frank,

I guess you're right. In the first case, when you hit the OK button for expressions dialog, the attribute is updated properly. But in the second case, expressions are not aware of the fact that the attribute has changed. You can use theTools->Update->Update for External Change command to trigger this.

Hakan Sonmezler said...

Actually this is no different from the case when an expressions value is linked to an Excel cell. You need to update manually for that as well.

Anonymous said...

Great blog. Here is a question on knowledge fusion that I haven't found the answer to:

How do I create a multiple patch through curve surface in NX that can be used in Knowledge Fusion, and be suppressed from there?

Linus

Hakan Sonmezler said...

Linus,

Unfortunately this question is beyond my very limited experience on KF..

Thanks for the compliment by the way..

hoping to have some (like a 3 month holiday!) spare time for KF in the future,
Hakan

Pranav C Lunavat said...

I was searching for the same. Thanks a Lot for for posting it.
I have a problem, I am working in assembly and import various expression file to update the complete assy. Having done as per your guidelines the Part attributes are created once, but doesnt update when expression file is imported till i manually go into each part and open expression window and update the dummy variable for attributes.
Could you please help..

Fabio said...

Hello Hakan are you still working on NX?
I have a question about this your old post.

I have a column in my template parts list called "Code" and I'd like its filled by .
I know that I can set column to automatically taken the but I need "Code" column because most parts had
Code = part name
while some others had
Code = partial part name
and few others had
Code = nothingf to do with part name

There is a way to automatically write in a parts list column?

Thank you

Admin said...

Industrial equipment suppliers play a vital role in supporting manufacturing and production processes. These suppliers offer a wide range of machinery, tools, and technologies tailored to diverse industrial needs. By ensuring the availability of high-quality equipment, they contribute to operational efficiency and output consistency. Find and refer UAE Industrial Equipment Supplier for more relevant info.