How to iterate through each Part in a Parts Only BOMview?

How to iterate through each Part in a Parts Only BOMview?

jake_egley
Advocate Advocate
226 Views
3 Replies
Message 1 of 4

How to iterate through each Part in a Parts Only BOMview?

jake_egley
Advocate
Advocate

Basically im making code that will iterate through each part in an assembly get the quantity of the part and then open the part to get a dxf and and area, then take this info and fill out an excel sheet. I've got the parts only bom view set up to give me quantity of each item using a counter. Now I want a for loop that will be something like:

 

For each Item in oPartsOnlyBOMView

     'open item and make dxf etc. here

Next

 

 

 

But I cant get the syntax right to iterate through each item in the parts only bom view. Can someone please help. This is where im at and I'm using VB:

 

Dim oBOM As BOM
Dim oDoc As Document
Dim oAsmDoc As AssemblyDocument

Set oAsmDoc = ThisApplication.ActiveDocument
Set oBOM = oAsmDoc.ComponentDefinition.BOM

' Make sure that the parts only view is enabled.
oBOM.PartsOnlyViewEnabled = True
    
' Set a reference to the "Parts Only" BOMView
Dim oPartsOnlyBOMView As BOMView
Set oPartsOnlyBOMView = oBOM.BOMViews.Item("Parts Only")

For Each oDoc In oPartsOnlyBOMView
     openDoc = ThisApplication.Documents.Open(oDoc.FullDocumentName, True)
     ThisApplication.ActiveDocument.Close
Next

 

 

 

Jake Egley
Inventor 2022
0 Likes
227 Views
3 Replies
Replies (3)
Message 2 of 4

marcin_otręba
Advisor
Advisor

hi,

 

use  for exporting dxf's from parts only bom view:

 

Dim oBOM As BOM
Dim oDoc As Document
Dim oAsmDoc As AssemblyDocument

Set oAsmDoc = ThisApplication.ActiveDocument
Set oBOM = oAsmDoc.ComponentDefinition.BOM

' Make sure that the parts only view is enabled.
oBOM.PartsOnlyViewEnabled = True
    
' Set a reference to the "Parts Only" BOMView
Dim oPartsOnlyBOMView As BOMView
Set oPartsOnlyBOMView = oBOM.BOMViews.Item(3)
Dim oBomRow As BOMRow
For Each oBomRow In oPartsOnlyBOMView.BOMRows
Set oDoc = oBomRow.ComponentDefinitions(1).Document
  dxffilename = ""
If oDoc.ComponentDefinition.Type = kSheetMetalComponentDefinitionObject Then
Dim oSheetMetalCompDef As SheetMetalComponentDefinition
Set oSheetMetalCompDef = oDoc.ComponentDefinition
Dim fp As FlatPattern
If oSheetMetalCompDef.HasFlatPattern = False Then
oSheetMetalCompDef.Unfold
oSheetMetalCompDef.FlatPattern.ExitEdit
End If
Set fp = oSheetMetalCompDef.FlatPattern

dxffilename = Replace(oDoc.FullFileName, ".ipt", ".dxf")


Dim oDataIO As DataIO
Set oDataIO = oDoc.ComponentDefinition.DataIO
Dim sOut As String
sOut = "FLAT PATTERN DXF?AcadVersion=R12&SimplifySplines=true&FeatureProfilesUpLayerCOLOR=255;255;0&InvisibleLayers=IV_BEND;IV_BEND_DOWN;IV_TANGENT;IV_ARC_CENTERS;IV_FEATURE_PROFILES_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ROLL;"
oDataIO.WriteDataToFile sOut, dxffilename
End If
Next

 

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 3 of 4

jake_egley
Advocate
Advocate

Beautiful. Only thing I had to change was this:

 

Set oPartsOnlyBOMView = oBOM.BOMViews.Item(3)

by replacing the (3) with ("Parts Only")

Jake Egley
Inventor 2022
0 Likes
Message 4 of 4

marcin_otręba
Advisor
Advisor

actually it is the same, you can use name of view or index to get it, where index value is  1-model, 2-structured, parts only

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes