cancel
Showing results for 
Search instead for 
Did you mean: 

get expression of suppresed component by "suppress by expression"

Genius
Genius

Hi All,

 

My journal cycles the assembly and detects if the components are suppressed.

I'm able to detect if the component is suppressed by expression by reading the errorlist.

But I need to get the expression that steers the suppression.

 

Any ideas how to get this expression?

 

Thanks,

Fred

Sub UnsuppressComponent(cmp1 As Component)
        'unsuppress this component

        Dim errorList1 As ErrorList
        errorList1 = cmp1.Unsuppress({cmp1})

        If errorList1.Length > 0 Then
            For ii As Integer = 0 To errorList1.Length - 1
                'suppressed by expression
                Dim errInfo As ErrorInfo = errorList1.GetErrorInfo(ii)
                lw.WriteLine(errInfo.ErrorCode)
                lw.WriteLine(errInfo.Description)

                If errInfo.ErrorCode = 650027 Then
                    'suppressed by expression

                    '????HOW TO GET EXPRESSION NAME????
                End If
            Next
        End If
        errorList1.Dispose()
    End Sub

 

3 REPLIES

Re: get expression of suppresed component by "suppress by expression"

Phenom
Phenom

I've not used it, but I'd give the .AskSuppressionExp method a try.

Re: get expression of suppresed component by "suppress by expression"

Phenom
Phenom

Here's a quick example:

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        lw.Open()

        Const undoMarkName As String = "suppression expression name"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        'process top level components of the display part
        For Each tempComp As Assemblies.Component In theSession.Parts.Display.ComponentAssembly.RootComponent.GetChildren
            lw.WriteLine("component name: " & tempComp.DisplayName)
            If tempComp.IsSuppressed Then
                Try
                    tempComp.Unsuppress()
                Catch ex As NXException
                    If ex.ErrorCode = 650027 Then
                        'component suppressed by non-constant expression

                        'get instance of component
                        Dim instanceTag As Tag = Tag.Null
                        instanceTag = theUfSession.Assem.AskInstOfPartOcc(tempComp.Tag)

                        If instanceTag = Tag.Null Then
                            'skip this
                            Continue For
                        End If

                        'get the suppression expression tag
                        Dim expTag As Tag = Tag.Null
                        theUfSession.Assem.AskSuppressionExp(instanceTag, expTag)
                        Dim suppressExp As Expression = Utilities.NXObjectManager.Get(expTag)

                        lw.WriteLine("  suppression controlled by expression: " & suppressExp.Name)

                    Else
                        lw.WriteLine("error " & ex.ErrorCode & " : " & ex.Message)

                    End If
                End Try
            End If
            lw.WriteLine("")
        Next

        lw.Close()

    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

Re: get expression of suppresed component by "suppress by expression"

Genius
Genius

Hi Cowski,

 

Thanks for the quick reply. I was planning on testing the journal today but copying your sample code is even faster. Smiley Happy

Thanks again for the great support!

 

grt

Fred