private void ChangePartNumber(Component component, string add)
        {
            try
            {
                Document locDoc = (Document)inventorApp.Documents.Open(component.FullFileName, false);
                // Set properties of main assembly
                PropertySet oPropSet = locDoc.PropertySets["Design Tracking Properties"];
                // Eliminate tail of factorynumbers
                int    defisIndex = mainComponent.FactoryNumber.ToString().IndexOf("-");
                string factoryNumberClean;
                if (defisIndex > 0)
                {
                    factoryNumberClean = mainComponent.FactoryNumber.ToString().Substring(0, defisIndex);
                }
                else
                {
                    factoryNumberClean = mainComponent.FactoryNumber.ToString();
                }

                component.PartNumber = add + " " + factoryNumberClean;
                if (add != "ЛСП")
                {
                    oPropSet["Part Number"].Value = component.PartNumber;
                }
                // Change type of assembly
                oPropSet = locDoc.PropertySets["Inventor User Defined Properties"];
                Library.ChangeInventorProperty(oPropSet, "Тип сборки", add);
                locDoc.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK);
            }
        }
        private void PrepareRename(Component component)
        {
            try
            {
                // Get file info
                string filePath    = component.FullFileName;
                string fileName    = Path.GetFileNameWithoutExtension(filePath);
                string extention   = Path.GetExtension(filePath);
                string partNumber  = component.PartNumber;
                string description = component.Description;
                string directory   = Path.GetDirectoryName(filePath);

                if (description != string.Empty)
                {
                    description = " " + description;
                }
                // Check whether the PartNumber+Description = filename
                string newFileName = partNumber + description;
                Library.CheckFileName(ref newFileName);
                if (fileName == newFileName)
                {
                    return;
                }
                else
                {
                    // Replace the references
                    ReplaceCheck(System.IO.Path.Combine(directory, fileName + extention), System.IO.Path.Combine(directory, newFileName + extention));
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK);
            }
        }
示例#3
0
        // Create the OnPropertyChanged method to raise the event
        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
            if ((name == "AssemblyType") || (name == "CasingType"))
            {
                // Change inventor property
                Document    document     = inventorApp.Documents.Open(this.FullFileName, false);
                PropertySet oPropSet     = document.PropertySets["Inventor User Defined Properties"];
                string      propertyName = "Тип сборки";
                switch (name)
                {
                case "AssemblyType":
                    Library.ChangeInventorProperty(oPropSet, propertyName, this.assemblyType.ToString());
                    break;

                case "CasingType":
                    Library.ChangeInventorProperty(oPropSet, propertyName, this.CasingType.ToString());
                    break;

                default:
                    break;
                }
            }
        }
        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 ChangeProperties(ComponentOccurrence occurrence)
 {
     try
     {
         Document locDoc   = (Document)occurrence.Definition.Document;
         string   filePath = locDoc.FullFileName;
         if (IsComponentInSubDirectories(filePath))
         {
             // Set properties of main assembly
             PropertySet oPropSet = locDoc.PropertySets["Design Tracking Properties"];
             oPropSet["Project"].Value = mainComponent.PartNumber;
             oPropSet = locDoc.PropertySets["Inventor User Defined Properties"];
             Library.ChangeInventorProperty(oPropSet, "Заводской номер", mainComponent.FactoryNumber);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK);
     }
 }
        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);
            }
        }