- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So, I'm attempting to order a variable number of virtual components, either in Ilogic or VB. However, I'm getting an error when accessing the bill of materials. Let me start off with that I have a "functional" code. The first code below is my old code and runs just fine for very low quantities but whenever I have to create large quantities it can take several minutes or crash the program entirely.
The 2nd code below is based off something used by a coworker, where he has a form where he inputs it by hand and has it create one instance then simply overwrite the quantity in the BOM, which runs much faster. I'm attempting to duplicate this either in iLogic or VB, but both are throwing me errors when attempting to interact with the BOM. (First it gives an error of invalid procedure call or argument on both of the lines where I set the structured view to first level only and enabled, which is odd because it's literally step for step what my coworker did and his works.)
Can anyone help me? I'd love to update to the 2nd set of code or else figure out why the first set runs so slowly at high quantities. Placing actual components is so much faster, and I can't for the life of me figure out why.
'Creates a number of virtual parts with the given name and description
Function UpdateVirtParts (sVirtPart, Description, iQty)
If iQty > 0
'Declaring Document Variables
Dim asmDoc As AssemblyDocument
Dim oAsmCompDef As AssemblyComponentDefinition
Dim asmOcc As ComponentOccurrence
Dim occs As ComponentOccurrences
Dim oOcc As Object
Dim identity As Matrix
asmDoc = ThisApplication.ActiveDocument
oAsmCompDef = asmDoc.ComponentDefinition
occs = oAsmCompDef.Occurrences
identity = ThisApplication.TransientGeometry.CreateMatrix
'create first instance of the virtual part
Dim virtOcc As ComponentOccurrence
virtOcc = occs.AddVirtual(sVirtPart, identity)
'Set Virtual component properties
iProperties.Value(sVirtPart & ":1", "Project", "Description") = Description
iProperties.Value(sVirtPart & ":1", "Project", "Part Number") = sVirtPart
iQty = Min(iQty, 10)
'Add additional components up to specified quantity
For index As Integer = 2 To iQty
occs.AddByComponentDefinition(virtOcc.Definition, identity)
Next
End If
End Function
Sub Main(sPartNumber, sDescription, iQty)
Dim odoc As AssemblyDocument
Set odoc = ThisApplication.ActiveDocument
Dim oAssyCompDef As AssemblyComponentDefinition
Set oAssyCompDef = odoc.ComponentDefinition
Dim oBOM As BOM
Set oBOM = odoc.ComponentDefinition.BOM
oBOM.StructuredViewFirstLevelOnly = True
oBOM.StructuredViewEnabled = True
Dim oStructuredBOMView As BOMView
Set oStructuredBOMView = oBOM.BOMViews.Item("Structured")
Dim oMatrix As Matrix
Set oMatrix = ThisApplication.TransientGeometry.CreateMatrix
' add one virtual occurrence
Dim oNewOcc As ComponentOccurrence
Set oNewOcc = oAssyCompDef.Occurrences.AddVirtual(sPartNumber, oMatrix)
Dim oCVirtualCompDef As VirtualComponentDefinition
Set oCVirtualCompDef = oNewOcc.Definition
oCVirtualCompDef.PropertySets.Item("Design Tracking Properties").Item("Description").value = sDescription
'update qty in bill of material to match userform
oStructuredBOMView.BOMRows.Item(i).TotalQuantity = iQty
End Sub
Thank you,
Thomas Long
Solved! Go to Solution.