- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
That's an odd sounding error, so I'm not entirely sure what it means. I'm guessing there may be more properties of the ComponentOccurrence that we need to be checking for, to help avoid potential errors. For instance, we may need to check the values of these:
ComponentOccurrence.Suppressed
ComponentOccurrence.Enabled
ComponentOccurrence.DisabledActionTypes = ActionTypeEnum.kRestructureAction (not sure about this one)
ComponentOccurrence.IsAssociativelyImported (not sure if this would be a problem)
ComponentOccurrence.IsiAssemblyMember (not sure if this would be a problem)
I'm also not sure if current ModelState settings might be preventing us from changing the BOMStructure, but I don't recall this being one of the things the ModelState us supposed to be handling. I do know they record which components are suppressed, because that was one of the main purposes of the LevelOfDetail representations, which these new ModelStates are replacing.
I added those first 3 checks into the code, then also incorporated a Try...Catch block in there at the only line that is trying to do something, to catch any possible error, report them, and allow the code to continue. Give this a try.
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
If oOcc.DisabledActionTypes = ActionTypeEnum.kRestructureAction Then Continue For
If oOcc.Suppressed Or oOcc.Enabled = False Then Continue For
StepDown(oOcc.Definition.Occurrences)
Next
End Sub
Sub StepDown(oComps As ComponentOccurrences)
For Each oComp As ComponentOccurrence In oComps
If oComp.BOMStructure <> BOMStructureEnum.kPurchasedBOMStructure Then
If oComp.DisabledActionTypes = ActionTypeEnum.kRestructureAction Then Continue For
If oComp.Suppressed Or oComp.Enabled = False Then Continue For
Try
oComp.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
Catch oEx As Exception
MsgBox("Failed to set BOMStructure to Purchased." & vbCrLf & _
oEx.Message & vbCrLf & oEx.StackTrace, vbExclamation, "iLogic")
End Try
End If
If oComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
StepDown(oComp.Definition.Occurrences)
End If
Next
End Sub
Wesley Crihfield
(Not an Autodesk Employee)