Structured bill of material returns just the top level assembly

Structured bill of material returns just the top level assembly

Anonymous
Not applicable
1,034 Views
3 Replies
Message 1 of 4

Structured bill of material returns just the top level assembly

Anonymous
Not applicable

Hi

 

I'm working on a standalone C# program that uses Inventor Apprentice API. It opens the top level assembly, loops through its BOM rows in Structured View and displays them in a DataGridView.

 

For a couple of assemblies, the BOMRowsCount (in the below code) is just 1 ( the top-level assembly), whereas if I change the BOMViewType to 'Model Data' or 'Parts Only', it shows up all the BOMRows.

 

When I open the Structured View tab of Bill of Materials of that assembly in Inventor UI, I can see all the parts & subassemblies listed. But the API fails to retrieve the BOMRows and it doens't throw any exception either.

 

I don't know what's special/wrong about these assemblies or there is a better way of implementation.

 

I'm not very familiar with Inventor APIs, any help on better understanding of this behaviour is appreciated.

 

 

var assemblyDoc = inventor.Open(assemblyPath);
var components = (Inventor.AssemblyComponentDefinition)assemblyDoc.ComponentDefinition;
Inventor.BOMView structuredView = null;
try
{
structuredView = components.BOM.BOMViews
.Cast<Inventor.BOMView>()
.Single(view => view.ViewType == Inventor.BOMViewTypeEnum.kStructuredBOMViewType);
var BOMRowsCount = structuredView.BOMRows.Count;
}

catch (InvalidOperationException x)
{
// If zero or more than one structured BOM was found.
throw new InventorStructuredBomException(x);
}

 

 

 

Thanks

Rekha.

0 Likes
1,035 Views
3 Replies
Replies (3)
Message 2 of 4

MechMachineMan
Advisor
Advisor

You are missing some lines to set the properties of the BOM object.

 

See documentation here:

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-5E4217C6-FCE6-4006-9232-ACC42372A688

 

or example in vb.net, but it should get you sorted out:

 

Sub FetchActiveDocBOM(oXLFileName As String, oExportSheetName As String) 
    On Error Resume Next
    
    
    Dim oBOM As BOM
    oBOM = invDoc.ComponentDefinition.BOM

    Call oBOM.ImportBOMCustomization("Z:\Python\Engineers folder\Justin\iLogic\BOM_Style.xml")

    oBOM.StructuredViewFirstLevelOnly = False
    oBOM.StructuredViewEnabled = True
 	oBOM.PartsOnlyViewEnabled = True
	
    Dim oStructuredBOMView
    oStructuredBOMView = oBOM.BOMViews.Item("Structured")
    Call oStructuredBOMView.Sort("Part Number", True)
	Call oStructuredBOMView.Renumber(1,1,)
	
    Call oStructuredBOMView.Export(oXLFileName, 74498, oExportSheetName)
   
    If Err.Number <> 0 Then
        MsgBox ("Error Opening/Exporting!: " & Err.Number & " :: " & Err.Description)
    End If
End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks for your reply Justin.

 

I'm not able to set these properties, I guess its because I'm using the apprentice API which has limited features (mostly read-only).

 

But I checked these properties on the assembly, they already have the expected values - 

 

StructuredViewFirstLevelOnly - False

StructuredViewEnabled - True

PartsOnlyViewEnabled - True

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

Has anyone else encountered this issue before? Any help would be appreciated.

 

Thanks

Rekha.

0 Likes