Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
daniel.puchta
846 Views, 7 Replies

Unable to suppress occurrence in subassembly

Hello everyone

I have this VBA code that check for each occurrence if it is suppressed. If yes it will unsuppress. Then it recursively calls itself if the occurrence is assembly.

Sub Main()
    Dim oAsmDoc As Inventor.AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = oAsmDoc.ComponentDefinition
    Dim oOccurrences As ComponentOccurrences
    Set oOccurrences = oAsmCompDef.Occurrences
    Zapnuti_occurrence oOccurrences, oAsmDoc
End Sub
Sub Zapnuti_occurrence(oOccurrences As ComponentOccurrences, oDoc As Inventor.AssemblyDocument)
    Dim oSuppress_Occurrence As Boolean
    Dim oModelState As ModelState
    Dim oModelState_created As Boolean
    
    oModelState_created = False
    For Each oOccurrence In oOccurrences 'tady to změnit na list
        oSuppress_Occurrence = False
        If oOccurrence.Suppressed = True Then
            If oModelState_created = False Then
                Set oModelState = ThisApplication.ActiveDocument.ComponentDefinition.ModelStates.Add("Part2Suppressed2")
            End If
            oOccurrence.Unsuppress
            oSuppress_Occurrence = True
        End If
        'do stuff...
        'If oSuppress_Occurrence = True Then
        '    oSuppress_Occurrence = False
        '    oOccurrence.Suppress
        'End If
    
        If oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then
            If InStr(oOccurrence.Definition.Document.DisplayName, new_element) = 0 Then
                oDoc.Update
            End If
            Set oDoc = ThisApplication.Documents.Open(oOccurrence.Definition.Document.FullFileName)
                            
            
            Zapnuti_occurrence oOccurrence.SubOccurrences, oDoc
            
            oDoc.Save2
            oDoc.Close
        End If
    Next
End Sub

 When trying to unsuppress occurrence of subassembly, it throws this error:

Unsuppress error.png

 It does not matter if before trying to suppress occurrence It creates new model state or not. Please do you know how to solve this problem?

Labels (3)