Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am working on rule to insert virtual parts into an assembly based on known user parameters and a list of possible virtual parts.
I am encountering the an issue at the end of the rule where I get the error
Error in rule: Erase, in document: VirtualPartsModelAssembly.iam
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
The rule runs and successfully creates the parts but shows the error at the end.
'Sets up Document
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAssyDoc.ComponentDefinition
Dim oOccs As ComponentOccurrences
oOccs = oAssyDoc.ComponentDefinition.Occurrences
'Deletes any existing virtual parts
For Each oOcc In oOccs
If Not oOcc.suppressed Then
If TypeOf oOcc.Definition Is VirtualComponentDefinition Then
oOcc.Delete
End If
End If
Next
'Defines Parts to Look at
'Dim PartList As New ArrayList
'PartList.Add("Lid") '0
'PartList.Add("Module") '1
'PartList.Add("ModuleFrame") '2
'Logger.Trace("PartList")
'Virtual parts
Dim VirtList As New ArrayList
VirtList.Add("Bolt") '0
VirtList.Add("Nut") '1
VirtList.Add("Washer") '2
VirtList.Add("Gasket") '3
Logger.Trace("Virt List")
Dim m As Integer
If OutletModuleQty = 1 Then
'Defines the number of modules
m = Outlet1LHQty + Outlet1RHQty 'User specified number of parts
Logger.Trace("OutletQTY")
End If
'Defines number of virtual parts
Dim iQty As Integer
iQty = m
Logger.Trace("iQty")
'Defines Virtual Part to create
Dim oString As String
For Each oString In VirtList
Vstart :
vPart = VirtList.Item(i)
i += 1
Logger.Trace(i & "VirtList")
'Defines location for Virt Part
Dim identity As Matrix
identity = ThisApplication.TransientGeometry.CreateMatrix()
Dim index As Integer
index = 2
Logger.Trace(index)
If vPart = "Washer" Then
'Loops back to bypass creating a virtual part
GoTo VStart
Else
iQty = m 'defines number of virtual parts
End If
'create first instance of the virtual part
Dim virtOcc As ComponentOccurrence
virtOcc = oOccs.AddVirtual(vPart, identity)
'add next instance starting at instance2 (if applicable)
Do While index <= iQty
oOccs.AddByComponentDefinition(virtOcc.Definition, identity)
index += 1
Logger.Trace(index & "Index")
Logger.Trace(iQty & "iQTY")
Loop
Next
Solved! Go to Solution.