Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IFRs on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting nx expressions 1

Status
Not open for further replies.

defaultrush

Mechanical
Mar 13, 2012
20
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
 
Replies continue below

Recommended for you

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.
 
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.;
 
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.
 
Don't listen to John! -He's only human :)
Go Tools - Expressions - Edit interpart references - Delete Reference / Delete All References.

Regards,
Tomas
 
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.
 
Ok, we're ~50/50 then :)
"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
 
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:
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
 
 http://files.engineering.com/getfile.aspx?folder=2a6702cf-fbb5-4a9b-911a-6d96407d68a7&file=simplifyexpressions.vb
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.
 
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.
 
 http://files.engineering.com/getfile.aspx?folder=cbd9eb87-b8d6-4ec6-81cf-a064f74a9844&file=error.JPG
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
 
 http://files.engineering.com/getfile.aspx?folder=564462fe-fbe7-44be-8d5b-a2494aef7638&file=simplifycomponentexpressions.vb
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 .
 
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
 
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 .
 
Sure

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

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 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
 
 http://files.engineering.com/getfile.aspx?folder=3b851e40-3369-4989-9505-1fd1c9a587ac&file=assemblyCleaner.vb
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:
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

 
 http://files.engineering.com/getfile.aspx?folder=4ae2d185-f4df-4657-948e-df577ac032a3&file=assemblyCleaner.vb
Status
Not open for further replies.

Part and Inventory Search

Sponsor