- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You are correct about the purpose of the code I posted.
I believe I now better understand what you actually wanted, and have changed the code as I believe was needed.
This new code now doesn't bother checking the BOMStructure of the main assembly. It now only loops through the first/top level components, and processes the sub assemblies. And it will only process that sub assembly if it's BOMStructure is currently set to Purchased. It then loops through just the first/top level components within that sub assembly, and changes each component's BOMStructure to Purchased, to match the sub assembly. I hope I was correct in assuming you only wanted the first level of components within each purchased sub assembly to be set to Purchased, and not attempting to dig down any deeper.
Here is the new code:
Public Sub Main()
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
oOccs = oAsmDoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs
'If it's not an Assembly, don't process it
If oOcc.DefinitionDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Continue For
'If it's not Purchased, don't process it
If oOcc.BOMStructure <> BOMStructureEnum.kPurchasedBOMStructure Then Continue For
'loop all first level components within this Purchased sub assembly
For Each oComp As ComponentOccurrence In oOcc.Definition.Occurrences
'if not already Purchased, then set to Purchased
If oComp.BOMStructure <> kPurchasedBOMStructure Then
oComp.BOMStructure = kPurchasedBOMStructure
End If
Next
Next
End Sub
Wesley Crihfield
(Not an Autodesk Employee)