private DataTable GetDataTable(Component specComponent) { DataTable resultTable = new DataTable(); // Format table resultTable.Columns.Add("VPNumber", typeof(string)); // Code from purchase roll resultTable.Columns.Add("PartNumber", typeof(string)); resultTable.Columns.Add("Description", typeof(string)); resultTable.Columns.Add("Quantity", typeof(string)); resultTable.Columns.Add("IsConsumable", typeof(bool)); resultTable.Columns.Add("UnitOfMeasure", typeof(string)); try { AssemblyDocument assembly = (AssemblyDocument)inventorApp.Documents.Open(specComponent.FullFileName, false); // Get BOM BOM bom = assembly.ComponentDefinition.BOM; bom.StructuredViewFirstLevelOnly = false; bom.StructuredViewEnabled = true; // Get merge settings bool mergeEnabled = false; string[] mergeExcludeList = new string[] { "жопа" }; bom.GetPartNumberMergeSettings(out mergeEnabled, out mergeExcludeList); // Set merge settings to false temporarily bom.SetPartNumberMergeSettings(false, mergeExcludeList); // Set a reference to the "Structured" BOMView BOMView bomView = bom.BOMViews["Структурированный"]; foreach (BOMRow BOMrow in bomView.BOMRows) { DataRow row = resultTable.NewRow(); ComponentDefinition componentDefinition = BOMrow.ComponentDefinitions[1]; Document locDoc = (Document)componentDefinition.Document; PropertySet oPropSet = locDoc.PropertySets["Design Tracking Properties"]; row["PartNumber"] = oPropSet["Part Number"].Value.ToString(); row["Description"] = oPropSet["Description"].Value.ToString(); oPropSet = locDoc.PropertySets["Inventor User Defined Properties"]; if (Library.HasInventorProperty(oPropSet, "Расходник")) { row["IsConsumable"] = oPropSet["Расходник"].Value; } else { row["IsConsumable"] = false; } row["Quantity"] = BOMrow.TotalQuantity; // Add row resultTable.Rows.Add(row); } // Restore BOM merge settings bom.SetPartNumberMergeSettings(mergeEnabled, mergeExcludeList); if (specComponent.FullFileName != mainComponent.FullFileName) { assembly.Close(); } return(resultTable); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK); return(null); } }