示例#1
0
        public override void ExecuteCommand()
        {
            TransientGeometry oTransGeo;

            oTransGeo         = m_inventorApplication.TransientGeometry;
            m_connectToaccess = new ConnectToAccess(m_filepath, m_filename);

            string name   = m_insertOutlineForm.listBoxName.SelectedItem.ToString();
            string sql    = @"select * from Outlines where Outlines.型号='" + name + "'";
            double startx = GetValueFromExpression(m_connectToaccess.GetSingleInformation(sql, "StartX"));
            double starty = GetValueFromExpression(m_connectToaccess.GetSingleInformation(sql, "StartY"));
            double endx   = GetValueFromExpression(m_connectToaccess.GetSingleInformation(sql, "EndX"));
            double endy   = GetValueFromExpression(m_connectToaccess.GetSingleInformation(sql, "EndY"));

            basex = GetDistanceBtwPointandLine(m_Point, m_UCS.YAxis);
            basey = GetDistanceBtwPointandLine(m_Point, m_UCS.XAxis);
            double x1 = basex - startx;
            double y1 = basey - starty;
            double x2 = basex + endx;
            double y2 = basey + endy;

            m_Point1 = oTransGeo.CreatePoint2d(y1, x1);
            m_Point2 = oTransGeo.CreatePoint2d(y2, x2);

            InsertOutlineRequest m_insertOutlineRequest = new InsertOutlineRequest(m_inventorApplication, m_insertFace, m_selectiFeature, m_Point1, m_Point2);

            base.ExecuteChangeRequest(m_insertOutlineRequest, "AppInsertOutlineChgDef", m_inventorApplication.ActiveDocument);
        }
示例#2
0
        public void PortNet(iFeature oifeature)
        {
            AttributeSets atr = oifeature.AttributeSets;

            AttributeSet abs = atr["MyAttribSet"];

            Inventor.Attribute att            = abs["InternalName"];
            Inventor.Attribute footprint      = abs["Footprint"];
            string             footprintCheck = footprint.Value;

            Inventor.Attribute indexAttribute = abs["IndexName"];
            string             indexName      = indexAttribute.Value;

            Inventor.Attribute codeNameAttribute = abs["CodeName"];
            string             codeName          = codeNameAttribute.Value;

            Inventor.Attribute codeNumberAttribute = abs["CodeNumber"];
            string             codeNumber          = codeNumberAttribute.Value;

            m_connectToaccess = new ConnectToAccess(deFaultpath, "CavityLibrary", codeName, indexName, codeNumber);
            string sql        = @"select * from ComponentsDb where ComponentsDb.IndexName='" + indexName + "'";
            string CavityType = m_connectToaccess.GetSingleInformation(sql, "CavityType");

            if (footprintCheck == "No")
            {
                AttributeSet       myPorts       = atr["MyPorts"];
                Inventor.Attribute AttPortNumber = myPorts["MyPortsNumber"];
                int    PortNumber = AttPortNumber.Value;
                int    i          = 0;
                string num;
                while (i < PortNumber)
                {
                    num = (++i).ToString();
                    Inventor.Attribute Port    = myPorts["Port" + num];
                    string             PortNet = Port.Value;
                    i = m_editNetForm.dataportNET.Rows.Add();
                    m_editNetForm.dataportNET.Rows[i].Cells[1].Value = PortNet;
                    m_editNetForm.dataportNET.Rows[i].Cells[0].Value = ++i;
                }
            }
            else if (footprintCheck == "Yes" && CavityType == "二通插装孔")
            {
                AttributeSet       myPorts       = atr["MyPorts"];
                Inventor.Attribute AttPortNumber = myPorts["MyPortsNumber"];
                int    PortNumber = AttPortNumber.Value;
                int    i          = 0;
                string num;
                while (i < PortNumber)
                {
                    num = (++i).ToString();
                    Inventor.Attribute Port    = myPorts["Port" + num];
                    string             PortNet = Port.Value;
                    i = m_editNetForm.dataportNET.Rows.Add();
                    m_editNetForm.dataportNET.Rows[i].Cells[1].Value = PortNet;
                    m_editNetForm.dataportNET.Rows[i].Cells[0].Value = ++i;
                }
                Inventor.Attribute portCountAttribute = myPorts["PortsCount"];
                int portCount = portCountAttribute.Value;
                int j         = 1;
                while (j <= portCount)
                {
                    i = m_editNetForm.dataportNET.Rows.Add();
                    string             portName   = m_connectToaccess.SelectConnectToAccess("PortName" + j.ToString());
                    Inventor.Attribute PortsOther = myPorts[portName];
                    string             NetName    = PortsOther.Value;
                    m_editNetForm.dataportNET.Rows[i].Cells[1].Value = NetName;
                    m_editNetForm.dataportNET.Rows[i].Cells[0].Value = portName;
                    j++;
                }
            }
            else
            {
                AttributeSet       myPorts            = atr["MyPorts"];
                Inventor.Attribute portCountAttribute = myPorts["PortsCount"];
                int portCount = portCountAttribute.Value;
                int j         = 1;
                int i         = 0;
                while (j <= portCount)
                {
                    i = m_editNetForm.dataportNET.Rows.Add();
                    string             portName   = m_connectToaccess.SelectConnectToAccess("PortName" + j.ToString());
                    Inventor.Attribute PortsOther = myPorts[portName];
                    string             NetName    = PortsOther.Value;
                    m_editNetForm.dataportNET.Rows[i].Cells[1].Value = NetName;
                    m_editNetForm.dataportNET.Rows[i].Cells[0].Value = portName;
                    j++;
                }
            }
        }
示例#3
0
        public override void OnExecute(Document document, NameValueMap context, bool succeeded)
        {
            PartDocument oPartDoc;

            oPartDoc = (PartDocument)document;

            PartComponentDefinition oPartCompDef;

            oPartCompDef = oPartDoc.ComponentDefinition;

            int i = 0;

            while (i < 20)
            {
                if (m_deleteName[i] != null)
                {
                    m_selectiFeature = oPartCompDef.Features.iFeatures[m_deleteName[i]];
                    AttributeSets atr = m_selectiFeature.AttributeSets;

                    AttributeSet abs = atr["MyAttribSet"];

                    Inventor.Attribute att                 = abs["InternalName"];
                    Inventor.Attribute footprint           = abs["Footprint"];
                    string             footprintCheck      = footprint.Value;
                    Inventor.Attribute indexAttribute      = abs["IndexName"];
                    string             indexName           = indexAttribute.Value;
                    Inventor.Attribute codeNameAttribute   = abs["CodeName"];
                    string             codeName            = codeNameAttribute.Value;
                    Inventor.Attribute codeNumberAttribute = abs["CodeNumber"];
                    string             codeNumber          = codeNumberAttribute.Value;
                    m_connectToaccess = new ConnectToAccess(deFaultpath + "\\CavityLibrary", "CavityLibrary", codeName, indexName, codeNumber);
                    string sql = @"select * from ComponentsDb where ComponentsDb.IndexName='" + indexName + "'";
                    CavityType = m_connectToaccess.GetSingleInformation(sql, "CavityType");
                    string num;
                    if (footprintCheck == "Yes" && CavityType == "板式阀通油孔")
                    {
                        PlanarSketch oSketchFootprint = oPartCompDef.Sketches["Footprint" + m_selectiFeature.Name];
                        oSketchFootprint.Delete();
                        AttributeSet       port       = atr["MyPorts"];
                        Inventor.Attribute portNumber = port["PortsCount"];
                        int portcount = portNumber.Value;
                        int j         = 1;
                        while (j <= portcount)
                        {
                            string portName = m_connectToaccess.SelectConnectToAccess("PortName" + j.ToString());
                            oPartCompDef.Features.ExtrudeFeatures[m_selectiFeature.Name + "-" + portName].Delete();
                            j++;
                        }
                    }
                    else if (footprintCheck == "Yes" && CavityType == "二通插装孔")
                    {
                        AttributeSet       port       = atr["MyPorts"];
                        Inventor.Attribute portNumber = port["MyPortsNumber"];
                        int portnum = portNumber.Value;
                        int j       = 1;
                        while (j <= portnum)
                        {
                            num = (j).ToString();
                            oPartCompDef.Features.ExtrudeFeatures[m_selectiFeature.Name + "-" + num].Delete();
                            j++;
                        }
                        PlanarSketch oSketchFootprint = oPartCompDef.Sketches["Footprint" + m_selectiFeature.Name];
                        oSketchFootprint.Delete();
                        Inventor.Attribute portCountAttribute = port["PortsCount"];
                        int portCount = portCountAttribute.Value;
                        j = 1;
                        while (j <= portCount)
                        {
                            string portName = m_connectToaccess.SelectConnectToAccess("PortName" + j.ToString());
                            oPartCompDef.Features.ExtrudeFeatures[m_selectiFeature.Name + "-" + portName].Delete();
                            j++;
                        }
                    }
                    else if ((footprintCheck == "No" && CavityType == "螺纹孔") || (footprintCheck == "No" && CavityType == "工艺油孔"))
                    {
                        oPartCompDef.Features.ExtrudeFeatures[m_selectiFeature.Name + "-1"].Delete();
                    }
                    else
                    {
                        AttributeSet       port       = atr["MyPorts"];
                        Inventor.Attribute portNumber = port["MyPortsNumber"];
                        int portnum = portNumber.Value;
                        int j       = 1;
                        while (j <= portnum)
                        {
                            num = (j).ToString();
                            oPartCompDef.Features.ExtrudeFeatures[m_selectiFeature.Name + "-" + num].Delete();
                            j++;
                        }
                    }

                    m_selectiFeature.Delete();

                    if (m_outlineDelete)
                    {
                        PlanarSketch oSketchOutline = oPartCompDef.Sketches["Footprint" + m_selectiFeature.Name];
                        oSketchOutline.Delete();
                    }
                }
                i++;
            }
            MessageBox.Show("元件删除成功");
        }
        public void insertFootFeature(Face selectFace, string indexnumber)//用于插入具有安装面的元件
        {
            string       oInputName;
            PartDocument oPartDocument;

            oPartDocument = (PartDocument)m_inventorApplication.ActiveDocument;
            PartComponentDefinition oPartCompDef;

            oPartCompDef = oPartDocument.ComponentDefinition;
            Face oSelectFace;

            oSelectFace = selectFace;

            PartFeatures oFeatures;

            oFeatures = oPartCompDef.Features;
            iFeatureDefinition oiFeatureDef;

            oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition(filepath + "\\" + indexnumber + "Footprint.ide");
            ucsNumber    = JudgeFaceUcs(oSelectFace);
            Inventor.Vector oVector = oPartCompDef.UserCoordinateSystems[ucsNumber].XAxis.Line.Direction.AsVector();
            foreach (iFeatureInput oInput in oiFeatureDef.iFeatureInputs)
            {
                if (oInput.Name == "放置平面" || oInput.Name == "x轴" || oInput.Name == "y轴" || oInput.Name == "y" || oInput.Name == "x")
                {
                    switch (oInput.Name)
                    {
                    case "放置平面":
                        iFeatureSketchPlaneInput oPlaneInput;
                        oPlaneInput            = (iFeatureSketchPlaneInput)oInput;
                        oPlaneInput.PlaneInput = oSelectFace;
                        oPlaneInput.SetPosition(m_Point, oVector, rotateAngle);
                        break;

                    case "x轴":
                        iFeatureEntityInput oInputXAxis;
                        oInputXAxis        = (iFeatureEntityInput)oInput;
                        oInputXAxis.Entity = oPartCompDef.UserCoordinateSystems[ucsNumber].XAxis;
                        break;

                    case "y轴":
                        iFeatureEntityInput oInputYAxis;
                        oInputYAxis        = (iFeatureEntityInput)oInput;
                        oInputYAxis.Entity = oPartCompDef.UserCoordinateSystems[ucsNumber].YAxis;
                        break;

                    case "y":
                        iFeatureParameterInput oInputx;
                        oInputx       = (iFeatureParameterInput)oInput;
                        oInputx.Value = Yposition;
                        break;

                    case "x":
                        iFeatureParameterInput oInputy;
                        oInputy       = (iFeatureParameterInput)oInput;
                        oInputy.Value = Xposition;
                        break;
                    }
                }
                else
                {
                    oInputName = oInput.Name;
                    iFeatureParameterInput oParameXInput;
                    oParameXInput            = (iFeatureParameterInput)oInput;
                    oParameXInput.Expression = m_connectToaccess.SelectConnectToAccess(oInputName);
                }
            }
            iFeature oiFeature;

            oiFeature  = oFeatures.iFeatures.Add(oiFeatureDef);
            m_iFeature = oiFeature;


            double disminX = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("LminX")) / 2.0 + Xposition;
            double disminY = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("LminY")) / 2.0 + Yposition;
            double dismaxX = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("LmaxX")) / 2.0 + Xposition;
            double dismaxY = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("LmaxY")) / 2.0 + Yposition;


            DrawSketch(selectFace, Yposition, Xposition, disminY, disminX, dismaxY, dismaxX, m_iFeatureName);

            //------------------------------------------------------------------------------编写保存iFeature名称的属性集
            RotateSketch(oPartCompDef, m_iFeatureName, Yposition, Xposition, rotateAngle);
            WriteAttribute(oiFeature, m_Point, "Yes", rotateAngle);
            oiFeature.Name = m_iFeatureName;

            //------------------------------------------------------------------------------拉伸曲面以区分网络
            string sql        = @"select * from ComponentsDb where ComponentsDb.IndexName='" + indexname + "'";
            string cavityType = m_connectToaccess.GetSingleInformation(sql, "CavityType");

            if (cavityType == "二通插装孔")
            {
                ColorAllCavPort(oiFeature, oSelectFace);
            }

            ColorAllFootpPort(oiFeature, oSelectFace);
            ShowPortColor();
            oPartDocument.Update2();
        }
        private void AddInformation(string path)//用于加载二维原理图信息显示的函数
        {
            trViewcopnent.Nodes[0].Nodes.Clear();
            trViewcopnent.Nodes[1].Nodes.Clear();
            trViewNet.Nodes.Clear();
            trViewcopnent.LabelEdit = true;
            trViewNet.LabelEdit     = true;
            string    indexnameref      = null;
            string    checkFootprintref = null;
            string    cavityTyperef     = null;
            XDocument doc = XDocument.Load(path);
            IEnumerable <XElement> partNos = from cavity in doc.Descendants("Component")
                                             select cavity;

            foreach (var n in partNos)//读取元件清单
            {
                TreeNode node = new TreeNode((string)n.Element("元件标识"));
                trViewcopnent.Nodes[0].Nodes.Add(node);
                TreeNode node1 = new TreeNode((string)n.Element("型号编码"));
                node.Nodes.Add(node1);
                TreeNode node2 = new TreeNode((string)n.Element("元件名称"));
                node.Nodes.Add(node2);
                TreeNode node3 = new TreeNode("元件编号:" + (string)n.Element("元件编号"));
                node.Nodes.Add(node3);
                TreeNode node4 = new TreeNode("油孔名称");
                node.Nodes.Add(node4);
                IEnumerable <XElement> partname = n.Element("油口名").Elements("名称");
                foreach (var s in partname)
                {
                    TreeNode node5 = new TreeNode((string)s);
                    node4.Nodes.Add(node5);
                }
                //用于找出原理图中不存在的元件并进行显示
                if (CheckIndexName((string)n.Element("型号编码"), (string)n.Element("元件名称"), ref indexnameref, ref checkFootprintref, ref cavityTyperef) == null)
                {
                    checkNumber.Items.Add((string)n.Element("元件标识"));
                    btnchange.Enabled = true;
                }
                else
                {
                    btnchange.Enabled = false;
                }
            }
            int i = 0;

            while (i < trViewcopnent.Nodes[0].Nodes.Count)
            {
                string name      = trViewcopnent.Nodes[0].Nodes[i].Nodes[1].Text;
                string indexname = trViewcopnent.Nodes[0].Nodes[i].Nodes[0].Text;
                m_connectToaccess = new ConnectToAccess(@"F:\CavityLibrary", "CavityLibrary");
                string sql    = @"select Footprint from ComponentsDb where ComponentsDb.Name='" + name + @"'";
                string result = m_connectToaccess.GetSingleInformation(sql, "Footprint");
                if (result == "Yes")
                {
                    trViewcopnent.Nodes[0].Nodes[i].ImageIndex         = 1;
                    trViewcopnent.Nodes[0].Nodes[i].SelectedImageIndex = 3;
                }
                else
                {
                    trViewcopnent.Nodes[0].Nodes[i].ImageIndex         = 0;
                    trViewcopnent.Nodes[0].Nodes[i].SelectedImageIndex = 2;
                }
                i++;
            }
            trViewcopnent.Nodes[0].Expand();
            IEnumerable <XElement> partNos1 = from port in doc.Descendants("Port")
                                              select port;

            foreach (var l in partNos1)//读取油孔清单
            {
                TreeNode nodeportnumber = new TreeNode((string)l.Element("油孔标识"));
                trViewcopnent.Nodes[1].Nodes.Add(nodeportnumber);

                TreeNode nodeport = new TreeNode((string)l.Element("型号编码"));
                nodeportnumber.Nodes.Add(nodeport);
                TreeNode nodeportname = new TreeNode((string)l.Element("油孔类型"));
                nodeportnumber.Nodes.Add(nodeportname);
                trViewcopnent.Nodes[1].ImageIndex = 0;
                trViewcopnent.Nodes[1].Expand();
            }

            IEnumerable <XElement> partNos2 = from net in doc.Descendants("Net")
                                              select net;

            foreach (var m in partNos2)//读取网络连接清单
            {
                TreeNode nodenet = new TreeNode((string)m.Element("网络名"));
                trViewNet.Nodes.Add(nodenet);
                int    nodenetindex;
                string Name = (string)m.Element("网络名");
                switch (Name)
                {
                case "NET1":
                    nodenetindex = 0;
                    break;

                case "NET2":
                    nodenetindex = 1;
                    break;

                case "NET3":
                    nodenetindex = 2;
                    break;

                case "NET4":
                    nodenetindex = 3;
                    break;

                case "NET5":
                    nodenetindex = 4;
                    break;

                case "NET6":
                    nodenetindex = 5;
                    break;

                case "NET7":
                    nodenetindex = 6;
                    break;

                case "NET8":
                    nodenetindex = 7;
                    break;

                case "NET9":
                    nodenetindex = 8;
                    break;

                case "NET10":
                    nodenetindex = 9;
                    break;

                case "NET11":
                    nodenetindex = 10;
                    break;

                case "NET12":
                    nodenetindex = 11;
                    break;

                case "NET13":
                    nodenetindex = 12;
                    break;

                case "NET14":
                    nodenetindex = 13;
                    break;

                case "NULLNET":
                    nodenetindex = 14;
                    break;

                default:
                    nodenetindex = 14;
                    break;
                }
                nodenet.ImageIndex = nodenetindex;
                IEnumerable <XElement> partnos3 = m.Element("接口名").Elements("名称");
                foreach (var l in partnos3)
                {
                    TreeNode nodenet2 = new TreeNode((string)l);
                    nodenet.Nodes.Add(nodenet2);
                    nodenet2.ImageIndex = 15;
                }
            }
        }