Esempio n. 1
0
        /**
         * C#读取和修改Inventor模型的属性
         */
        private static void AFunction()
        {
            Inventor.Application inventorApp = null;
            try
            {
                inventorApp = Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
            }
            catch
            {
                var inventorType = Type.GetTypeFromProgID("Inventor.Application");
                inventorApp         = Activator.CreateInstance(inventorType) as Inventor.Application;
                inventorApp.Visible = true;
            }

            AssemblyDocument asmDoc = (AssemblyDocument)inventorApp.Documents.Open(@"Path", true);

            AssemblyComponentDefinition asmDef = asmDoc.ComponentDefinition;

            foreach (ComponentOccurrence oOcc in asmDef.Occurrences)
            {
                Document oDoc = (Document)oOcc.Definition.Document;
                // using GUID to find the "Summary Information"
                PropertySet oPS = oDoc.PropertySets["{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"];
                // using proID to find TITLE
                Inventor.Property oP = oPS.ItemByPropId[(int)PropertiesForSummaryInformationEnum.kTitleSummaryInformation];
                oP.Value = oP.Value + "new";
            }
        }
Esempio n. 2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text.Length > 0)
            {
                PartDocument oDoc = (PartDocument)mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject,
                                                                     mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject),
                                                                     true);

                //Author property is contained in "Inventor Summary Information" Set
                PropertySet oPropertySet = oDoc.PropertySets["{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"];

                //Using Inventor.Property to avoid confusion
                Inventor.Property oProperty = oPropertySet["Author"];

                oProperty.Value = TextBox1.Text;

                //Get "Inventor User Defined Properties" set
                oPropertySet = oDoc.PropertySets["{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"];

                //Create new property
                oProperty = oPropertySet.Add("Parts R Us", "Supplier", null);

                //Save document, prompt user for filename
                FileDialog oDLG = null;
                mApp.CreateFileDialog(out oDLG);

                oDLG.FileName    = @"C:\Temp\NewPart.ipt";
                oDLG.Filter      = "Inventor Files (*.ipt)|*.ipt";
                oDLG.DialogTitle = "Save Part";

                oDLG.ShowSave();

                if (oDLG.FileName != "")
                {
                    oDoc.SaveAs(oDLG.FileName, false);
                    oDoc.Close(true);
                }
            }
        }