- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
There were a couple of things that needed to be changed to make it work. First of all, you were trying to change the BOMStructure of the component's definition, not of the component itself. You had to remove a level from that line of code. Second, the Sub was designed to recieve a 'ComponentOccurrences' object, which comes from the ComponentDefinition.Occurrences, but you were supplying oOcc.SubOccurrences, which is a ComponentOccurrencesEnumerator, to that Sub within the TraverseAssembly Sub's code. On another note, in your post you said you were working with 'Purchased' main assembly, and wanted to set all components within to 'Purchased' BOMStructure, but your code was trying to set them all to 'Phantom' BOMStructure, so I changed that part too. I added some code to the main Sub that gets the BOMStructure of the main assembly, then uses that as the basis to set everything under it.
Here is the new code:
Public Sub Main()
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
'get the BOMStructure status of the main assembly
oBOMSt = oAsmDoc.ComponentDefinition.BOMStructure
'now push that to all sub assemblies and components at all levels within
TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, oBOMSt)
End Sub
Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, oBOMStr As BOMStructureEnum)
For Each oOcc As ComponentOccurrence In Occurrences
Try
oOcc.BOMStructure = oBOMStr
Catch
MsgBox(oOcc.Name & "remains unchanged")
End Try
' Check to see if this occurrence represents a subassembly
' and recursively call this function to traverse through it.
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
TraverseAssembly(oOcc.Definition.Occurrences, oBOMStr)
End If
Next
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS)
.
If you want and have time, I would appreciate your Vote(s) for My IDEAS
or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)