Showing results for 
Search instead for 
Do you mean 

Edit NX Expressions Through WinForms



I have created a Windows Form in VB.Net, which shows Existing expressions in TextBoxes, and allow user to edit it. When user hits OK it will modify the values in NX Expressions.And Model will be updated.


I don't know much about coding. I have just copied paste the code and modified and it ran.


Now I am stuck with some Logic. What I want is that-

- User may able to edit the Both -'Name & Values' of Expressions-Which is linked to NX expressions - i.e. changes in NX expressions 's Name & Value should be updated in WinForm & vice versa.


But from the following code , I am just able to modify the Values of expressions , not the Name.


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim exp1 As NXOpen.Expression = CType(workPart.Expressions.FindObject("p1"), NXOpen.Expression)
Dim exp2 As NXOpen.Expression = CType(workPart.Expressions.FindObject("p2"), NXOpen.Expression)
Dim exp3 As NXOpen.Expression = CType(workPart.Expressions.FindObject("p3"), NXOpen.Expression)
Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
Dim markId1 As Session.UndoMarkId
workPart.Expressions.EditWithUnits(exp1,Unit1, TextBox1.Text)
workPart.Expressions.EditWithUnits(exp2,Unit1, TextBox2.Text)
workPart.Expressions.EditWithUnits(exp3,Unit1, TextBox3.Text)
theSession.Preferences.Modeling.UpdatePending = False
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
End Sub


Above codes edit/replace the expressions' value with the input value (values put in textboxes)

But if expression P1 is renamed in NX by any user , as suppose X1 , it will not update to userform as code will just try to find P1.


So plesae help me to link nx expressions to WinFoms in such a way that user can edit Name & Value.





Re: Edit NX Expressions Through WinForms

[ Edited ]

Hi @Vivek_LnT


here is your solution.


Dim expression1 As Expression
expression1 = CType(workPart.Expressions.FindObject("P1"), Expression)


'here I change the expression name from P1 to textboxname input

expression1 .SetName ( TextBoxName.Text )


'here I change the expression value from to textboxvalue input




hope it helps.




Re: Edit NX Expressions Through WinForms

Hiii @Abhi_Learner


Thanks for reply!!


Your code can solve the issue but still having concern from this line.


Dim expression1 As Expression
expression1 = CType(workPart.Expressions.FindObject("P1"), Expression)


First time it is finding the expression based on the Name of Expression i.e. P1 - so in case if I rename it in NX, journal will not able to find P1 and fail.So that is keep stinging.




Re: Edit NX Expressions Through WinForms

Hi @Vivek_LnT


Please tell me if my understanding is wrong.

I feel,

You need that expression to modify again and again using the app?


If this is the scenario ,

here how you should go,


1. In code you should search for "MyFirstExpression" in My.Load

2. If it's not existing then, assign that name ("MyFirstExpression") for the expression by renaming "P1".

3. Now you should change the value for "MyFirstExpression" expression only, not P1.


From next time launch,

As "MyFirstExpression"  exists , you need not to rename P1 to "MyFirstExpression".

You can directly assign the value for that expression.


Is it clear now?





Re: Edit NX Expressions Through WinForms

@Hi @Vivek_LnT


Did you gert the answer what you were looking for?




Re: Edit NX Expressions Through WinForms

Hii @Abhi_Learner


As I am Mechanical Engg. it is being more difficult to control/validate userform through NX journaling and specially to solve my expression issue. So now I am skipping to make this userform.


But I appriciate help from Siemens Community. But my lack of programming languages is a limitation.




Re: Edit NX Expressions Through WinForms

No problem.

Re: Edit NX Expressions Through WinForms

Hiii Abhi,


I just try to simplify my query, and try to solve my query.


Query : Link Desired NX expressions to WinForm


Background : (These below things are already done before Playing Journal)

1) I have an Assembly with 10 Expressions (Example)

2) Among 10 expressions , I am interested in only 5 expressions.

3) I add comment "Interested"  to those 5 expressions by going to Tools->Expressions-> (Expression I'm Interested in) -> Edit Comment -> (Enter the Comment : Interested)

So I can just get those 5 expressions only in which I am interested. (I dont want to prefere going with Comments - you can suggest any other simple/easy logic to derive REQUIRED expressions among bunch of expressions)


What I want to do :


1) User Play the Journal

2) Journal launches  WinForm

3) Journal will go to the all expressions in Tools->Expressions->Comment

5) It will derive only those expressions in which Comment field : Interested  is written.

6) Now WinForm shows  the Name and Values of those 5 expressions I am interested in, in TextBoxes

5) User selects his required Expressions, Edit the Name/Value in TextBoxes. Hits OKAY

6) Assembly is updated.


I hope my query & Logic sequence to solve my query are clear and simplified than my previous posts.


This is a conceptual sequence I thought and u can suggest easy steps , loops,logic etc to simplify as I dont know much about programming.

If I can get full example code for above sequences, It will be very very much useful to our customer & Business.






Re: Edit NX Expressions Through WinForms

Is this thread closed ?

Re: Edit NX Expressions Through WinForms

No, It's not. As you said it was not required so I didn't look further.
Now I will look again and let you know.