How can I suppress the Circular Pattern Component in an Assembly file ?

By Wayne Brill

Issue

I want to supress the Circular Pattern Component in an assembly file. I can do this through UI as shown in image.  If I use the Visible property of CircularOccurrencePattern Object, I can only control the object visibilty in the Assembly file, but in the corresponding drawing document, the objects visibilty will not be supressed.

How can I achieve this using API ?

Solution

If you want to make the entire occurrence pattern invisible, you could access all the pattern elements which make up the occurrence pattern, from each pattern element access all the individual occurrences and make them invisible:

Public Sub SuppressOccPatterns()        Dim m_inventorApp As  _            Inventor.Application = Nothing             ' Try to get an active instance of Inventor        Try            m_inventorApp = _                System.Runtime.InteropServices.Marshal _                .GetActiveObject("Inventor.Application")        Catch ex As Exception             End Try             ' If not active, create a new Inventor session        If m_inventorApp Is Nothing Then            Try                Dim inventorAppType As Type = _                  System.Type.GetTypeFromProgID _                            ("Inventor.Application")                m_inventorApp = System.Activator. _                    CreateInstance(inventorAppType)                 Catch ex As Exception                 End Try        End If             If m_inventorApp Is Nothing Then            MsgBox("no Inventor instance!")            Exit Sub        End If             Dim oAssemDoc As AssemblyDocument        oAssemDoc = m_inventorApp.ActiveDocument             If oAssemDoc.SelectSet.Count = 0 Then            Exit Sub        End If                  Dim oSelectedObj As Object        oSelectedObj = oAssemDoc.SelectSet.Item(1)             If Not oSelectedObj Is Nothing Then            Dim oOccPattern As OccurrencePattern                 If TypeOf oSelectedObj Is  _                           OccurrencePattern Then                Dim oSuppOccPattTrans As Transaction                oSuppOccPattTrans = m_inventorApp. _                    TransactionManager.StartTransaction _                      (oAssemDoc, "Suppress OccPatterns")                     oOccPattern = oSelectedObj                     Dim oOccPatElement As  _                               OccurrencePatternElement                For Each oOccPatElement In _                                   oOccPattern. _                              OccurrencePatternElements                    Dim oCompOcc As ComponentOccurrence                    For Each oCompOcc In _                             oOccPatElement.Occurrences                        oCompOcc.Visible = False                    Next                Next oOccPatElement                     oSuppOccPattTrans.End()            Else                MsgBox("Select an Occurrence Pattern")            End If        Else            MsgBox("Select an Occurrence Pattern")        End If    End Sub

Comments

One response to “How can I suppress the Circular Pattern Component in an Assembly file ?”

  1. alessandro Avatar
    alessandro

    como seria esse código em c#?

Leave a Reply to alessandroCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading