@mrattray wrote:
Can you create a pattern of them? That's how I would do it with the UI...
Great idea! Decided to write a VBA macro to do just that 😉
Sub CreateVirtPattern()
' JDK 2013 - Create virtual component then pattern it
Dim oAssDoc As AssemblyDocument
Set oAssDoc = ThisApplication.ActiveDocument
Dim oAssDef As AssemblyComponentDefinition
Set oAssDef = oAssDoc.ComponentDefinition
Dim oMatrix As Matrix
Set oMatrix = ThisApplication.TransientGeometry.CreateMatrix
' Create virtual component
Dim sName As String
sName = "VirtualComp"
Set oNewOcc = oAssDef.Occurrences.AddVirtual(sName, oMatrix)
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAssDef.Occurrences
' Look for virtual components
If TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
' Look for name match
sNameS = Split(oOccurrence.name, ":")
If sName & ":" & sNameS(1) = oOccurrence.name Then
Dim XAxis As WorkAxis
Set XAxis = oAssDef.WorkAxes(1)
' Create object collection
Dim objCol As ObjectCollection
Set objCol = ThisApplication _
.TransientObjects.CreateObjectCollection
' Add virtual comp to object collection
objCol.Add oAssDef.Occurrences.Item(1)
' How many components in pattern
Dim iNum As Integer
iNum = 3
' Create pattern
Call oAssDef.OccurrencePatterns _
.AddRectangularPattern(objCol, _
XAxis, True, 10, iNum)
End If
End If
Next
End Sub
Here's the iLogic version as well...
' JDK 2013 - Create virtual component then pattern it
Dim oAssDoc As AssemblyDocument = ThisDoc.Document
Dim oAssDef As AssemblyComponentDefinition = oAssDoc.ComponentDefinition
Dim oMatrix As Matrix: oMatrix = ThisApplication.TransientGeometry.CreateMatrix
' Create virtual component
sName = "VirtualComp"
oNewOcc = oAssDef.Occurrences.AddVirtual(sName, oMatrix)
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAssDef.Occurrences
' Look for virtual components
If TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
' Look for name match
sNameS = Split(oOccurrence.Name, ":")
If sName & ":" & sNameS(1) = oOccurrence.Name Then
Dim XAxis As WorkAxis: XAxis = oAssDef.WorkAxes(1)
' Create object collection
Dim objCol As ObjectCollection
objCol = ThisApplication _
.TransientObjects.CreateObjectCollection
' Add virtual comp to object collection
objCol.Add(oAssDef.Occurrences.Item(1))
' How many components in pattern
Dim iNum As Integer
iNum = 3
' Create pattern
Call oAssDef.OccurrencePatterns _
.AddRectangularPattern(objCol, _
XAxis, True, 10, iNum)
End If
End If
Next
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.