示例#1
0
文件: Form1.cs 项目: waztdotnet/Api2
 private void Form1_Load(object sender, EventArgs e)
 {
     try
     {
         InvApp = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
     }
     catch
     {
         System.Windows.Forms.MessageBox.Show("Starting a New Inventor Session");
     }
     if (InvApp == null)
     {
         Type inventorAppType = System.Type.GetTypeFromProgID("Inventor.Application");
         InvApp         = System.Activator.CreateInstance(inventorAppType) as Inventor.Application;
         InvApp.Visible = true;
     }
     Inventor.Document Document = InvApp.ActiveDocument;
     if (Document.DocumentType == Inventor.DocumentTypeEnum.kAssemblyDocumentObject)
     {
         Inventor.AssemblyDocument AssemblyDocument = (Inventor.AssemblyDocument)Document;
         foreach (Inventor.OccurrencePattern OccurrencePattern in AssemblyDocument.ComponentDefinition.OccurrencePatterns)
         {
             if (OccurrencePattern.Type == Inventor.ObjectTypeEnum.kRectangularOccurrencePatternObject)
             {
                 Inventor.RectangularOccurrencePattern RectangularOccurrencePattern;
                 RectangularOccurrencePattern = (Inventor.RectangularOccurrencePattern)OccurrencePattern;
                 foreach (Inventor.OccurrencePatternElement OccurrencePatternElement in RectangularOccurrencePattern.OccurrencePatternElements)
                 {
                     cmbElements.Items.Add(OccurrencePatternElement.Name);
                 }
             }
         }
     }
 }
示例#2
0
        private void BtnSetSingelPartView_Click(object sender, EventArgs e)
        {
            Inventor.Document mDocument = mInvApplication.ActiveDocument;
            CModelViews       ModelView = new CModelViews(ref mInvApplication);

            ModelView.SetSingelView(ref mDocument);
        }
示例#3
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            Inventor.AssemblyDocument mAssemblyDocument;
            Inventor.Document         mDocument = InvApp.ActiveDocument;

            if (mDocument.DocumentType == Inventor.DocumentTypeEnum.kAssemblyDocumentObject)
            {
                mAssemblyDocument = (Inventor.AssemblyDocument)mDocument;
                Inventor.PartDocument mPartDocument;
                // Inventor.PartDocument mDocumentPart;
                foreach (Inventor.ComponentOccurrence mComponentOccurrence in mAssemblyDocument.ComponentDefinition.Occurrences)
                {
                    if (mComponentOccurrence.DefinitionDocumentType == Inventor.DocumentTypeEnum.kPartDocumentObject)
                    {
                        mPartDocument = mComponentOccurrence.Definition.Document;
                        GetExtents(ref mPartDocument);
                        if (cmbMaterials.SelectedIndex != -1)
                        {
                            mPartDocument.ComponentDefinition.Material.Name = cmbMaterials.Items[cmbMaterials.SelectedIndex].ToString();
                            lstNames.Items.Add(mPartDocument.DisplayName + "...Updated");
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Not an Assembly");
            }
        }
示例#4
0
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        // Developing
        private void SetDocumentWorkPlanes(ref Inventor.ComponentOccurrence Occurrence, bool VisableState)
        {
            Inventor.Document Document = Occurrence.Definition.Document;

            if (Occurrence.DefinitionDocumentType == Inventor.DocumentTypeEnum.kPartDocumentObject)
            {
                Inventor.PartDocument PartDocument = (Inventor.PartDocument)Document;
                foreach (Inventor.WorkPlane WP in PartDocument.ComponentDefinition.WorkPlanes)
                {
                    if (WP.Visible != VisableState)
                    {
                        WP.Visible = VisableState;
                    }
                }
            }
            else if (Occurrence.DefinitionDocumentType == Inventor.DocumentTypeEnum.kAssemblyDocumentObject)
            {
                Inventor.AssemblyDocument AssemblyDocument = (Inventor.AssemblyDocument)Document;
                foreach (Inventor.WorkPlane WP in AssemblyDocument.ComponentDefinition.WorkPlanes)
                {
                    if (WP.Visible != VisableState)
                    {
                        WP.Visible = VisableState;
                    }
                }
            }
        }
示例#5
0
        } //Single Call

        private void cmbMaterials_DropDown(object sender, EventArgs e)
        {
            Inventor.Document mDocument = InvApp.ActiveDocument;
            if (mDocument.DocumentType == Inventor.DocumentTypeEnum.kAssemblyDocumentObject)
            {
                Inventor.AssemblyDocument mAssemblyDocument = (Inventor.AssemblyDocument)mDocument;
                GetMaterial(ref mAssemblyDocument);
            }
        }
示例#6
0
文件: Form1.cs 项目: waztdotnet/Api2
        private void btnStart_Click(object sender, EventArgs e)
        {
            Inventor.AssemblyDocument AssemblyDocument;
            Inventor.Document         mDocument = InvApp.ActiveDocument;
            // Inventor.PartDocument PartDocument;
            Inventor.RectangularOccurrencePattern     RectangularOccurrencePattern;
            Collection <Inventor.ComponentOccurrence> name = new Collection <Inventor.ComponentOccurrence>();

            if (mDocument.DocumentType == Inventor.DocumentTypeEnum.kAssemblyDocumentObject)
            {
                AssemblyDocument = (Inventor.AssemblyDocument)mDocument;

                foreach (Inventor.OccurrencePattern OccurrencePattern in AssemblyDocument.ComponentDefinition.OccurrencePatterns)
                {
                    if (OccurrencePattern.Type == Inventor.ObjectTypeEnum.kRectangularOccurrencePatternObject)
                    {
                        RectangularOccurrencePattern = (Inventor.RectangularOccurrencePattern)OccurrencePattern;
                        foreach (Inventor.OccurrencePatternElement OccurrencePatternElement in RectangularOccurrencePattern.OccurrencePatternElements)
                        {
                            if (OccurrencePatternElement.Index > 0 || !OccurrencePatternElement.Suppressed)
                            {
                                //OccurrencePatternElement.Independent = true;
                                Inventor.ComponentOccurrences occs;
                                if (OccurrencePatternElement.Name == "Element:7")
                                {
                                    //OccurrencePatternElement.Independent = true;
                                    foreach (Inventor.ComponentOccurrence occ in OccurrencePatternElement.Occurrences)
                                    {
                                        if (occ.Name != "P00001 - 02:21" || occ.Name != "P00001 - 01:11")
                                        {
                                            lstNames.Items.Add(occ.Name + ": :" + OccurrencePatternElement.Name);
                                        }
                                        else
                                        {
                                            name.Add(occ);
                                        }
                                    }
                                }
                                // MessageBox.Show(OccurrencePatternElement.Name);
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Not an Assembly");
            }
        }
示例#7
0
        private void UserInputEvents_OnSelect(Inventor.ObjectsEnumerator JustSelectedEntities, ref Inventor.ObjectCollection MoreSelectedEntities, Inventor.SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Inventor.Point2d ViewPosition, Inventor.View View)
        {
            if (View.Parent != null)
            {
                Inventor.Document         Document         = (Inventor.Document)View.Parent;
                Inventor.AssemblyDocument AssemblyDocument = (Inventor.AssemblyDocument)Document;

                if (JustSelectedEntities.Count > 0)
                {
                    for (int i = JustSelectedEntities.Count; i >= 1; i--)
                    {
                        GetInventorObjType(JustSelectedEntities[i]);
                    }
                }
            }
        }
示例#8
0
 public NewSheetCreationForm(Inventor.Application inventorApp,
                             Inventor.Document drawingDoc)
 {
     try
     {
         this.inventorApp = inventorApp;
         sheetSettings    = new SheetSettings(inventorApp, drawingDoc);
         ShowMyDialog     = "Constructor was called.";
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message, "Error Launching Sheet Manager", MessageBoxButtons.OK,
                         MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
         this.Close();
     }
     InitializeComponent();
 }
示例#9
0
        private void UserInputEvents_OnSelect(Inventor.ObjectsEnumerator JustSelectedEntities, ref Inventor.ObjectCollection MoreSelectedEntities, Inventor.SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Inventor.Point2d ViewPosition, Inventor.View View)
        {
            if (View.Parent != null)
            {
                Inventor.Document Document = (Inventor.Document)View.Parent;
                if (Document.DocumentType == Inventor.DocumentTypeEnum.kAssemblyDocumentObject)
                {
                    Inventor.AssemblyDocument AssemblyDocument = (Inventor.AssemblyDocument)Document;

                    OnSelectionChange(ref AssemblyDocument, ref MoreSelectedEntities);
                }
                else
                {
                    Inventor.AssemblyDocument AssemblyDocument = null;
                    JustSelectedEntities = null;
                    OnSelectionChange(ref AssemblyDocument, ref MoreSelectedEntities);
                }
            }
        }
示例#10
0
        public void ProcessFileRefs(Inventor.File File)
        {
            foreach (Inventor.FileDescriptor DescriptedFile in File.ReferencedFileDescriptors)
            {
                if (!DescriptedFile.ReferenceMissing)
                {
                    if (DescriptedFile.ReferencedFileType != Inventor.FileTypeEnum.kForeignFileType)
                    {
                        if (DescriptedFile.ReferencedFileType != Inventor.FileTypeEnum.kUnknownFileType)
                        {
                            Inventor.Document Document = mInvApplication.Documents.Open(DescriptedFile.FullFileName, true);
                            SetModelView(Document);

                            Document.Close(false);
                            //  ProcessFileRefs(DescriptedFile.ReferencedFile);
                        }
                    }
                }
            }
        }
示例#11
0
        private void CreateDocument(out Inventor.Document Document, Inventor.DocumentTypeEnum DocumentType, string TemplateFileName)
        {
            Inventor.UnitsOfMeasure UnitsOfMeasure;
            if (TemplateFileName != "")
            {
                Inventor.FileOptions FileOptions = InvApp.FileOptions;
                TemplateFileName = FileOptions.TemplatesPath + "\\" + TemplateFileName;
                Document         = InvApp.Documents.Add(DocumentType, TemplateFileName, true);
            }
            else
            {
                Document = InvApp.Documents.Add(DocumentType, "", true);
            }

            UnitsOfMeasure                        = Document.UnitsOfMeasure;
            UnitsOfMeasure.LengthUnits            = Inventor.UnitsTypeEnum.kMillimeterLengthUnits;
            UnitsOfMeasure.AngleUnits             = Inventor.UnitsTypeEnum.kDegreeAngleUnits;
            UnitsOfMeasure.MassUnits              = Inventor.UnitsTypeEnum.kKilogramMassUnits;
            UnitsOfMeasure.TimeUnits              = Inventor.UnitsTypeEnum.kSecondTimeUnits;
            UnitsOfMeasure.LengthDisplayPrecision = 3;
            UnitsOfMeasure.AngleDisplayPrecision  = 3;
        }
示例#12
0
 private void SetModelView(Inventor.Document mDocument)
 {
     Inventor.SurfaceBody mSurfaceBody;
     if (mDocument.DocumentType == Inventor.DocumentTypeEnum.kPartDocumentObject)
     {
         Inventor.PartDocument mPartDocument = (Inventor.PartDocument)mDocument;
         if (mPartDocument.DocumentSubType.DocumentSubTypeID != "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}")
         {
             Inventor.ComponentDefinition mComponentDefinition;
             mComponentDefinition = (Inventor.ComponentDefinition)mPartDocument.ComponentDefinition;
             mSurfaceBody         = mComponentDefinition.SurfaceBodies[1];
             GetFaceToSetView(mSurfaceBody, mPartDocument);
             mPartDocument.Save2(false);
         }
         else
         {
             return;
         }
     }
     else
     {
         return;
     }
 }
示例#13
0
        public void MirrorPart()
        {
            Inventor.AssemblyDocument    AssemblyDocument;
            Inventor.ComponentDefinition ComponentDefinition;
            Inventor.ComponentOccurrence ComponentOccurrence;
            Inventor.Document            Document = InvApp.ActiveDocument;
            Inventor.PartDocument        PartDocument;


            if (Document.DocumentType == Inventor.DocumentTypeEnum.kAssemblyDocumentObject)
            {
                AssemblyDocument = (Inventor.AssemblyDocument)Document;
                Inventor.WorkPlane WorkPlane;

                WorkPlane = AssemblyDocument.ComponentDefinition.WorkPlanes["XZ Plane"];

                double XNormal;
                double YNormal;
                double ZNormal;

                Inventor.Plane Plane;

                Plane = WorkPlane.Plane;
                //Get the Normals
                XNormal = Plane.Normal.X;
                YNormal = Plane.Normal.Y;
                ZNormal = Plane.Normal.Z;


                //Mirroring matrix
                Inventor.Matrix MirroringMatrix = InvApp.TransientGeometry.CreateMatrix();
                Inventor.Matrix MMatrix         = InvApp.TransientGeometry.CreateMatrix();

                double[] MirroringMatrixData = new double[16];
                MirroringMatrixData[0] = 1 - 2 * XNormal * XNormal;
                MirroringMatrixData[1] = -2 * XNormal * YNormal;
                MirroringMatrixData[2] = -2 * XNormal * ZNormal;
                MirroringMatrixData[3] = 0;

                MirroringMatrixData[4] = -2 * XNormal * YNormal;
                MirroringMatrixData[5] = 1 - 2 * YNormal * YNormal;
                MirroringMatrixData[6] = -2 * ZNormal * YNormal;
                MirroringMatrixData[7] = 0;

                MirroringMatrixData[8]  = -2 * XNormal * ZNormal;
                MirroringMatrixData[9]  = -2 * ZNormal * YNormal;
                MirroringMatrixData[10] = 1 - 2 * ZNormal * ZNormal;
                MirroringMatrixData[11] = 0;

                MirroringMatrixData[12] = 0;
                MirroringMatrixData[13] = 0;
                MirroringMatrixData[14] = 0;
                MirroringMatrixData[15] = 1;


                //Hand over the marix Data
                MirroringMatrix.PutMatrixData(ref MirroringMatrixData);

                ComponentOccurrence = AssemblyDocument.ComponentDefinition.Occurrences[1];
                ComponentDefinition = ComponentOccurrence.Definition;

                MirroringMatrix.PostMultiplyBy(ComponentOccurrence.Transformation);

                AssemblyDocument.ComponentDefinition.Occurrences.AddByComponentDefinition(ComponentDefinition, MirroringMatrix);
            }
            else if (Document.DocumentType == Inventor.DocumentTypeEnum.kPartDocumentObject)
            {
                PartDocument = (Inventor.PartDocument)Document;
            }
        }
示例#14
0
        private void GetAllPartsInBom(ref Inventor.AssemblyDocument AssemblyDocument)
        {
            Inventor.BOM bOM = AssemblyDocument.ComponentDefinition.BOM;
            bOM.PartsOnlyViewEnabled  = true;
            bOM.StructuredViewEnabled = true;

            Inventor.BOMView           bOMViews = AssemblyDocument.ComponentDefinition.BOM.BOMViews[3];
            Inventor.BOMRowsEnumerator bOMRows  = bOMViews.BOMRows;

            int length = bOMRows.Count;

            for (int i = 1; i <= length; i++)
            {
                Inventor.BOMRow bOMRow = bOMViews.BOMRows[i];
                if (true)
                {
                    Inventor.Document Document = bOMRow.ComponentDefinitions[1].Document;

                    if (Document.DocumentType == Inventor.DocumentTypeEnum.kPartDocumentObject)
                    {
                        string PartNumber = "";
                        PartNumber = Document.PropertySets["{32853F0F-3444-11d1-9E93-0060B03C1CA6}"].get_ItemByPropId((int)Inventor.PropertiesForDesignTrackingPropertiesEnum.kPartNumberDesignTrackingProperties).Value;

                        if (CFileNames.IsPartNumberPreFixsMatch(PartNumber, PartNumberID))
                        {
                            //Inventor.PartDocument PartDocument = (Inventor.PartDocument)Document;
                            Inventor.PartDocument PartDocument = (Inventor.PartDocument)mInvApplication.Documents.Open(Document.FullFileName, true);
                            if (PartDocument.Open)
                            {
                                FileSaveUrl = PartDocument.FullFileName.Substring(0, PartDocument.FullFileName.LastIndexOf("."));


                                if ((!PartDocument.ComponentDefinition.IsContentMember) || !PartDocument.ComponentDefinition.IsiPartFactory || !PartDocument.ComponentDefinition.IsiPartMember)
                                {
                                    //check for Flat Pattern
                                    if (PartDocument.SubType == "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}")
                                    {
                                        DXFExport(FileSaveUrl, PartDocument);
                                        ListComponents.Items.Add("SM Qty " + bOMRow.ItemQuantity.ToString() + " Part * " + PartDocument.PropertySets["{32853F0F-3444-11d1-9E93-0060B03C1CA6}"].get_ItemByPropId((int)Inventor.PropertiesForDesignTrackingPropertiesEnum.kPartNumberDesignTrackingProperties).Value + " * ");
                                    }
                                    else
                                    {
                                        //if (true)
                                        //{
                                        //    logWriter.WriteAsync(PartNumber);
                                        //}
                                        DoCommandExportDXF(PartDocument);
                                        ListComponents.Items.Add("Cmmd Qty " + bOMRow.ItemQuantity.ToString() + " Part * " + PartDocument.PropertySets["{32853F0F-3444-11d1-9E93-0060B03C1CA6}"].get_ItemByPropId((int)Inventor.PropertiesForDesignTrackingPropertiesEnum.kPartNumberDesignTrackingProperties).Value + " * ");
                                    }
                                }
                                // ListComponents.Items.Add("Qty " + bOMRow.ItemQuantity.ToString() + " Part * " + PartDocument.PropertySets["{32853F0F-3444-11d1-9E93-0060B03C1CA6}"].get_ItemByPropId((int)Inventor.PropertiesForDesignTrackingPropertiesEnum.kPartNumberDesignTrackingProperties).Value + " * ");
                            }
                            else
                            {
                            }
                            PartDocument.Close(false);
                            PartDocument = null;
                        }
                    }
                    else if (Document.DocumentType == Inventor.DocumentTypeEnum.kAssemblyDocumentObject)
                    {
                        Inventor.AssemblyDocument AssemDocument = (Inventor.AssemblyDocument)Document;
                        //ListComponents.Items.Add("Qty " + bOMRow.ItemQuantity.ToString() + " Part * " + AssemDocument.PropertySets["{32853F0F-3444-11d1-9E93-0060B03C1CA6}"].get_ItemByPropId((int)Inventor.PropertiesForDesignTrackingPropertiesEnum.kPartNumberDesignTrackingProperties).Value + " * ");
                        ListComponents.Items.Add("Qty " + bOMRow.ItemQuantity.ToString() + " Part * " + AssemDocument.PropertySets["{32853F0F-3444-11d1-9E93-0060B03C1CA6}"].get_ItemByPropId((int)Inventor.PropertiesForDesignTrackingPropertiesEnum.kPartNumberDesignTrackingProperties).Value + " * ");
                    }
                    Document = null;
                }
            }
        }
示例#15
0
 public void SetSingelView(ref Inventor.Document mDocument)
 {
     SetModelView(mDocument);
 }