Example #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            assembly = (AssemblyDocument)inventorApp.ActiveDocument;

            position_X = Convert.ToString(Math.Abs(Convert.ToInt32(assembly.ComponentDefinition.Parameters.ModelParameters[inventorModelParameterPart1].Value * 57.3f)));
            position_Y = Convert.ToString(Math.Abs(Convert.ToInt32(assembly.ComponentDefinition.Parameters.ModelParameters[inventorModelParameterPart2].Value * 57.3f)));

            string value = position_X + " " + position_Y;


            try
            {
                serialPort.WriteLine(value);
            }
            catch (Exception)
            {
                timer1.Stop();
                isConnectLabel.Text = "Not Connected";

                MessageBox.Show("Arduino disconnected.");
            }

            positionXLabel.Text = "POSX: " + position_X;
            positionYLabel.Text = "POSY: " + position_Y;
        }
Example #2
0
 public Sticker(Inventor.Document pDoc, Inventor.Application m_InvApp)
 {
     InitializeComponent();
     invApp = m_InvApp;
     m_TG   = invApp.TransientGeometry;
     if (pDoc.DocumentType == DocumentTypeEnum.kPartDocumentObject)
     {
         m_Doc = (PartDocument)pDoc;
     }
     if (pDoc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
     {
         m_Asm   = (AssemblyDocument)pDoc;
         compDef = m_Asm.ComponentDefinition;
         box     = compDef.RangeBox;
     }
     valXML  = new List <string>();
     attrXML = new List <string>();
     if (System.IO.File.Exists(@"C:\ProgramData\Autodesk\Inventor Addins\Stickers.xml"))
     {
         tbl = new InvDoc.XML(@"C:\ProgramData\Autodesk\Inventor Addins\Stickers.xml");
         tbl.ReadXML("Sticker", ref valXML, ref attrXML);
         if (attrXML.Count != 0)
         {
             for (int i = 0; i < attrXML.Count; i++)
             {
                 if (attrXML[i].StartsWith("Name="))
                 {
                     string XMLVal = tbl.substring(attrXML[i], "Name=");
                     this.comboBox1.Items.Add(XMLVal);
                 }
             }
         }
     }
 }
Example #3
0
        public ArduinoControl()
        {
            InitializeComponent();

            this.TopMost = true;

            getAvailableComPorts();
            initializeSerialPorts();



            try
            {
                inventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");

                assembly = (AssemblyDocument)inventorApp.ActiveDocument;

                assembly.ComponentDefinition.Parameters.ModelParameters[inventorModelParameterPart1].Value = 0;
                assembly.ComponentDefinition.Parameters.ModelParameters[inventorModelParameterPart2].Value = 0;
                assembly.Update();
            }
            catch (Exception)
            {
                MessageBox.Show("cannot connect to Inventor");
            }
        }
        public MyBalloon(Inventor.Document oDoc)
        {
            if (oDoc.DocumentType == DocumentTypeEnum.kDrawingDocumentObject && InvDoc.u.referendedDoc(oDoc).DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
            {
                m_DrwDoc  = (Inventor.DrawingDocument)oDoc;
                m_AsmDoc  = (Inventor.AssemblyDocument)InvDoc.u.referendedDoc(oDoc);
                invApp    = (Inventor.Application)oDoc.Parent;
                cmdMgr    = invApp.CommandManager;
                interEvts = cmdMgr.CreateInteractionEvents();
                selEvts   = interEvts.SelectEvents;
                selEvts.AddSelectionFilter(SelectionFilterEnum.kDrawingCurveSegmentFilter);
                selEvts.SingleSelectEnabled = true;
                selEvts.OnSelect           += new SelectEventsSink_OnSelectEventHandler(selectEvts);
                mouseEvts = interEvts.MouseEvents;
                mouseEvts.MouseMoveEnabled = true;
                mouseEvts.OnMouseClick    += new MouseEventsSink_OnMouseClickEventHandler(mouseClick);
                mouseEvts.OnMouseMove     += new MouseEventsSink_OnMouseMoveEventHandler(mouseMove);
                objs = invApp.TransientObjects.CreateObjectCollection();

                interEvts.StatusBarText = "Первая точка выноски:";
                interEvts.Start();
                //dcs = (Inventor.DrawingCurveSegment)cmdMgr.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Выберите компонент:");

                //m_Type = obj.GetType();
                //compOcc = (ComponentOccurrence)m_Type.GetProperty("ContainingOccurrence");

                //interEvts.InteractionGraphics;
                //if (obj.
                //    dcs.Parent.ModelGeometry.GetType() == Inventor.ObjectTypeEnum.kEdgeProxyObject)
                //{

                //}
            }
        }
Example #5
0
        private InvAssemblyDocument InternalAddAssemblyDocument()
        {
            string assemblyTemplateFile = @"C:\Users\Public\Documents\Autodesk\Inventor 2013\Templates\Standard.iam";

            Inventor.Application      invApp           = (Inventor.Application)InventorServices.Persistence.PersistenceManager.InventorApplication;
            Inventor.AssemblyDocument assemblyDocument = (Inventor.AssemblyDocument)invApp.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, assemblyTemplateFile, true);
            return(InvAssemblyDocument.ByInvAssemblyDocument(assemblyDocument));
        }
Example #6
0
        public void _buttonDef1_OnExecute(NameValueMap Context)
        {
            Inventor.Document Document = m_inventorApplication.ActiveDocument;
            if (Document.DocumentType == Inventor.DocumentTypeEnum.kAssemblyDocumentObject)
            {
                Inventor.AssemblyDocument AssemblyDocument = (Inventor.AssemblyDocument)Document;

                IComDialog comDialog = new UIMain();
                comDialog.RunUI(m_inventorApplication);
            }
        }
Example #7
0
 public Utility(Document newDoc)
 {
     m_doc = newDoc;
     if (m_doc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
     {
         m_Asm = (AssemblyDocument)m_doc;
     }
     if (m_doc.DocumentType == DocumentTypeEnum.kDrawingDocumentObject)
     {
         m_Drw = (DrawingDocument)m_doc;
     }
 }
Example #8
0
            private void Grid_CellEndEdit(object sender, DataGridViewCellEventArgs e)
            {
                if (e.ColumnIndex == 3 || e.ColumnIndex == 4)
                {
                    Inventor.Application      invApp   = Macros.StandardAddInServer.m_inventorApplication;
                    Inventor.Document         oDoc     = invApp.ActiveDocument;
                    Inventor.AssemblyDocument m_AsmDoc = (AssemblyDocument)InvDoc.u.referendedDoc(oDoc as Document);
                    Inventor.BOM m_BOM = m_AsmDoc.ComponentDefinition.BOM;
                    m_BOM.StructuredViewEnabled = true;
                    if (!m_BOM.StructuredViewFirstLevelOnly)
                    {
                        m_BOM.StructuredViewFirstLevelOnly = true;
                    }
                    Inventor.BOMView m_BOMView = m_BOM.BOMViews["Структурированный"];
                    foreach (Inventor.BOMRow row in m_BOMView.BOMRows)
                    {
                        Inventor.ComponentDefinition oCompDef = row.ComponentDefinitions[1];
                        oDoc = (Inventor.Document)oCompDef.Document;
                        string partNumber = (string)oDoc.PropertySets[3][2].Value;
                        string desc       = (string)oDoc.PropertySets[3][14].Value;
                        if (partNumber == val1 && desc == val2)
                        {
                            switch (x)
                            {
                            case 3:
                                oDoc.PropertySets[3][2].Value = ((DataGridView)sender)[x, y].Value.ToString();
                                break;

                            case 4:
                                oDoc.PropertySets[3][14].Value = ((DataGridView)sender)[x, y].Value.ToString();
                                break;
                            }
                            break;
                        }
                    }
                }
            }
        public static String Test()
        {
            if (_invApp.Documents.Count == 0)
            {
                return "Need to open an Assembly document or Part document";

            }

            if (_invApp.ActiveDocument.DocumentType != DocumentTypeEnum.kAssemblyDocumentObject && _invApp.ActiveDocument.DocumentType != DocumentTypeEnum.kPartDocumentObject)
            {
                return "Need to open an Assembly document or Part document";
            }

            // Here is a slight variation in the code where I look for a PART vs a ASSEMBLY File

            if (_invApp.ActiveDocument.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
            {
                AssemblyDocument doc = default(AssemblyDocument);
                doc = (AssemblyDocument)_invApp.ActiveDocument;
                type = "Assembly";
            }

            if (_invApp.ActiveDocument.DocumentType == DocumentTypeEnum.kPartDocumentObject)
            {
                PartDocument doc = default(PartDocument);
                doc = (PartDocument)_invApp.ActiveDocument;
                type = "Part";
            }

            //Gets Current document name!
            name = (_invApp.ActiveDocument.DisplayName);

            //For Assembly Files
            if (type == "Assembly")
            {
                ASSEMBLY_DOCUMENT = (Inventor.AssemblyDocument)_invApp.ActiveDocument;
                AssemblyComponentDefinitions assDef = ASSEMBLY_DOCUMENT.ComponentDefinitions;
                GenerateExportList(assDef);
                //GenerateExportList(ASSEMBLY_DOCUMENT.ComponentDefinition.Parameters);
            }

            if(type == "Part")
            {
                PART_DOCUMENT = (Inventor.PartDocument)_invApp.ActiveDocument;
                PartFeatures pFeat = PART_DOCUMENT.ComponentDefinition.Features;
                GenerateExportList(pFeat);
            }

            //Saves the info into XML base
            SaveFile xSave = new SaveFile(program, type, length, name, attributesText);

            return "This exported correctly!";
        }
Example #10
0
        public Table(Inventor.Document pDoc, Inventor.Application m_InvApp)
        {
            boundsScreen = Screen.PrimaryScreen.WorkingArea;
            scale        = boundsScreen.Width * 0.465 / 16.5;
            m_TG         = m_InvApp.TransientGeometry;
            switch (pDoc.DocumentType)
            {
            case DocumentTypeEnum.kAssemblyDocumentObject:
                m_AsmDoc = (AssemblyDocument)pDoc;
                break;

            case DocumentTypeEnum.kDrawingDocumentObject:
                m_DrwDoc = (DrawingDocument)pDoc;
                m_AsmDoc = (AssemblyDocument)InvDoc.u.referendedDoc(m_DrwDoc as Document);    //m_DrwDoc.ReferencedDocuments.Count];
                if (m_AsmDoc.FullDocumentName.EndsWith(">"))
                {
                    m_AsmDoc = (AssemblyDocument)((Inventor.Application)m_AsmDoc.Parent).Documents.Open(m_AsmDoc.FullFileName, false);
                }
                break;
            }
            path          = pDoc.FullFileName.ToString();
            path          = path.Substring(0, path.LastIndexOf('\\'));
            m_BOM         = m_AsmDoc.ComponentDefinition.BOM;
            partNumberAsm = m_AsmDoc.PropertySets[3][2].Value.ToString();
            m_BOM.StructuredViewEnabled = true;
            if (!m_BOM.StructuredViewFirstLevelOnly)
            {
                m_BOM.StructuredViewFirstLevelOnly = true;
            }
            //if (m_BOM.StructuredViewFirstLevelOnly)
            //    m_BOM.StructuredViewFirstLevelOnly = false;
            m_BOMView = m_BOM.BOMViews["Структурированный"];
            InitializeComponent();
            this.ClientSize        = Screen.PrimaryScreen.WorkingArea.Size;
            this.Format.Width      = (int)(0.6 * scale);
            this.Zone.Width        = (int)(0.6 * scale);
            this.Position.Width    = (int)(0.8 * scale);
            this.PartNumber.Width  = (int)(5 * scale);
            this.Description.Width = (int)(6.3 * scale);
            this.Count.Width       = (int)(1 * scale);
            this.Note.Width        = (int)(2.2 * scale);

            this.FormatVar.Width      = this.Format.Width;
            this.ZoneVar.Width        = this.Zone.Width;
            this.PositionVar.Width    = this.Position.Width;
            this.PartNumberVar.Width  = this.PartNumber.Width;
            this.DescriptionVar.Width = this.Description.Width;
            this.CountVar.Width       = this.Count.Width;
            this.NoteVar.Width        = this.Note.Width;

            int offset = (int)(0.004 * boundsScreen.Width);
            int width  = dgv.Columns.OfType <DataGridViewColumn>().Sum(e => e.Width);

            width                   += 22;
            this.dgv.Size            = new System.Drawing.Size(width, this.Size.Height - menu.Height - 50 /*(int)(boundsScreen.Height*0.08)*/);
            this.dgv.Location        = new System.Drawing.Point(0, this.menu.Bounds.Bottom);
            this.dgvVar.Size         = dgv.Size;
            this.dgvVar.Location     = new System.Drawing.Point(dgv.Location.X + dgv.Width, dgv.Location.Y);
            this.dgv.RowHeadersWidth = this.dgvVar.RowHeadersWidth = 20;

            label1.Location = new System.Drawing.Point(dgv.Location.X + width / 2 - label1.Width / 2, dgv.Location.Y /*- label1.Width/2*/ - 24);
            label2.Location = new System.Drawing.Point(dgv.Location.X + width + width / 2 - label2.Width / 2, dgv.Location.Y /*- label2.Width/2*/ - 24);
            label2.Visible  = false;
            dgvVar.Visible  = false;

            width *= 2;
            width += (int)(0.001 * boundsScreen.Width);
            int bottomButton = dgv.Bounds.Bottom + (boundsScreen.Height - dgv.Bounds.Bottom) / 2 - button1.Bounds.Height / 2;

            this.button1.Width    = button2.Width = button3.Width = txtBox.Width = /*txtBox3.Width = */ (int)(0.045 * boundsScreen.Width);
            this.button1.Location = new System.Drawing.Point(dgvVar.Bounds.Right + offset, this.menu.Bounds.Bottom + offset);
            this.button3.Location = new System.Drawing.Point(button1.Bounds.Left, button1.Bounds.Bottom + offset);
            this.button2.Location = new System.Drawing.Point(button3.Bounds.Left, button3.Bounds.Bottom + offset);
            this.lbl.Location     = new System.Drawing.Point(button2.Bounds.Left, button2.Bounds.Bottom + offset);
            this.txtBox.Location  = new System.Drawing.Point(button2.Bounds.Left, lbl.Bounds.Bottom + offset);
            //this.lbl3.Location = new System.Drawing.Point(button2.Bounds.Left, txtBox.Bounds.Bottom + offset);
            //this.txtBox3.Location = new System.Drawing.Point(button2.Bounds.Left, lbl3.Bounds.Bottom + offset);

            //initSpec(dgv);

            tbl = tbl ?? new TableInv(m_DrwDoc, @"C:\ProgramData\Autodesk\Inventor Addins\Sequence.xml");
            //if (txtBox.Text != "") tbl.split = txtBox.Text;
            //VariableDataForSpec vd = new VariableDataForSpec((Document)m_AsmDoc);
            //List<string> lst = vd.AttribLoad("Split");
            AttributeSet attSet;

            if (m_AsmDoc.AttributeSets.get_NameIsUsed("Split"))
            {
                attSet = m_AsmDoc.AttributeSets["Split"];

                if (attSet.Count != 0)
                {
                    txtBox.Text = attSet[1].Value.ToString();
                }
            }

            tbl.addTable(m_BOMView);
            if (tbl.countPerf == 0)
            {
                tbl.showTable(dgv, 0, 100, tbl.group, varData: false);
            }
            else
            {
                tbl.showTable(dgv, 0, 100, tbl.group, varData: false);
                tbl.showTable(dgvVar, 100, 5000, tbl.group, varData: true);
                dgvVar.Visible = true;
            }
            //tbl.asmDoc = m_AsmDoc;
            balloon();
            dgv.RowHeaderMouseClick += dataGridView1_RowHeaderMouseClick;
            dgv.KeyDown             += dgv_KeyDown;
        }
Example #11
0
        //  Load template file and extract related parameters
        public List <InventorParameterStructure> LoadInventorTemplateParameters(string fullPath)
        {
            NLogger.LogText("Entered LoadInventorTemplateParameters method");

            var        inventorParams = new List <InventorParameterStructure>();
            Parameters InventorParams = null;

            //  TODO: HANDLE THE HARDCODED PATH
            //var rootPath = Utilities.GetBIM360RootPath();
            //var fullPath = rootPath + @"ATDSK ​DEV​\Sample Project\Project Files\Libraries\" + templateName;

            try
            {
                NLogger.LogText($"Try opening assembly document {fullPath}");

                try
                {
                    NLogger.LogText($"Try opening assembly document {fullPath} with LOD specified");

                    NameValueMap oOptions = m_InventorApplication.TransientObjects.CreateNameValueMap();
                    oOptions.Add("LevelOfDetailRepresentation", "LOD1");

                    m_AssemblyDocument = (AssemblyDocument)m_InventorApplication.Documents.OpenWithOptions(fullPath, oOptions, false);

                    NLogger.LogText($"Opening assembly document {fullPath} with LOD specified suceeded");
                }
                catch
                {
                    NLogger.LogText($"Failed opening assembly document {fullPath} with LOD specified. Try to open it without LOD specified");

                    m_AssemblyDocument = (AssemblyDocument)m_InventorApplication.Documents.Open(fullPath, false);

                    NLogger.LogText($"Opening assembly document {fullPath} without LOD specified suceeded");
                }

                //  Load params
                NLogger.LogText("Load assembly document parameters");
                InventorParams = m_AssemblyDocument.ComponentDefinition.Parameters;
            }
            catch (Exception ex)
            {
                NLogger.LogText("An error has occurred casting to an Inventor Assembly document. Try casting to a Part document");

                try
                {
                    NLogger.LogText($"Try opening part document {fullPath}");

                    m_PartDocument = (PartDocument)m_InventorApplication.Documents.Open(fullPath, false);

                    NLogger.LogText($"Opening part document {fullPath} suceeded");

                    //  Load params
                    NLogger.LogText("Load Part document parameters");

                    InventorParams = m_PartDocument.ComponentDefinition.Parameters;
                }
                catch (Exception ex1)
                {
                    NLogger.LogText("An error has occurred casting to an Inventor Part document");

                    NLogger.LogError(ex1);
                    throw (ex1);
                }
            }

            NLogger.LogText("Create 'InventorParameterStructure'");

            for (int h = 1; h <= InventorParams.Count; h++)
            {
                if (ConfigUtilities.GetInventorElementShowOnlyKeys().ToLower() == "true")
                {
                    if (InventorParams[h].IsKey)
                    {
                        inventorParams.Add(new InventorParameterStructure {
                            Name = InventorParams[h].Name.ToString()
                        });
                    }
                }
                else
                {
                    inventorParams.Add(new InventorParameterStructure {
                        Name = InventorParams[h].Name.ToString()
                    });
                }
            }

            NLogger.LogText("Remove documents from  Inventor application instance");

            m_InventorApplication.Documents.CloseAll();

            NLogger.LogText("Exit LoadInventorTemplateParameters method");

            return(inventorParams);
        }
Example #12
0
 private InvAssemblyDocument(Inventor.AssemblyDocument invAssemblyDocument)
 {
     InternalAssemblyDocument = invAssemblyDocument;
 }
Example #13
0
 public static InvAssemblyDocument ByInvAssemblyDocument(Inventor.AssemblyDocument invAssemblyDocument)
 {
     return(new InvAssemblyDocument(invAssemblyDocument));
 }