Message 1 of 6
Ilogic code for placing both structured and parts only BOMs on a drawing sheet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi , can someone please provide me a code for placing both BOMs simultaneously into a drawing sheet in inventor 2021 or 2022?
I have tried using Chatgpt and the above code but i keep receiving an error.
Error in rule: Rule0, in document: Assembly1 femi
Public member 'ComponentDefinition' on type '_DocumentClass' not found.
Below is the code i tried to input.
ub Main() PlaceBothBOMsOnSheet() End Sub Sub PlaceBothBOMsOnSheet() If Not TypeOf ThisApplication.ActiveEditDocument Is DrawingDocument Then MsgBox("Please open a drawing document.") Exit Sub End If Dim drawingDoc As DrawingDocument = ThisApplication.ActiveEditDocument Dim ActiveSheet As Sheet = drawingDoc.ActiveSheet ' Check if a drawing sheet is active If ActiveSheet Is Nothing Then MsgBox("Please activate a drawing sheet.") Exit Sub End If ' Find the associated assembly document Dim asmDoc As AssemblyDocument = Nothing For Each refDoc As Document In ThisApplication.Documents If TypeOf refDoc Is AssemblyDocument AndAlso refDoc.FullFileName = drawingDoc.ComponentDefinition.ReferencedDocumentDescriptors(1).FullDocumentName Then asmDoc = refDoc Exit For End If Next ' Check if an assembly document was found If asmDoc Is Nothing Then MsgBox("No associated assembly document found.") Exit Sub End If ' Get the BOM views from the assembly Dim structuredBOMView As BOMView = asmDoc.ComponentDefinition.BOM.BOMViews.Item("Structured") Dim partsOnlyBOMView As BOMView = asmDoc.ComponentDefinition.BOM.BOMViews.Item("Parts Only") ' Define positions for the BOMs on the drawing sheet Dim structuredBOMPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(50, 50) Dim partsOnlyBOMPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(50, 350) ' Add structured BOM view to the drawing sheet ActiveSheet.DrawingBOMs.AddBOMView(structuredBOMView, structuredBOMPosition) ' Add parts-only BOM view to the drawing sheet ActiveSheet.DrawingBOMs.AddBOMView(partsOnlyBOMView, partsOnlyBOMPosition) End Sub