Why accessing ComponentDefinition sometimes throws error?

By Philippe Leefsma

A common mistake made by people who begin working with the Inventor API:

When trying to access a suppressed ComponentDefinition it throws an error?  How to solve this issue ?

Solution

If the Occurrence is suppressed, the component definition may not be available! So Before trying to access the ComponentDefinition , test "Suppressed" property. This is applicable for both Inventor and Apprentice

Following code shows how to do this:

    Sub TestIsSuppressed(ByVal app As Inventor.Application)

 

        Dim oAsmCompDef As AssemblyComponentDefinition

        oAsmCompDef = app.ActiveDocument.ComponentDefinition

 

        Dim oOcc As ComponentOccurrence

        For Each oOcc In oAsmCompDef.Occurrences

            ‘ Now we need error handling here,

            ‘ or a check that the component isn’t suppressed 

            If Not oOcc.Suppressed Then

                Dim oDef As ComponentDefinition

                oDef = oOcc.Definition

            End If

        Next

<

p style=”line-height: normal;margin: 0in 0in 0pt” class=”MsoNormal”>    End Sub


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading