- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks Again Dalton, really appreciate the help.
I've bene playing around a bit more and think I am very close. I have managed to get it reading the occurrence name.
The only problem here is there is duplicates of the occurrence names due to promoted components from the phantom sub assemblies.
So anything with an occurrence name in a sub assembly that matches an occurrence name from the main assembly does not get update. Anything with a unique occurrence name does.
i.e if there is 4 occurrences of 'part1' in the main assembly, and 7 in a sub. Then 5,6 & 7 will have the instance property applied but 1-4 will not.
Any suggestions on how to dig down to rectify this?
Current code snip:
Sub Main
Dim oAdoc As AssemblyDocument
oAdoc = ThisApplication.ActiveDocument
'Check it is the active document that triggered this script
Dim activeDocName As String = oAdoc.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
'Get current Assembly TOTAL_QUANTITY value as Pack Quantity multiplier
Dim oPQ As String
oPQ = (iProperties.Value("Custom", "TOTAL_QUANTITY"))
Dim oCompDef As AssemblyComponentDefinition
oCompDef = oAdoc.ComponentDefinition
Dim asmOccurrences = oCompDef.Occurrences
'Get BOM Definition
Dim oBOM As BOM
oBOM = oCompDef.BOM
'Set BOM to structured view & first level only
oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = True
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Structured")
Dim oRow As BOMRow
For Each oRow In oBOMView.BOMRows
'do stuff
'Message box for debugging
MessageBox.Show(oRow.ItemNumber, "Debug1")
For Each CompDef As ComponentDefinition In oRow.ComponentDefinitions
Dim occurrences = asmOccurrences.AllLeafOccurrences(CompDef)
For Each occ As ComponentOccurrence In occurrences
'Message box for debugging
MessageBox.Show(occ.Name, "Debug2")
iProperties.InstanceValue(occ.Name, "PACK_QTY") = oPQ
Next
Next
Next
End Sub
In the snip below I have turned off merging to demonstrate what has been updated and what has not. (Previous value manually set to 20, ilogic trying to update to 50)