Adding iAssembly occurrences
Description
This sample demonstrates adding iAssembly occurrences to an assembly.Code Samples
Before running the sample, make sure that C:\temp\iAssemblyFactory.iam exists and that it is an iAssembly factory.
Public Sub AddiAssemblyOccurrence()
' Open the factory document invisible.
Dim oFactoryDoc As AssemblyDocument
Set oFactoryDoc = ThisApplication.Documents.Open("C:\temp\iAssemblyFactory.iam", False)
' Set a reference to the component definition.
Dim oCompDef As AssemblyComponentDefinition
Set oCompDef = oFactoryDoc.ComponentDefinition
' Make sure we have an iAssembly factory.
If oCompDef.IsiAssemblyFactory = False Then
MsgBox "Chosen document is not a factory.", vbExclamation
Exit Sub
End If
' Set a reference to the factory.
Dim oiAssyFactory As iAssemblyFactory
Set oiAssyFactory = oCompDef.iAssemblyFactory
' Get the number of rows in the factory.
Dim iNumRows As Integer
iNumRows = oiAssyFactory.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.AddiAssemblyMember("C:\temp\iAssemblyFactory.iam ", oPos, iRow)
Next
End Sub
