Message 1 of 14
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a script for sorting and renumbering the BOM which in turn sorts the drawing parts list how I wish. Since model states were introduced my script has been failing and I cannot figure why or how to correct it. Adding a model state to an assembly and then running the code below doesn't always cause a failure, but after renumbering an item in the assembly BOM the code will always fail. The primary failure is trying to set the BOM structured view first level only to False and the secondary failure is trying to import the BOM customization XML file.
I have a test drawing and related assembly attached with an iLogic rule in the drawing that has the below code.
Dim oSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet
Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
If (oDrawingView.ReferencedDocumentDescriptor.ReferencedDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject) Then
MsgBox("This is not an assembly drawing")
Exit Sub
End If
Dim oAssydoc As AssemblyDocument = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(oAssydoc, "Sort BOM")
If (oAssydoc.ComponentDefinition.ModelStates.ActiveModelState.Name <> "[Primary]") Then
If (MsgBox("Primary Model State not selected." & vbNewLine & "Click Yes to switch to Primary Model State or No to cancel.", MsgBoxStyle.YesNo) = MsgBoxResult.Yes) Then
ThisApplication.Documents.Open(oAssydoc.FullFileName, False).ComponentDefinition.ModelStates("[Primary]").Activate()
Else
Exit Sub
End If
End If
Dim oBOM As BOM = oAssydoc.ComponentDefinition.BOM
oBOM.StructuredViewEnabled = True
Try
oBOM.StructuredViewFirstLevelOnly = False
Catch ex As Exception
MsgBox("Failed to set BOM view to first level only, try again or sort BOM manually")
'Exit Sub
End Try
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
Dim oBOMRows As BOMRowsEnumerator = oBOMView.BOMRows
Try
'MsgBox(System.IO.Path.GetDirectoryName(ThisApplication.ActiveDocument.fullfilename) & "\Bom.xml")
Call oBOM.ImportBOMCustomization(System.IO.Path.GetDirectoryName(ThisApplication.ActiveDocument.fullfilename) & "\Bom.xml")
Catch ex As Exception
MsgBox("Failed to import BOM customization, try again or sort BOM manually")
'Exit Sub
End Try
Solved! Go to Solution.