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

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
 
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...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor