NX Journal C# => write name of selected expression into string

85 views Asked by At

I am not able to read the name of a selected expression (marked in details tab of Part Navigator) into a string to use it later in the code to address the selected expression.

NX Version is 2206.9102

Thank you for your support.

The goal is to click on an expression and start a journal to rename and change the selected expression by importing an expression file.

For speeding up the whole process, this should be done in the details tab of the part navigator. Select a feature first and select expression afterwards before starting the journal (via user command button that is triggering the journal)

screenshot of details tab

For renaming I was able to extract and use this function:

NXOpen.Expression expression1 = ((NXOpen.Expression)workPart.Expressions.FindObject("p257"));
workPart.Expressions.Rename(expression1, "NEW_EXP");

Importing expression file is also done.

The record for renaming is specific for expression "p257" and this is the core problem since the name will be different each time and therefore we need a string input here.

The solution should be easy to use with basic out of the box features since I will not be able to do changes in the system itself (working as enduser in a big corporation).

C# preferred but VBA would also help a lot.

I tried using own code, several code i found in the interwebs, tried to record with the journal tool or created by ChatGPT but nothing worked for me.

For example AskSelectedObjects, GetExpressionName for selected Objetcs, GetAttributeExpression in different attempts.

Unfortunately I never learned programming so basically a noob with some self-taught experience and very less knowledge what is happening inside C# or how NX journaling is addressing different objects. So in 95% of the cases I am adapting pre-recorded code.

Please understand that I am not allowed to share a lot of information.

0

There are 0 answers