×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

deleting nx expressions

deleting nx expressions

deleting nx expressions

(OP)
hi,

i am trying to figure out a way to clear/delete all expressions and interpart data from a ug model , is there a command in ug to do this or is it possible to create a macro or jounal for it . any help would be appreciated...

cheers......

chetan herur

RE: deleting nx expressions

If you willing to accept the fact that if you "...clear/delete all expressions and interpart data..." from you Part model, that this will remove all features and paratmeters from the model as well (i.e. make it a 'dumb' model), then there are a couple of approaches that you could take.

The quickest way to do this would be to go to...

File -> Export -> Part...

...and with the 'Feature Parameters' option set to 'Remove Parameters', select all of the bodies and curves which you wish to retain in their 'dumb' state, enter the name of new file and hit OK. Now you'll have a new part file with all of the features and parameters removed.

An alternative, in case you don't want to create a new Part file, is to go to...

Edit -> Feature -> Remover Parameters...

...select all of the features in the Part model and hit OK. You may still need to go to open the Expression dialog and delete any leftover expressions.

BTW, why are you so interested in "...clearing/deleteing all expressions and interpart data..." from your Part model?

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.

RE: deleting nx expressions

(OP)
what i actually intend to do is clear all the expressions/inter-part data so that the value should remain and the part is still parametric , in fact we have a number of parts and a assembly which uses inter-part link and values from a external spread sheet ,the product when complete should have no trace of expressions/interpart data or reference to the values borrowed from the external spreadsheet.;

RE: deleting nx expressions

You'll have to edit each expression manually (or write some sort of NX Open application to replace the externally referenced expressions with some acceptable value since they have to be set equal to something). Once they have been edited, the external spreadsheet can be deleted and you should be good to go.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.

RE: deleting nx expressions

(OP)
thank you....

RE: deleting nx expressions

Don't listen to John! -He's only human smile
Go Tools - Expressions - Edit interpart references - Delete Reference / Delete All References.

Regards,
Tomas

RE: deleting nx expressions

This will take care of 'InterPart Expressions': Expressions linked to Expressions in other Part files, but it will have NO effect whatsoever on Expressions reading values from an external spreadsheet, which, if I read the OP's request correctly, is what he's actually looking for.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.

RE: deleting nx expressions

Ok, we're ~50/50 then smile
"a number of parts and a assembly which uses inter-part link and values from a external spread sheet"

Maybe the cleaning can be simplified by exporting the expressions to a separate file, clean the external file , import.
( Tools- expression - export expressions to file and Import...)
Sadly the expression in the text file only shows as expression, not the current value.
i.e
ug_excel_read( "C:\temp\Book1.xlsx", "B2" )
and not that the current value of cell "B2" happens to be "100"



Regards,
Tomas

RE: deleting nx expressions

The following example nxopen/journal works on the displayed part and will replace the right hand side formula of any numerical expression with the evaluated value.

CODE --> vb.net

Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Module simplify_expressions Dim s As Session = Session.GetSession() Sub Main() Dim dp As Part = s.Parts.Display Dim exps() As Expression = dp.Expressions.ToArray() For Each thisExp As Expression In exps If thisExp.Type.ToString().Contains("Number") Then dp.Expressions.Edit(thisExp, thisExp.Value().ToString()) End If Next End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer Return Session.LibraryUnloadOption.Immediately End Function End Module

RE: deleting nx expressions

(OP)
works like a charm.....thank you so much......bye

RE: deleting nx expressions

I guess the moral of this story is; if there isn't a way for NX to do what you want, then there is a way for you to make NX do what you want.

RE: deleting nx expressions

(OP)
it seems that the journal by petulf works fine in nx8 but shows a error in nx 7.5 (screenshot attached) . and it would be better if someone could figure out a way to remove the expression from all parts in an assembly . this one does the job for only displyed part that too only in nx8.

RE: deleting nx expressions

The error you are getting in 7.5 is most likely a culture error due to the toString() method converting "." to ","
the following code fixes that.

CODE -->

Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Module simplify_expressions Dim s As Session = Session.GetSession() Dim enUS As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US") Sub Main() Dim dp As Part = s.Parts.Display Dim exps() As Expression = dp.Expressions.ToArray() For Each thisExp As Expression In exps If thisExp.Type.ToString().Contains("Number") Then dp.Expressions.Edit(thisExp, thisExp.Value().ToString(enUS)) End If Next End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer Return Session.LibraryUnloadOption.Immediately End Function End Module

The following code uses a recursive function to find the unique parts in a assembly with the displayed part as root. It then loops over the parts and "simplifies" the expressions. As always the code is provided as is, I would not run it on anything critical before testing that it works in your environment.

CODE -->

Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Imports NXOpen.Assemblies Module simplifyComponentExpressions Dim s As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession Dim lw As ListingWindow = s.ListingWindow Dim uniqueParts As New Collections.Generic.List(Of Part) Dim enUS As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US") Sub getUniqueParts(ByVal theComponent As Component) Dim children As Component() = theComponent.GetChildren() For Each child As Component In children If Not child.Prototype Is Nothing Then Dim childPart As Part = CType(child.Prototype.OwningPart, Part) If Not uniqueParts.Contains(childPart) Then uniqueParts.Add(childPart) End If End If getUniqueParts(child) Next End Sub Sub simplifyExpressions(ByVal thePart As Part) lw.WriteLine(thePart.JournalIdentifier) For Each exp As Expression In thePart.Expressions If exp.Type.Contains("Number") Then Dim debugString As String = exp.Equation + " -> " + exp.Value.ToString(enUS) thePart.Expressions.Edit(exp, exp.Value.ToString(enUS)) lw.WriteLine(debugString) End If Next End Sub Sub Main() lw.Open() Try Dim rootComponent As Component = s.Parts.Display.ComponentAssembly.RootComponent uniqueParts.Add(s.Parts.Display) getUniqueParts(rootComponent) For Each PartItem As Part In uniqueParts simplifyExpressions(PartItem) Next Catch ex As Exception lw.WriteLine(ex.Message) End Try End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer Return Session.LibraryUnloadOption.Immediately End Function End Module

RE: deleting nx expressions

(OP)
thanks for the post by petulf

the second code works well on nx7.5 but as i have used measure in the some parts the program stops at measure snd does not continue further. it would be great if the program could be modified to skip measure and continue to simplify the expression .

RE: deleting nx expressions

Here is a quick fix that skips expressions that belong to measurements.

CODE -->

Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Imports NXOpen.Assemblies Module simplify_component_expressions Dim s As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession Dim lw As ListingWindow = s.ListingWindow Dim uniqueParts As New Collections.Generic.List(Of Part) Dim enUS As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US") Sub getUniqueParts(ByVal theComponent As Component) Dim children As Component() = theComponent.GetChildren() For Each child As Component In children If Not child.Prototype Is Nothing Then Dim childPart As Part = CType(child.Prototype.OwningPart, Part) If Not uniqueParts.Contains(childPart) Then uniqueParts.Add(childPart) End If End If getUniqueParts(child) Next End Sub Sub simplifyExpressions(ByVal thePart As Part) lw.WriteLine(thePart.JournalIdentifier) For Each exp As Expression In thePart.Expressions If exp.Type.Contains("Number") And Not exp.IsMeasurementExpression Then Dim debugString As String = exp.Equation + " -> " + exp.Value.ToString(enUS) thePart.Expressions.Edit(exp, exp.Value.ToString(enUS)) lw.WriteLine(debugString) End If Next End Sub Sub Main() lw.Open() Try uniqueParts.Add(s.Parts.Display) If Not s.Parts.Display.ComponentAssembly.RootComponent Is Nothing Then Dim rootComponent As Component = s.Parts.Display.ComponentAssembly.RootComponent getUniqueParts(rootComponent) End If For Each PartItem As Part In uniqueParts simplifyExpressions(PartItem) Next Catch ex As Exception lw.WriteLine(ex.Message) End Try End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer Return Session.LibraryUnloadOption.Immediately End Function End Module

RE: deleting nx expressions

(OP)
thank you "petulf "this one works really good ....one more favour, if its not too much to ask, would it be possible to create a journal which deletes suppresses parts in assembly and suppressed features in parts. the journal should run in assembly mode .

RE: deleting nx expressions

Sure

Here is an extended program that "cleans" the assembly of any supressed components, supressed features and expression formulas.

CODE --> vb.net

Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Imports NXOpen.Assemblies Module simplify_component_expressions Dim s As Session = Session.GetSession() Dim lw As ListingWindow = s.ListingWindow Dim uniqueParts As New Collections.Generic.List(Of Part) Dim enUS As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US") Sub getUniqueParts(ByVal theComponent As Component) Dim children As Component() = theComponent.GetChildren() For Each child As Component In children If child.IsSuppressed Then Dim deleteComponentUndoMark As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Visible, "Delete Component") Try lw.WriteLine(child.JournalIdentifier + " is suppressed and will be deleted.") s.UpdateManager.AddToDeleteList(CType(child, NXObject)) s.UpdateManager.DoUpdate(deleteComponentUndoMark) Catch ex As Exception End Try Else If Not child.Prototype Is Nothing Then Dim childPart As Part = CType(child.Prototype.OwningPart, Part) If Not uniqueParts.Contains(childPart) Then uniqueParts.Add(childPart) End If End If getUniqueParts(child) End If Next End Sub Sub deleteSupressedFeatures(ByVal thePart As Part) Dim featuresToDelete As New Collections.Generic.List(Of NXObject) For Each theFeature As Features.Feature In thePart.Features If theFeature.Suppressed Then lw.WriteLine(" "+theFeature.JournalIdentifier + " is supressed and will be deleted.") featuresToDelete.Add(theFeature) End If Next Try Dim featureDeleteUndoMarkId As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Visible, "Features Deleted") s.UpdateManager.AddToDeleteList(featuresToDelete.ToArray()) s.UpdateManager.DoUpdate(featureDeleteUndoMarkId) Catch ex As Exception End Try End Sub Sub simplifyExpressions(ByVal thePart As Part) For Each exp As Expression In thePart.Expressions If exp.Type.Contains("Number") Then Dim debugString As String =" "+ exp.Equation + " -> " + exp.Value.ToString(enUS) thePart.Expressions.Edit(exp, exp.Value.ToString(enUS)) lw.WriteLine(debugString) End If Next End Sub Sub Main() lw.Open() Try s.UpdateManager.ClearErrorList() Dim rootComponent As Component = s.Parts.Display.ComponentAssembly.RootComponent uniqueParts.Add(s.Parts.Display) getUniqueParts(rootComponent) For Each PartItem As Part In uniqueParts lw.WriteLine("Working on part " + PartItem.JournalIdentifier) deleteSupressedFeatures(PartItem) simplifyExpressions(PartItem) lw.WriteLine("Finished processing part ") Next Catch ex As Exception lw.WriteLine(ex.Message) End Try End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer Return Session.LibraryUnloadOption.Immediately End Function End Module

RE: deleting nx expressions

Feature group deletion turned out to need only a small code change. One needed to set a boolean switch to allow the deletion of it and its members. Component array interaction requires the use of wrapped UF functions which leads to more involved code. Thus my suggestion is to instead delete all arrays manually before running the journal.

CODE --> vb.net

Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Imports NXOpen.Assemblies Module simplify_component_expressions Dim s As Session = Session.GetSession() Dim lw As ListingWindow = s.ListingWindow Dim uniqueParts As New Collections.Generic.List(Of Part) Dim enUS As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US") Sub getUniqueParts(ByVal theComponent As Component) Dim children As Component() = theComponent.GetChildren() For Each child As Component In children If child.IsSuppressed Then Dim deleteComponentUndoMark As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Visible, "Delete Component") Try lw.WriteLine(child.JournalIdentifier + " is suppressed and will be deleted.") s.UpdateManager.AddToDeleteList(CType(child, NXObject)) s.UpdateManager.DoUpdate(deleteComponentUndoMark) Catch ex As Exception End Try Else If Not child.Prototype Is Nothing Then Dim childPart As Part = CType(child.Prototype.OwningPart, Part) If Not uniqueParts.Contains(childPart) Then uniqueParts.Add(childPart) End If End If getUniqueParts(child) End If Next End Sub Sub deleteSupressedFeatures(ByVal thePart As Part) Dim featuresToDelete As New Collections.Generic.List(Of NXObject) For Each theFeature As Features.Feature In thePart.Features If theFeature.Suppressed Then lw.WriteLine(" " + theFeature.JournalIdentifier + " is supressed and will be deleted.") If TypeOf theFeature Is Features.FeatureGroup Then CType(theFeature, Features.FeatureGroup).AllowDeleteMembers = True End If featuresToDelete.Add(theFeature) End If Next Try Dim featureDeleteUndoMarkId As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Visible, "Features Deleted") s.UpdateManager.AddToDeleteList(featuresToDelete.ToArray()) s.UpdateManager.DoUpdate(featureDeleteUndoMarkId) Catch ex As Exception End Try End Sub Sub simplifyExpressions(ByVal thePart As Part) For Each exp As Expression In thePart.Expressions If exp.Type.Contains("Number") Then Dim debugString As String = " " + exp.Equation + " -> " + exp.Value.ToString(enUS) thePart.Expressions.Edit(exp, exp.Value.ToString(enUS)) lw.WriteLine(debugString) End If Next End Sub Sub Main() lw.Open() Try s.UpdateManager.ClearErrorList() Dim rootComponent As Component = s.Parts.Display.ComponentAssembly.RootComponent uniqueParts.Add(s.Parts.Display) getUniqueParts(rootComponent) For Each PartItem As Part In uniqueParts lw.WriteLine("Working on part " + PartItem.JournalIdentifier) deleteSupressedFeatures(PartItem) simplifyExpressions(PartItem) lw.WriteLine("Finished processing part ") Next Catch ex As Exception lw.WriteLine(ex.Message) End Try End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer Return Session.LibraryUnloadOption.Immediately End Function End Module

RE: deleting nx expressions

Okay i went through the c UF reference documentation and found the component array functions that allows me to ask if a component instance belongs to an array and subsequently deleting that array. I also reworked feature group deletion code as it seems to work more consistently if i set the part as work part before trying to delete the features.

CODE -->

Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Imports NXOpen.Assemblies Module AssemblyCleaner Dim s As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession() Dim lw As ListingWindow = s.ListingWindow Dim uniqueParts As New Collections.Generic.List(Of Part) Dim enUS As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US") Sub getUniqueParts(ByVal theComponent As Component) Dim children As Component() = theComponent.GetChildren() For Each child As Component In children If child.IsSuppressed Then Dim deleteComponentUndoMark As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Visible, "Delete Component") Dim numArrays As Integer = Nothing Dim compArrays() As Tag = Nothing Dim childInstanceTag As Tag = ufs.Assem.AskInstOfPartOcc(child.Tag) ufs.Assem.AskArraysOfInst(childInstanceTag, numArrays, compArrays) For Each arrayItem As Tag In compArrays Try lw.WriteLine(child.JournalIdentifier + " belongs to array which will be deleted") ufs.Assem.DeleteArray(arrayItem, False) Catch ex As Exception End Try Next Try lw.WriteLine(child.JournalIdentifier + " is suppressed and will be deleted.") s.UpdateManager.AddToDeleteList(CType(child, NXObject)) s.UpdateManager.DoUpdate(deleteComponentUndoMark) Catch ex As Exception End Try Else If Not child.Prototype Is Nothing Then Dim childPart As Part = CType(child.Prototype.OwningPart, Part) If Not uniqueParts.Contains(childPart) Then uniqueParts.Add(childPart) End If End If getUniqueParts(child) End If Next End Sub Sub deleteSupressedFeatures(ByVal thePart As Part) s.Parts.SetWork(thePart) Dim featuresToDelete As New Collections.Generic.List(Of NXObject) For Each theFeature As Features.Feature In thePart.Features If theFeature.Suppressed Then lw.WriteLine(" " + theFeature.JournalIdentifier + " is supressed and will be deleted.") If TypeOf theFeature Is Features.FeatureGroup Then CType(theFeature, Features.FeatureGroup).AllowDeleteMembers = True End If featuresToDelete.Add(theFeature) End If Next Try Dim featureDeleteUndoMarkId As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Visible, "Features Deleted") Dim nErrors As Integer = s.UpdateManager.AddToDeleteList(featuresToDelete.ToArray) s.UpdateManager.DoUpdate(featureDeleteUndoMarkId) Catch ex As Exception End Try End Sub Sub simplifyExpressions(ByVal thePart As Part) For Each exp As Expression In thePart.Expressions If exp.Type.Contains("Number") Then Dim debugString As String = " " + exp.Equation + " -> " + exp.Value.ToString(enUS) thePart.Expressions.Edit(exp, exp.Value.ToString(enUS)) lw.WriteLine(debugString) End If Next End Sub Sub Main() lw.Open() Try s.UpdateManager.ClearErrorList() Dim rootComponent As Component = s.Parts.Display.ComponentAssembly.RootComponent uniqueParts.Add(s.Parts.Display) getUniqueParts(rootComponent) For Each PartItem As Part In uniqueParts lw.WriteLine("Working on part " + PartItem.JournalIdentifier) deleteSupressedFeatures(PartItem) simplifyExpressions(PartItem) lw.WriteLine("Finished processing part ") Next s.Parts.SetWorkComponent(rootComponent, Nothing) Catch ex As Exception lw.WriteLine(ex.Message) End Try End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer Return Session.LibraryUnloadOption.Immediately End Function End Module

RE: deleting nx expressions

(OP)
awesome...works great...thank you so much.....it is really hard to find stuff on NXopen , we have been trying to learn this for a long time....it would be great if u could give us some tips on how to start ....share some reference material or websites ,u seem to be very good at this.....thank you one again...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources