Share

Adding iPart occurrences to an assembly

Description

This sample demonstrates adding iPart occurrences to an assembly.

Code Samples

Before running the sample, make sure that C:\temp\iPartFactory.ipt exists and that it is an iPart factory.
Public Sub AddiPartOccurrence()
    ' Open the factory document invisible.
    Dim oFactoryDoc As PartDocument
    Set oFactoryDoc = ThisApplication.Documents.Open("C:\temp\iPartFactory.ipt", False)

    ' Set a reference to the component definition.
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oFactoryDoc.ComponentDefinition

    ' Make sure we have an iPart factory.
    If oCompDef.IsiPartFactory = False Then
        MsgBox "Chosen document is not a factory.", vbExclamation
        Exit Sub
    End If

    ' Set a reference to the factory.
    Dim oiPartFactory As iPartFactory
    Set oiPartFactory = oCompDef.iPartFactory

    ' Get the number of rows in the factory.
    Dim iNumRows As Integer
    iNumRows = oiPartFactory.TableRows.Count

    ' Create a new assembly document
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.Documents.Add(kAssemblyDocumentObject, , True)

    Dim oOccs As ComponentOccurrences
    Set oOccs = oDoc.ComponentDefinition.Occurrences

    Dim oPos As Matrix
    Set oPos = ThisApplication.TransientGeometry.CreateMatrix

    Dim oStep As Double
    oStep = 0#
    Dim iRow As Long

    ' Add an occurrence for each member in the factory.
    For iRow = 1 To iNumRows

        oStep = oStep + 10

        ' Add a translation along X axis
        oPos.SetTranslation ThisApplication.TransientGeometry.CreateVector(oStep, oStep, 0)

        Dim oOcc As ComponentOccurrence
        Set oOcc = oOccs.AddiPartMember("C:\temp\iPartFactory.ipt ", oPos, iRow)
    Next
End Sub


Was this information helpful?