Hello all,
I think this canbe a really short post. Is it a known issue that the ApprenticeServer cannot export BOM views directly to Excel? Or am I doing something wrong?
I'm using Inventor 2015 SP2 update 2.
The below code throws a system.notimplemented exception. The view is loaded correctly, I can read out the BOM values, but want to export with a single command instead of an exporting algorithm.
private void button1_Click(object sender, EventArgs e)
{
Inventor.ApprenticeServerComponent oApprServerComp = new Inventor.ApprenticeServerComponent();
Inventor.ApprenticeServerDocument oApprDoc = oApprServerComp.Open(@"C:\EPDM_DATA\ARB\SANDBOX\KLAAS\2D CAD\ANDY_EXPORTS\S400_10T\DPP-0372608.iam");
Inventor.AssemblyComponentDefinition oAssemblyCompDef = (Inventor.AssemblyComponentDefinition)oApprDoc.ComponentDefinition;
Inventor.BOMView view_model = null;
Inventor.BOMView view_structured = null;
Inventor.BOMView view_parts_only = null;
foreach (Inventor.BOMView view in oAssemblyCompDef.BOM.BOMViews)
{
if (view.ViewType.Equals(Inventor.BOMViewTypeEnum.kModelDataBOMViewType))
{
view_model = view;
}
if (view.ViewType.Equals(Inventor.BOMViewTypeEnum.kStructuredBOMViewType))
{
view_structured = view;
}
if (view.ViewType.Equals(Inventor.BOMViewTypeEnum.kPartsOnlyBOMViewType))
{
view_parts_only = view;
}
}
view_structured.Export(@"C:\temp\BOM-StructuredAllLevels.xls", Inventor.FileFormatEnum.kMicrosoftExcelFormat);
//view_structured.Export(@"C:\temp\BOM-StructuredAllLevels.txt", Inventor.FileFormatEnum.kTextFileTabDelimitedFormat);
//view_structured.Export(@"C:\temp\BOM-StructuredAllLevels.accdb", Inventor.FileFormatEnum.kMicrosoftAccessFormat);
}
Thanks for any help I can get on this!
Another attempt to get this under the radar. Is there anyone that can help, maybe if I share some more info? And if yes, what info?
Maybe.. you can try a more controlled BOM export method?
This sample shows you how to read the BOM via it's API row, by row, you have much more control if you do an export based on this method. I don't know if is accessable via apprentice. But you can try this sample to see if it works?
Public Sub BOMQuery() ' Set a reference to the assembly document. ' This assumes an assembly document is active. Dim oDoc As AssemblyDocument Set oDoc = ThisApplication.ActiveDocument Dim FirstLevelOnly As Boolean If MsgBox("First level only?", vbYesNo) = vbYes Then FirstLevelOnly = True Else FirstLevelOnly = False End If ' Set a reference to the BOM Dim oBOM As BOM Set oBOM = oDoc.ComponentDefinition.BOM ' Set whether first level only or all levels. If FirstLevelOnly Then oBOM.StructuredViewFirstLevelOnly = True Else oBOM.StructuredViewFirstLevelOnly = False End If ' Make sure that the structured view is enabled. oBOM.StructuredViewEnabled = True 'Set a reference to the "Structured" BOMView Dim oBOMView As BOMView Set oBOMView = oBOM.BOMViews.Item("Structured") Debug.Print "Item"; Tab(15); "Quantity"; Tab(30); "Part Number"; Tab(70); "Description" Debug.Print "----------------------------------------------------------------------------------" 'Initialize the tab for ItemNumber Dim ItemTab As Long ItemTab = -3 Call QueryBOMRowProperties(oBOMView.BOMRows, ItemTab) End Sub Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, ItemTab As Long) ItemTab = ItemTab + 3 ' Iterate through the contents of the BOM Rows. Dim i As Long For i = 1 To oBOMRows.Count ' Get the current row. Dim oRow As BOMRow Set oRow = oBOMRows.Item(i) 'Set a reference to the primary ComponentDefinition of the row Dim oCompDef As ComponentDefinition Set oCompDef = oRow.ComponentDefinitions.Item(1) Dim oPartNumProperty As Property Dim oDescripProperty As Property If Typeof oCompDef Is VirtualComponentDefinition Then 'Get the file property that contains the "Part Number" 'The file property is obtained from the virtual component definition Set oPartNumProperty = oCompDef.PropertySets _ .Item("Design Tracking Properties").Item("Part Number") 'Get the file property that contains the "Description" Set oDescripProperty = oCompDef.PropertySets _ .Item("Design Tracking Properties").Item("Description") Debug.Print Tab(ItemTab); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; Tab(30); _ oPartNumProperty.Value; Tab(70); oDescripProperty.Value Else 'Get the file property that contains the "Part Number" 'The file property is obtained from the parent 'document of the associated ComponentDefinition. Set oPartNumProperty = oCompDef.Document.PropertySets _ .Item("Design Tracking Properties").Item("Part Number") 'Get the file property that contains the "Description" Set oDescripProperty = oCompDef.Document.PropertySets _ .Item("Design Tracking Properties").Item("Description") Debug.Print Tab(ItemTab); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; Tab(30); _ oPartNumProperty.Value; Tab(70); oDescripProperty.Value 'Recursively iterate child rows if present. If Not oRow.ChildRows Is Nothing Then Call QueryBOMRowProperties(oRow.ChildRows, ItemTab) End If End If Next ItemTab = ItemTab - 3 End Sub
Klaas
I did a lot of work with BOM's & Apprentice a short while ago. I found that i couldn't export a BOM using Apprentice only. My end method was to use the Document method to get the BOM and use Apprentice for the rest. A bit of a mismatch i know but that was the only way i could get it to work.
The code example above is using the Document method, not Apprentice.
Hope that helps
Nacho
Nacho
Automation & Design Engineer
Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Can't find what you're looking for? Ask the community or share your knowledge.