private Component GetCasingComponent(AssemblyDocument assembly) { try { Component component = new Component(inventorApp); // Get file info component.FullFileName = assembly.FullFileName; PropertySet oPropSet = assembly.PropertySets["Design Tracking Properties"]; component.PartNumber = oPropSet["Part Number"].Value.ToString(); component.Description = oPropSet["Description"].Value.ToString(); oPropSet = assembly.PropertySets["Inventor User Defined Properties"]; component.FactoryNumber = oPropSet["Заводской номер"].Value.ToString(); component.ComponentType = ComponentTypes.Assembly; // Define assembly type string fileName = Path.GetFileName(component.FullFileName); component.CasingType = CasingTypes.Common; if (fileName.IndexOf("Комплект ЛСП") >= 0) { component.CasingType = CasingTypes.ЛСП; } if (fileName.IndexOf("Рама") >= 0) { component.CasingType = CasingTypes.Frame; } // Get property "Тип сборки" string casingType = "Common"; string propertyName = "Тип сборки"; if (Library.HasInventorProperty(oPropSet, propertyName)) { casingType = oPropSet[propertyName].Value.ToString(); } switch (casingType) { case "Common": component.CasingType = CasingTypes.Common; break; case "ЛСП": component.CasingType = CasingTypes.ЛСП; break; case "F": component.CasingType = CasingTypes.Frame; break; default: break; } return(component); } catch (Exception ex) { MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK); return(null); } }
private bool IsProfile(Document part) { try { bool ok = false; PropertySet oPropSet = part.PropertySets["Inventor User Defined Properties"]; string propertyName = "ProfileType"; if (Library.HasInventorProperty(oPropSet, propertyName)) { return(true); } return(ok); } catch (Exception ex) { MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK); return(false); } }
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); } }
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); } }
private Component GetAssemblyComponent(AssemblyDocument assembly) { try { Component component = new Component(inventorApp); // Get file info component.FullFileName = assembly.FullFileName; PropertySet oPropSet = assembly.PropertySets["Design Tracking Properties"]; component.PartNumber = oPropSet["Part Number"].Value.ToString(); component.Description = oPropSet["Description"].Value.ToString(); oPropSet = assembly.PropertySets["Inventor User Defined Properties"]; string propertyName = "Заводской номер"; if (Library.HasInventorProperty(oPropSet, propertyName)) { component.FactoryNumber = oPropSet[propertyName].Value.ToString(); } component.ComponentType = ComponentTypes.Assembly; // Define assembly type string fileName = Path.GetFileName(component.FullFileName); // Get property "Тип сборки" string assemblyType = "Common"; propertyName = "Тип сборки"; if (Library.HasInventorProperty(oPropSet, propertyName)) { assemblyType = oPropSet[propertyName].Value.ToString(); } switch (assemblyType) { case "Common": component.AssemblyType = AssemblyTypes.Common; break; case "Casing": component.AssemblyType = AssemblyTypes.Casing; casingComponent = component; SearchCasingComponents(); break; case "ТМ": component.AssemblyType = AssemblyTypes.ТМ; break; case "ТС": component.AssemblyType = AssemblyTypes.ТС; break; case "ТП": component.AssemblyType = AssemblyTypes.ТП; break; default: break; } return(component); } catch (Exception ex) { MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK); return(null); } }