- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I would like some help creating an iLogic code to iterate through the structured BOM of an assembly and update/add an instance property.
I had a code that would do this to the assembly component occurrences (see snip below), but there was 2 issues with this.
- It would not apply to the children of of phantom assemblies so caused issues with parts lists
- I recently discovered that if you 'replace' a component then the instance property no longer updates or creates (This must be a glitch surely?)
So i'm thinking if it is possible to do this through the structured BOM might be a better way? (It can be done manually, so hopefully there is an automation for it)
The basic rundown is we need to create a 'Pack Qty' for our parts lists. The pack qty = the Item qty from this assembly * the number of these assemblies to be made (Custom Iprop "TOTAL_QUANTITY)
The code needs to give each occurrence and Instance property = to the parent assy total quantity and the Partslist sums these with a substitution column to give the final Pack Qty.
If the Instance property does not get through to the promoted components from phantom sub-assemblies then this causes 'Varies' issues.
Also it needs to be an instance property as the items are used in multiple assemblies and so have a 'Total_Quantity' of their own that is the sum of all it's pack quantities.
Sorry if this is worded confusingly, and thanks in advance.
'This is the original method that did not get children & also had an issue with replaced components
Dim activeDocName As String = ThisApplication.ActiveDocument.FullFileName
Dim thisDocName As String = ThisDoc.Document.FullFileName
If (activeDocName <> thisDocName) Then
' the script was not triggered by the active document
Return
End If
'Check active document is an assembly
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MessageBox.Show("This rule " & iLogicVb.RuleName & " only works for Assembly Documents.", "WRONG DOCUMENT TYPE", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
'set a reference to the assembly component definintion.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Get the value from the parent assembly TOTAL_QUANTITY
Dim oPQ As String
oPQ = (iProperties.Value("Custom", "TOTAL_QUANTITY"))
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
'Set instance property value
iProperties.InstanceValue(oOccurrence.Name, "PACK_QTY") = oPQ
'Message box for debugging
'MessageBox.Show(oPQ, "iLogic")
Next
Solved! Go to Solution.