Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Could you please help me out and advise, where do I miss additional code with ComponentOccurance or Add.Virtual item.
When configurator is run and door reach height of 2500mm, I would like to add virtual item "FLUSHBOLT EXTENDED ROD"
If leaf_height >= 2500 Then AddAdditionalItems(oAsmDoc,1, "FLUSHBOLT EXTENDED ROD", "FLUSHBOLT EXTENDED ROD")
It works, but then I have another instance where, if another parameter is true then:
AddAdditionalItems(oAsmDoc,1, "PACKER FOR EXTERNAL DEVICE", "PACKER FOR EXTERNAL DEVICE")
And at this point both virtual items are PACKER FOR EXTERNAL DEVICE:1 and PACKER FOR EXTERNAL DEVICE:2
Please see code below:
Function AddAdditionalItems(asmDoc As AssemblyDocument, ItemQuantity As Double, ItemNameOnDrawing As String, ItemNameDescription As String) As String ' QTY = ItemQuantity 'Dim asmDoc As AssemblyDocument asmDoc = ThisDoc.ModelDocument Dim oOccs As ComponentOccurrences oOccs = asmDoc.ComponentDefinition.Occurrences ' Create collection to hold virtual parts Dim oVPs As ObjectCollection oVPs = ThisApplication.TransientObjects.CreateObjectCollection ' Add to collection of virtual parts For Each oOcc As ComponentOccurrence In oOccs If TypeOf oOcc.Definition Is VirtualComponentDefinition Then oVPs.Add(oOcc) End If Next Dim identity As Matrix = ThisApplication.TransientGeometry.CreateMatrix Dim virtOcc As ComponentOccurrence If oVPs.Count > 0 Then virtOcc = oVPs.Item(1) Else virtOcc = oOccs.AddVirtual(ItemNameOnDrawing, identity) ' Set properties of virtual part 'iProperties.Value(virtOcc.Name, "Project", "Part Number") = "INSERT PART NUMBER HERE" iProperties.Value(virtOcc.Name, "Project", "Description") = ItemNameDescription 'iProperties.Value(virtOcc.Name, "Project", "Stock Number") = "INSERT STOCK NUMBER HERE" oVPs.Add(virtOcc) End If ' Compare actual to required If QTY > oVPs.Count Then ' Add more virtual parts For aaa = 1 To QTY - oVPs.Count Call oOccs.AddByComponentDefinition(virtOcc.Definition, identity) Next Else If QTY < oVPs.Count ' Remove virtual parts RemoveQTY = oVPs.Count - QTY For bbb = oVPs.Count To QTY + 1 Step -1 oVPs.Item(bbb).Delete Next End If End Function
Thanks...
Solved! Go to Solution.