Example #1
0
        public void RemoveExisting_works()
        {
            Inventor.Application app = ApplicationShim.Instance();
            var      path            = app.DesignProjectManager.ActiveDesignProject.TemplatesPath;
            Document doc             = app.Documents.Add(DocumentTypeEnum.kPartDocumentObject, path + "Standard.ipt", true);

            //create the test AttributeSet
            AttributeSet attributeSet = doc.AttributeSets.Add("testSet");

            Inventor.Attribute attribute = attributeSet.Add("testAttribute", ValueTypeEnum.kStringType, "test string");

            AttributeShim.RemoveAttribute(doc, "testSet", "testAttribute");

            bool result = false;

            foreach (Inventor.Attribute i in doc.AttributeSets["testSet"])
            {
                if (i.Name.Equals("testAttribute"))
                {
                    result = true;
                }
            }

            try
            {
                Assert.IsFalse(result);
            }
            finally { doc.Close(true); }
        }
        public void RemoveExisting_works()
        {
            var doc = tests.TestUtilities.CreatePartDocument();

            //create the test AttributeSet
            AttributeSet attributeSet = doc.AttributeSets.Add("testSet");

            Inventor.Attribute attribute = attributeSet.Add("testAttribute", ValueTypeEnum.kStringType, "test string");

            AttributeShim.RemoveAttribute(doc, "testSet", "testAttribute");

            bool result = false;

            foreach (Inventor.Attribute i in doc.AttributeSets["testSet"])
            {
                if (i.Name.Equals("testAttribute"))
                {
                    result = true;
                }
            }

            try
            {
                Assert.IsFalse(result);
            }
            finally { doc.Close(true); }
        }
Example #3
0
        private void ExcuteAlign(PartDocument partDoc, WorkPlane refPlane, string paraName, int coeff)
        {
            PartComponentDefinition oPartCompDef;

            oPartCompDef = partDoc.ComponentDefinition;

            WorkAxis thisFaceAxis;

            thisFaceAxis = oPartCompDef.WorkAxes.AddByRevolvedFace(m_thisFace, false);
            Double thisDist = GetDistanceBetwLineAndFace(oPartCompDef, thisFaceAxis, refPlane);

            thisFaceAxis.Delete();

            WorkAxis withThisFaceAxis;

            withThisFaceAxis = oPartCompDef.WorkAxes.AddByRevolvedFace(m_withThisFace, false);
            Double withThisDist = GetDistanceBetwLineAndFace(oPartCompDef, withThisFaceAxis, refPlane);

            withThisFaceAxis.Delete();

            Double differ;

            differ = thisDist - withThisDist;

            AttributeSets atr = m_thisiFeature.AttributeSets;

            AttributeSet abs = atr["MyAttribSet"];

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

            string thisiFeatureName = att.Value;
            string oParameterName   = thisiFeatureName + ":" + paraName;

            foreach (iFeatureInput oInput in m_thisiFeature.iFeatureDefinition.iFeatureInputs)
            {
                if (oInput.Name == thisiFeatureName + ":" + paraName || oInput.Name == thisiFeatureName + ":" + paraName + ":2")
                {
                    iFeatureParameterInput oParamInput;
                    oParamInput = (iFeatureParameterInput)oInput;
                    Double newValue = oParamInput.Parameter.Value + coeff * differ;
                    oParamInput.Parameter.Value = newValue;
                }
            }
            if (footprintCheck == "Yes")
            {
                if (paraName == "y")
                {
                    MoveSketch(0, coeff * differ);
                }
                else
                {
                    MoveSketch(coeff * differ, 0);
                }
            }
            partDoc.Update2();
        }
Example #4
0
        public override void OnExecute(Document document, NameValueMap context, bool succeeded)
        {
            PartDocument oPartDoc;

            oPartDoc = (PartDocument)document;

            PartComponentDefinition oPartCompDef;

            oPartCompDef = oPartDoc.ComponentDefinition;

            AttributeSets atr = m_selectiFeature.AttributeSets;

            AttributeSet abs = atr["MyAttribSet"];

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

            //string oXParamName = thisiFeatureName + ":x";
            //string oYParamName = thisiFeatureName + ":y";

            foreach (iFeatureInput oInput in m_selectiFeature.iFeatureDefinition.iFeatureInputs)
            {
                try
                {
                    if (oInput.Name == thisiFeatureName + ":x" || oInput.Name == thisiFeatureName + ":x:2")
                    {
                        iFeatureParameterInput oParamInput;
                        oParamInput = (iFeatureParameterInput)oInput;
                        Double newValue = oParamInput.Parameter.Value + m_xOffset;
                        oParamInput.Parameter.Value = newValue;
                    }

                    if (oInput.Name == thisiFeatureName + ":y" || oInput.Name == thisiFeatureName + ":y:2")
                    {
                        iFeatureParameterInput oParamInput;
                        oParamInput = (iFeatureParameterInput)oInput;
                        Double newValue = oParamInput.Parameter.Value + m_yOffset;
                        oParamInput.Parameter.Value = newValue;
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
            }
            if (footprintCheck == "Yes")
            {
                MoveSketch();
            }
            oPartDoc.Update2();
            //MessageBox.Show(m_selectiFeature.Name);
        }
Example #5
0
        public void InsertInformation()
        {
            PartDocument oPartDocument;

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

            oPartCompDef = oPartDocument.ComponentDefinition;

            AttributeSets atr = m_selectiFeature.AttributeSets;
            int           insertPlane;
            int           insertFace;

            this.GetInsertFace(oPartCompDef, m_selectFace, out insertPlane, out insertFace);
            m_insertFace = oPartCompDef.Features.ExtrudeFeatures["拉伸1"].Faces[insertFace];
            AttributeSet abs = atr["MyAttribSet"];

            Inventor.Attribute internalname = abs["InternalName"];
            Inventor.Attribute footprint    = abs["Footprint"];
            Inventor.Attribute pointX       = abs["PointX"];
            Inventor.Attribute pointY       = abs["PointY"];
            Inventor.Attribute pointZ       = abs["PointZ"];
            Inventor.Attribute indexname    = abs["IndexName"];
            m_indexname = indexname.Value;
            Inventor.Attribute codename = abs["CodeName"];
            m_codename = codename.Value;
            Inventor.Attribute codenumber = abs["CodeNumber"];
            m_codenumber = codenumber.Value;
            Inventor.Attribute angle = abs["Angle"];
            m_OldAngle    = angle.Value;
            m_InsertAngle = m_OldAngle + m_Angle;

            m_checkfootprint = footprint.Value;

            TransientGeometry oTransGeo;

            oTransGeo = m_inventorApplication.TransientGeometry;
            m_Point   = oTransGeo.CreatePoint(pointX.Value, pointY.Value, pointZ.Value);

            Xposition = pointX.Value;
            //GetDistanceBtwPointandLine(m_Point,oPartCompDef.UserCoordinateSystems[insertPlane].XAxis);
            Yposition = pointY.Value;
            //GetDistanceBtwPointandLine(m_Point,oPartCompDef.UserCoordinateSystems[insertPlane].YAxis);
            m_iFeatureName = m_selectiFeature.Name;
            assembly       = System.Reflection.Assembly.GetExecutingAssembly();
            FileInfo asmFile = new FileInfo(assembly.Location);

            deFaultpath = asmFile.DirectoryName;
            m_filepath  = deFaultpath + "\\CavityLibrary";
        }
Example #6
0
        private void createPart2()
        {
            // create a new part
            PartDocument            oDoc = (PartDocument)mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject);
            PartComponentDefinition oDef = oDoc.ComponentDefinition;

            TransientGeometry oTG = mApp.TransientGeometry;

            // create sketch elements
            PlanarSketch oSketch = oDef.Sketches.Add(oDef.WorkPlanes[3]);

            oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(-5, -5), oTG.CreatePoint2d(5, 5));

            SketchPoint oSketchPt = oSketch.SketchPoints.Add(oTG.CreatePoint2d(0, 0));

            Profile oProfile = oSketch.Profiles.AddForSolid();
            // create a plate with a hole feature
            ExtrudeDefinition oExtrudDef = oDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation);

            oExtrudDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);
            ExtrudeFeature oExtrudeF = oDef.Features.ExtrudeFeatures.Add(oExtrudDef);

            // Create an object collection for the hole center points.
            ObjectCollection oHoleCenters = default(ObjectCollection);

            oHoleCenters = mApp.TransientObjects.CreateObjectCollection();

            oHoleCenters.Add(oSketchPt);

            // create hole feature
            HolePlacementDefinition oHPdef = (HolePlacementDefinition)oDef.Features.HoleFeatures.CreateSketchPlacementDefinition(oHoleCenters);

            HoleFeature oHoleF = oDef.Features.HoleFeatures.AddDrilledByThroughAllExtent(oHPdef, "2", PartFeatureExtentDirectionEnum.kNegativeExtentDirection);

            Face         oFace   = oHoleF.SideFaces[1];
            AttributeSet oAttSet = default(AttributeSet);

            Inventor.Attribute oAtt = null;
            oAttSet = oFace.AttributeSets.Add("demoAttset");
            oAtt    = oAttSet.Add("demoAtt", ValueTypeEnum.kStringType, "namedEdge");
            if (System.IO.File.Exists("c:\temp\test2.ipt"))
            {
                System.IO.File.Delete("c:\temp\test2.ipt");
            }


            oDoc.SaveAs("c:\\temp\\test2.ipt", false);
        }
Example #7
0
        public void AddInformation()
        {
            PartDocument oPartDocument;

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

            oPartCompDef = oPartDocument.ComponentDefinition;

            AttributeSets atr = m_selectiFeature.AttributeSets;
            int           insertPlane;
            int           insertFace;

            this.GetInsertFace(oPartCompDef, m_selectFace, out insertPlane, out insertFace);
            m_insertFace = oPartCompDef.Features.ExtrudeFeatures["拉伸1"].Faces[insertFace];
            AttributeSet abs = atr["MyAttribSet"];

            Inventor.Attribute internalname = abs["InternalName"];
            Inventor.Attribute footprint    = abs["Footprint"];
            Inventor.Attribute pointX       = abs["PointX"];
            Inventor.Attribute pointY       = abs["PointY"];
            Inventor.Attribute pointZ       = abs["PointZ"];
            TransientGeometry  oTransGeo;

            oTransGeo = m_inventorApplication.TransientGeometry;
            m_Point   = oTransGeo.CreatePoint(pointX.Value, pointY.Value, pointZ.Value);
            Inventor.Attribute indexname = abs["IndexName"];
            m_indexname = indexname.Value;
            Inventor.Attribute codename = abs["CodeName"];
            m_codename = codename.Value;
            Inventor.Attribute codenumber = abs["CodeNumber"];
            m_codenumber      = codenumber.Value;
            m_connectToaccess = new ConnectToAccess(m_filepath, m_filename, m_codename, m_indexname, m_codenumber);
            string sql = @"select 生产厂家 from Outlines where Outlines.标准='" + m_indexname + "'";

            string [] result = new string[25];
            m_connectToaccess.GetInformation(sql, "生产厂家", out result);
            int i = 0;

            while (result[i] != null)
            {
                m_insertOutlineForm.listBoxName.Items.Add(result[i]);
                i++;
            }
        }
        public void GetExisting_works()
        {
            var doc = tests.TestUtilities.CreatePartDocument();

            //create the test Attribute
            var          test         = "test string";
            AttributeSet attributeSet = doc.AttributeSets.Add("testSet");

            Inventor.Attribute attribute = attributeSet.Add("testAttribute", ValueTypeEnum.kStringType, test);

            var result = AttributeShim.GetAttributeValue(doc, "testSet", "testAttribute");

            try
            {
                Assert.AreEqual(result, test);
            }
            finally { doc.Close(true); }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Use: Read attribute and returns its value in out parameter.
        //      Returns true if attribute exists, false otherwise
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static bool ReadAttribute(object target,
                                         string setName,
                                         string attName,
                                         out object value,
                                         out ValueTypeEnum type)
        {
            value = null;
            type  = ValueTypeEnum.kIntegerType;

            try
            {
                AttributeSets sets = AdnInventorUtilities.GetProperty(target, "AttributeSets") as AttributeSets;

                if (sets == null)
                {
                    return(false);
                }

                if (!sets.get_NameIsUsed(setName))
                {
                    return(false);
                }

                AttributeSet set = sets[setName];

                if (!set.get_NameIsUsed(attName))
                {
                    return(false);
                }

                Inventor.Attribute att = set[attName];

                type = att.ValueType;

                value = att.Value;

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #10
0
        public void GetExisting_works()
        {
            Inventor.Application app = ApplicationShim.Instance();
            var      path            = app.DesignProjectManager.ActiveDesignProject.TemplatesPath;
            Document doc             = app.Documents.Add(DocumentTypeEnum.kPartDocumentObject, path + "Standard.ipt", true);


            //create the test Attribute
            var          test         = "test string";
            AttributeSet attributeSet = doc.AttributeSets.Add("testSet");

            Inventor.Attribute attribute = attributeSet.Add("testAttribute", ValueTypeEnum.kStringType, test);


            var result = AttributeShim.GetAttributeValue(doc, "testSet", "testAttribute");


            try
            {
                Assert.AreEqual(result, test);
            }
            finally { doc.Close(true); }
        }
Example #11
0
        void createPart1()
        {
            // create a new part

            PartDocument            oDoc = (PartDocument)mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject);
            PartComponentDefinition oDef = oDoc.ComponentDefinition;

            TransientGeometry oTG = mApp.TransientGeometry;

            // create sketch elements
            PlanarSketch oSketch = oDef.Sketches.Add(oDef.WorkPlanes[3]);
            SketchCircle oCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, 0), 1);

            Profile oProfile = oSketch.Profiles.AddForSolid();

            // create a cylinder feature
            ExtrudeDefinition oExtrudDef = oDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation);

            oExtrudDef.SetDistanceExtent(5, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);
            ExtrudeFeature oExtrudeF = oDef.Features.ExtrudeFeatures.Add(oExtrudDef);

            //add an attribute to cylinder face
            Face oFace = oExtrudeF.SideFaces[1];

            AttributeSet oAttSet = default(AttributeSet);

            Inventor.Attribute oAtt = null;
            oAttSet = oFace.AttributeSets.Add("demoAttset");
            oAtt    = oAttSet.Add("demoAtt", ValueTypeEnum.kStringType, "namedEdge");
            if (System.IO.File.Exists("c:\temp\test1.ipt"))
            {
                System.IO.File.Delete("c:\temp\test1.ipt");
            }

            oDoc.SaveAs("c:\\temp\\test1.ipt", false);
        }
Example #12
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++;
                }
            }
        }
Example #13
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 override void OnExecute(Document document, NameValueMap context, bool succeeded)
        {
            PartDocument oPartDoc   = (PartDocument)m_inventorApplication.ActiveDocument;
            SelectSet    oSelectSet = oPartDoc.SelectSet;

            PartComponentDefinition oPartCompDef;

            oPartCompDef = oPartDoc.ComponentDefinition;
            try
            {
                int    Portname = int.Parse(m_selectportName);
                string portEditName;
                portEditName = m_selectiFeature.Name + "-" + m_selectportName;
                ExtrudeFeature portFaceExtru;
                portFaceExtru = oPartCompDef.Features.ExtrudeFeatures[portEditName];
                Asset asset = null;
                foreach (Asset asset1 in oPartDoc.Assets)
                {
                    if (asset1.DisplayName == m_netName)
                    {
                        asset = asset1;
                    }
                }
                portFaceExtru.Appearance = asset;
                string coneEditName;
                if (m_selectportName == "1")
                {
                    coneEditName = m_selectiFeature.Name + "-" + m_selectportName + "cone";
                    ExtrudeFeature coneFaceExtru;
                    coneFaceExtru            = oPartCompDef.Features.ExtrudeFeatures[coneEditName];
                    coneFaceExtru.Appearance = asset;
                }
                AttributeSets      Ports   = m_selectiFeature.AttributeSets;
                AttributeSet       myPorts = Ports["MyPorts"];
                Inventor.Attribute Port    = myPorts["Port" + m_selectportName];
                Port.Value = m_netName;
            }
            catch
            {
                string portEditName;
                portEditName = m_selectiFeature.Name + "-" + m_selectportName;
                ExtrudeFeature portFaceExtru;
                portFaceExtru = oPartCompDef.Features.ExtrudeFeatures[portEditName];
                Asset asset = null;
                foreach (Asset asset1 in oPartDoc.Assets)
                {
                    if (asset1.DisplayName == m_netName)
                    {
                        asset = asset1;
                    }
                }
                portFaceExtru.Appearance = asset;
                string coneEditName;
                coneEditName = m_selectiFeature.Name + "-" + m_selectportName + "cone";
                ExtrudeFeature coneFaceExtru;
                coneFaceExtru            = oPartCompDef.Features.ExtrudeFeatures[coneEditName];
                coneFaceExtru.Appearance = asset;

                AttributeSets      Ports   = m_selectiFeature.AttributeSets;
                AttributeSet       myPorts = Ports["MyPorts"];
                Inventor.Attribute Port    = myPorts[m_selectportName];
                Port.Value = m_netName;
            }
        }
Example #15
0
        public void AddOrRemoveFromGroup(bool add)
        {
            if (_invApp.Documents.Count == 0)
            {
                MessageBox.Show("Need to open an Assembly document");
                return;
            }

            if (_invApp.ActiveDocument.DocumentType != DocumentTypeEnum.kAssemblyDocumentObject)
            {
                MessageBox.Show("Need to have an Assembly document active");
                return;
            }

            AssemblyDocument asmDoc = default(AssemblyDocument);

            asmDoc = (AssemblyDocument)_invApp.ActiveDocument;

            if (asmDoc.SelectSet.Count == 0)
            {
                MessageBox.Show("Need to select a Part or Sub Assembly");
                return;
            }

            SelectSet selSet = default(SelectSet);

            selSet = asmDoc.SelectSet;
            Inventor.Assets colour = asmDoc.Assets;
            try
            {
                ComponentOccurrence compOcc = default(ComponentOccurrence);
                object obj = null;
                foreach (object obj_loopVariable in selSet)
                {
                    obj     = obj_loopVariable;
                    compOcc = (ComponentOccurrence)obj;
                    System.Diagnostics.Debug.Print(compOcc.Name);

                    AttributeSets attbSets = compOcc.AttributeSets;

                    if (add)
                    {
                        // Add the attributes to the ComponentOccurrence

                        if (!attbSets.NameIsUsed["myPartGroup"])
                        {
                            AttributeSet attbSet = attbSets.Add("myPartGroup");

                            Inventor.Attribute attb  = attbSet.Add("PartGroup1", ValueTypeEnum.kStringType, "Group1");
                            Inventor.Asset     asset = asmDoc.Assets["Red"];
                            compOcc.Appearance = asset;
                        }
                    }
                    else
                    {
                        // Delete the attributes to the ComponentOccurrence
                        if (attbSets.NameIsUsed["myPartGroup"])
                        {
                            attbSets["myPartGroup"].Delete();
                        }
                    }

                    //compOcc.Visible = False
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Is the selected item a Component?");
                MessageBox.Show(ex.ToString());
                return;
            }
        }