Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Default BOM structure

khalil.ksibi0
Explorer

Default BOM structure

khalil.ksibi0
Explorer
Explorer

Hello Community,

 

I really need your help!

 

I have an iLogic script which import a structured BOM and now I want to add a function/condition to to read the categories (mentioned below in the screenshot) in order to not consider all the parts/BOMs under a purchasing component.

khalilksibi0_0-1689692639949.png

 

I don´t know exactly since I am new in dealing with iLogic scripts but I assume it should be somewhere in this block:

 

oBOM.StructuredViewFirstLevelOnly = False

oBOM.StructuredViewEnabled = True


oBOM.StructuredViewDelimiter = "."
Dim oStructuredBOMView As BOMView


oStructuredBOMView = oBOM.BOMViews.Item("Structured")

oStructuredBOMView.Export (oFilePath & ".xls", kMicrosoftExcelFormat)


myXLS_File = oFilePath & ".xls"


myName= ThisApplication.GeneralOptions.UserName


excelApp = CreateObject("Excel.Application")

excelApp.Visible = False

excelApp.DisplayAlerts = False


If Dir(myXLS_File) <> "" Then

excelWorkbook = excelApp.Workbooks.Open(myXLS_File)

excelSheet = excelWorkbook.Worksheets(1).activate
Else

excelWorkbook = excelApp.Workbooks.Add

End If

 

I really appreciate your help and thank you in advance 🙂

 

0 Likes
Reply
Accepted solutions (1)
1,111 Views
8 Replies
Replies (8)

A.Acheson
Mentor
Mentor

Hi @khalil.ksibi0 

 

It seems this question has been answered before. Here is the forum post.

 

It is working by exporting the BOM to excel and then just sorting the BOM Structure column in excel and deleting unecessary rows.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes

khalil.ksibi0
Explorer
Explorer

Hello @A.Acheson,

 

Thank you for your feedback.

 

Actually, I need it to get done directly by the iLogic script, means when I run it, I get the desired BOM structure.

Do you think this won´t be possible?

 

Best regards,

Khalil

0 Likes

tonythm
Advocate
Advocate

@khalil.ksibi0 

 

You can test ilogic below. Make sure the parts in it are placed correctly with the BOM structure.

    ' Set a reference to the assembly document.
    ' This assumes an assembly document is active.
    Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument
    
    Dim oACDef As AssemblyComponentDefinition
    oACDef = oDoc.ComponentDefinition
    oACDef.RepresentationsManager.LevelOfDetailRepresentations("Master").Activate

    ' Set a reference to the BOM
    Dim oBOM As BOM
    oBOM = oDoc.ComponentDefinition.BOM
    
    ' Set the structured view to 'all levels'
    oBOM.StructuredViewFirstLevelOnly = True

    ' Make sure that the structured view is enabled.
    oBOM.StructuredViewEnabled = True

    ' Set a reference to the "Structured" BOMView
    Dim oStructuredBOMView As BOMView
    oStructuredBOMView = oBOM.BOMViews.Item("Structured")
    
    'Set Excel file name
    Dim oFilename As String
    oFilename = ThisDoc.FileName(False) & ".xls"
	
	Dim oPath As String = ThisDoc.Path
	Dim sFolder As String
	sFolder = Left(oPath, InStrRev(oPath, "\"))
	If Not System.IO.Directory.Exists(sFolder) Then
	System.IO.Directory.CreateDirectory(sFolder)
	End If
    
    ' Export the BOM view to an Excel file
    oStructuredBOMView.Export( sFolder & "\" & ThisDoc.FileName(False) & ".xls", kMicrosoftExcelFormat)

 

khalil.ksibi0
Explorer
Explorer

Hi @tonythm,

 

Thank you for your feedback.

 

In tis case, the script will get rid of all sub-parts, in my case, I just want to get rid of the parts/assemblies under purchased components.

 

So I guess it needs to be declared right?

 

Best regards,

Khalil

0 Likes

A.Acheson
Mentor
Mentor
Accepted solution

Hi @khalil.ksibi0 

 

No there is no direct way to add the option of BOM Structure to the BOM Export method. You have a few options for indirect filtering.

 

1. Export the whole BOM to excel with the BOM Structure column visible and delete the rows not needed.

Edit:

2. Loop through the BOM Row and filter for BOM Structure and write the cells of any rows matching to a cell within an excel sheet. See Curtis example here

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes

WCrihfield
Mentor
Mentor

Just a related thought, but maybe you could create a temporary drawing document for the assembly, and place a PartsList in it.  Then customize that PartsList the way you want it, because it is usually a lot simpler to deal with a PartsList than it is an assembly BOMView.  Then either save the changes back to the assembly BOM from there, or export the PartsList to Excel directly, instead of exporting the BOMView to Excel.

Edit:  You can also 'filter' the PartsList several different ways, including by a DVR (DesignViewRepresentation).  You could have a DVR in which all those purchased components have their 'visibility' turned off, then use that to filter the PartsList.  However, I don't believe that filters can be applied to PartsList by code yet, so that might be one limitation of that route.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

WCrihfield
Mentor
Mentor

Actually, why not create an LOD or ModelState in your assembly first, then loop through all the components in your assembly and suppress the ones that are set to purchasing BOMStructure.  Then base the BOMView on that LOD or ModelState, and set the BOM.HideSuppressedComponentsInBOM setting to True.  Then, your BOMView will not be showing any purchased items in it.  Unfortunately, the BOMView.ModelStateMemberName property is ReadOnly, so you would likely have to activate the correct ModelState before starting the code.  And if you need a version of the BOMView that does include the purchased stuff, just use the Master/Primary LOD/ModelState, or have another LOD/ModelState that is set up the way you want it to use.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)