private void GetBomRowProperties(BOMRowsEnumerator bomRowsEnumerator, List <object[]> rows) { foreach (BOMRow row in bomRowsEnumerator) { ComponentDefinition componentDef = row.ComponentDefinitions[1]; var trackingSet = componentDef.Document.PropertySets[TrackingProperties]; // Assumes not virtual component (if so add conditional for that here) Property partNum = trackingSet["Part Number"]; Property description = trackingSet["Description"]; Property material = trackingSet["Material"]; object[] data = // order is important. a place to improve { row.ItemNumber, partNum.Value, row.ItemQuantity, description.Value, material.Value }; rows.Add(data); // iterate through child rows if (row.ChildRows != null) { GetBomRowProperties(row.ChildRows, rows); } } }
public void GetBomRowProperties(BOMRowsEnumerator rows, JArray bomRows) { const string TRACKING = "Design Tracking Properties"; foreach (BOMRow row in rows) { ComponentDefinition componentDef = row.ComponentDefinitions[1]; // Assumes not virtual component (if so add conditional for that here) Property partNum = componentDef.Document.PropertySets[TRACKING]["Part Number"]; Property descr = componentDef.Document.PropertySets[TRACKING]["Description"]; Property material = componentDef.Document.PropertySets[TRACKING]["Material"]; JObject bomRow = new JObject( new JProperty("row_number", row.ItemNumber), new JProperty("part_number", partNum.Value), new JProperty("quantity", row.ItemQuantity), new JProperty("description", descr.Value), new JProperty("material", material.Value) ); // LogTrace("Add BOM Row #" + row.ItemNumber); bomRows.Add(bomRow); // iterate through child rows if (row.ChildRows != null) { GetBomRowProperties(row.ChildRows, bomRows); } } }
private void SetPartNumbersInSheetMetalKitRecursive(BOMRowsEnumerator bomRows, Component component) { try { int AssemblyIndex = 0; int PartIndex = 20; foreach (BOMRow row in bomRows) { ComponentDefinition componentDefinition = row.ComponentDefinitions[1]; if (!(componentDefinition is VirtualComponentDefinition)) { Component subComponent; Document locDoc = (Document)componentDefinition.Document; PropertySet oPropSet = locDoc.PropertySets["Design Tracking Properties"]; // Check whether the component in casing directory string filePath = locDoc.FullFileName; if (filePath.IndexOf(casingDirectory) >= 0) { if (componentDefinition is AssemblyComponentDefinition) { // Change Part Number AssemblyIndex++; string add = AssemblyIndex.ToString(); if (add.Length == 1) { add = "0" + add; } oPropSet["Part Number"].Value = component.PartNumber + "." + add; subComponent = GetComponent(locDoc); // Recursive call SetPartNumbersInSheetMetalKitRecursive(row.ChildRows, subComponent); // Set component lvl subComponent.Level = component.Level + 1; // Add component component.Components.Add(subComponent); } else if (componentDefinition is PartComponentDefinition) { PartIndex++; oPropSet["Part Number"].Value = component.PartNumber + "." + PartIndex.ToString(); subComponent = GetComponent(locDoc); // Set component lvl subComponent.Level = component.Level + 1; // Add component component.Components.Add(subComponent); } } } } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK); } }
private void ReNumberSheetMetalKit(AssemblyDocument assembly, BOMRowsEnumerator bomRows) { try { // Get component of sheet metal kit Component component = GetComponent((Document)assembly); component.Level = 1; SetPartNumbersInSheetMetalKitRecursive(bomRows, component); componentsToReplace.Add(component); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK); } }
/// <summary> /// it create a JSON file with BOM Data /// </summary> /// <param name="doc"></param> /// <param name="eBomViewType"></param> public void GetBom(Document doc, BOMViewTypeEnum eBomViewType) { doc.Update(); try { string viewType = "Structured"; AssemblyDocument assemblyDoc = doc as AssemblyDocument; AssemblyComponentDefinition componentDef = assemblyDoc.ComponentDefinition; LogTrace("Create BOM Object"); BOM bom = componentDef.BOM; if (eBomViewType == BOMViewTypeEnum.kStructuredBOMViewType) { bom.StructuredViewEnabled = true; bom.StructuredViewFirstLevelOnly = false; } else { bom.PartsOnlyViewEnabled = true; viewType = "Parts Only"; } LogTrace("Create BOM Views"); BOMViews bomViews = bom.BOMViews; LogTrace("Create BOM View"); BOMView structureView = bomViews[viewType]; JArray bomRows = new JArray(); LogTrace("Get BOM Rows to Json"); BOMRowsEnumerator rows = structureView.BOMRows; LogTrace("Start to generate BOM data ..."); GetBomRowProperties(structureView.BOMRows, bomRows); LogTrace("Writing out bomRows.json"); File.WriteAllText(currentDirectory + "/bomRows.json", bomRows.ToString()); GetListOfDirectory(currentDirectory); } catch (Exception e) { LogError("Bom failed: " + e.ToString()); } }
private void QueryBOM(BOMRowsEnumerator bomRows) { for (int i = 1; i < bomRows.Count + 1; i++) { try { BOMRow bomRow = bomRows[i]; ComponentDefinition compDef = bomRow.ComponentDefinitions[1]; Document doc = (Document)compDef.Document; PropertySets propertySets = doc.PropertySets; PropertySet propertySet = propertySets["Design Tracking Properties"]; Property descProp = propertySet["Description"]; //Property weightProp Property materialProp = propertySet["Material"]; Property costProp = propertySet["Cost"]; matBreakdown.Rows.Add(bomRow.ItemQuantity, descProp.Value, materialProp.Value, costProp.Value); Marshal.ReleaseComObject(costProp); costProp = null; Marshal.ReleaseComObject(materialProp); materialProp = null; Marshal.ReleaseComObject(descProp); descProp = null; Marshal.ReleaseComObject(propertySet); propertySet = null; Marshal.ReleaseComObject(propertySets); propertySets = null; Marshal.ReleaseComObject(doc); doc = null; Marshal.ReleaseComObject(compDef); compDef = null; Marshal.ReleaseComObject(bomRow); bomRow = null; } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
private void SetPartNumbersInFrameRecursive(BOMRowsEnumerator bomRows, Component component) { try { int AssemblyIndex = 0; int PartIndex = 20; foreach (BOMRow row in bomRows) { ComponentDefinition componentDefinition = row.ComponentDefinitions[1]; if (!(componentDefinition is VirtualComponentDefinition)) { Component subComponent; Document locDoc = (Document)componentDefinition.Document; PropertySet oPropSet = locDoc.PropertySets["Design Tracking Properties"]; // Check whether the component in casing directory string filePath = locDoc.FullFileName; if (filePath.IndexOf(frameDirectory) >= 0) { if (componentDefinition is AssemblyComponentDefinition) { // Change Part Number AssemblyIndex++; string add = AssemblyIndex.ToString(); if (add.Length == 1) { add = "0" + add; } oPropSet["Part Number"].Value = component.PartNumber + "." + add; subComponent = GetComponent(locDoc); // Recursive call SetPartNumbersInFrameRecursive(row.ChildRows, subComponent); // Set component lvl subComponent.Level = component.Level + 1; // Add component component.Components.Add(subComponent); } else if (componentDefinition is PartComponentDefinition) { bool needToAdd = false; if (IsProfile(locDoc)) { // Check whether the profile has unique partnumber oPropSet = locDoc.PropertySets["Inventor User Defined Properties"]; string propertyName = "HasUniquePartNumber"; bool HasUniquePartNumber = false; if (Library.HasInventorProperty(oPropSet, propertyName)) { HasUniquePartNumber = (bool)oPropSet[propertyName].Value; } // Profile with unique partnumber if (HasUniquePartNumber) { needToAdd = true; } } else { // Not a profile needToAdd = true; } // If part is unique profile or not a profile if (needToAdd) { PartIndex++; oPropSet["Part Number"].Value = component.PartNumber + "." + PartIndex.ToString(); subComponent = GetComponent(locDoc); // Set component lvl subComponent.Level = component.Level + 1; // Add component component.Components.Add(subComponent); } } } } } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK); } }