コード例 #1
0
ファイル: Program.cs プロジェクト: JRobotson/InventorShims
        private static void test_GetDocumentsFromSelectSet()
        {
            Inventor.Application oApp  = ApplicationShim.CurrentInstance();
            SelectSet            oSSet = oApp.ActiveDocument.SelectSet;

            if (oSSet.Count == 0)
            {
                oSSet.Select(oApp.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select thing(s)..."));
            }


            if (oSSet.Count == 0)
            {
                return;
            }

            List <Document> documentList = new List <Document>();

            documentList = DocumentShim.GetDocumentsFromSelectSet(oSSet);

            Console.WriteLine("Number of documents in List: " + documentList.Count().ToString());
            foreach (Document i in documentList)
            {
                //    Console.WriteLine(i.FullFileName);
            }

            Console.WriteLine("Press Enter to Exit!");
            Console.ReadLine();
        }
コード例 #2
0
 public Elements(Document doc)
 {
     app = Macros.StandardAddInServer.m_inventorApplication;
     if (doc.DocumentType == DocumentTypeEnum.kPartDocumentObject)
     {
         Entity.doc = doc as PartDocument;
         ss         = Entity.doc.SelectSet;
         if (ss.Count != 1)
         {
             return;
         }
         //cen = ss[1] as SketchPoint;
         //colect = app.TransientObjects.CreateObjectCollection();
         //add(u.pathUtil(doc) + "\\AC700-53A.00.006 (Люк автомата).ipt");
         //to = cen.Parent as PlanarSketch;
         ps = ss[1] as PlanarSketch;
         if (ps.SketchEntities.Count < 3)
         {
             readXML(@"c:\WORK\Завесы\Модули\asm.xml");
         }
         else
         {
             createXML();
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Returns a list of Documents from a provided SelectSet.  If no Documents are found, an
        /// empty list is returned.  Only unique documents objects are returned.
        /// </summary>
        /// <param name="selectSet">Inventor.SelectSet</param>
        /// <returns>List(of Documents)</returns>
        public static List <Document> GetDocumentsFromSelectSet(this SelectSet selectSet)
        {
            List <Document> documentList = new List <Document>();

            if (selectSet.Count == 0)
            {
                //nothing is selected, return an null list!
                return(documentList);
            }

            Document tempDocument = null;

            foreach (dynamic i in selectSet)
            {
                tempDocument = GetDocumentFromObject(i);
                Console.WriteLine("item  " + i.type);

                if (tempDocument is null)
                {
                    Console.WriteLine("this object is not a document");
                    continue;
                }
                Console.WriteLine("this object is a document.");
                documentList.Add(tempDocument);
            }

            if (documentList != null)
            {
                documentList = documentList.Distinct().ToList();
            }

            return(documentList);
        }
コード例 #4
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        protected void SelectInventorFeatures()
        {
            SelectSet ss = AdnInventorUtilities.InvApplication.ActiveDocument.SelectSet;

            ss.Clear();

            foreach (TreeNode node in TreeView.SelectedNodes)
            {
                if (node.Tag is PartFeature)
                {
                    ss.Select(node.Tag);
                }
            }
        }
コード例 #5
0
        protected override void ButtonDefinition_OnExecute(NameValueMap context)
        {
            Document doc = Macros.StandardAddInServer.m_inventorApplication.ActiveDocument;

            if (doc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
            {
                this.doc = doc as AssemblyDocument;
                ss       = this.doc.SelectSet;
                if (ss.Count == 0)
                {
                    return;
                }
                getForm();
            }
        }
コード例 #6
0
        private void ShowPortColor()
        {
            PartDocument oPartDoc   = (PartDocument)m_inventorApplication.ActiveDocument;
            SelectSet    oSelectSet = oPartDoc.SelectSet;

            PartComponentDefinition oPartCompDef;

            oPartCompDef = oPartDoc.ComponentDefinition;

            WorkSurfaces workSurfaces;

            workSurfaces = oPartCompDef.WorkSurfaces;

            foreach (WorkSurface workSurf in workSurfaces)
            {
                workSurf.Translucent = false;
            }
        }
コード例 #7
0
        //IsIPartFactory IsIPartMember


        #region IEnumerable<Document> providors

        /// <summary>
        /// Returns an IEnumerable collection of Inventor.Document from a SelectSet object.
        /// </summary>
        /// <param name="selectSet">Inventor.SelectionSet</param>
        /// <returns>IEnumerable Document</returns>
        /// <exception cref="System.ArgumentNullException">Throws an error if the selection set is empty.</exception>
        public static IEnumerable <Document> EnumerateDocuments(this SelectSet selectSet)
        {
            if (selectSet.Count == 0)
            {
                throw new System.ArgumentNullException("The selection set was empty.");
            }

            foreach (dynamic i in selectSet)
            {
                Document tempDocument = DocumentShim.GetDocumentFromObject(i);

                if (tempDocument is null)
                {
                    continue;
                }

                yield return(tempDocument);
            }
        }
コード例 #8
0
        private void CreateReferenceKeyButton_Click(object sender, EventArgs e)
        {
            SelectSet ss = m_app.ActiveDocument.SelectSet;

            if (ss.Count != 1)
            {
                MessageBox.Show("Please select a single object before using this command", "No single object selected");
                return;
            }

            try
            {
                string context, key;
                GetContextAndKey(ReferenceKeysTreeView.SelectedNode, out context, out key);
                int i = GetContextIndex(context);

                byte[] bytes = new byte[] { };
                ss[1].GetReferenceKey(ref bytes, i);

                Inventor.ReferenceKeyManager rkm = m_app.ActiveDocument.ReferenceKeyManager;
                key = rkm.KeyToString(bytes);

                if (ReferenceKeysTreeView.SelectedNode.Nodes.ContainsKey(key))
                {
                    TreeNode existingNode = ReferenceKeysTreeView.SelectedNode.Nodes.Find(context, false)[0];
                    ReferenceKeysTreeView.SelectedNode = existingNode;

                    MessageBox.Show("Such key already exists and is now highlighted in the Browser", "Duplicate key");

                    return;
                }

                TreeNode node = ReferenceKeysTreeView.SelectedNode.Nodes.Add(key, key);
                node.ImageKey         = kReference;
                node.SelectedImageKey = kReference;
                node.EnsureVisible();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Could not create key");
            }
        }
コード例 #9
0
        public int getSelectSetCount(SelectSet set)
        {
            int count = 0;
            //记录符合选择项的ids
            ObjectIDs oids = new ObjectIDs();
            ObjectID  oid  = new ObjectID();

            if (set != null)
            {
                //获取选择集列表
                List <SelectSetItem> lst = set.Get();

                foreach (SelectSetItem item in lst)
                {
                    count += item.IDList.Count;
                }
                if (lst == null || lst.Count == 0)
                {
                    return(count);
                }

                //获取图层信息
                MapLayer maplayer = lst[0].Layer;
                //获取图层对应的要素类的信息
                basClass = maplayer.GetData();

                //获取处于编辑状态第一个图层的要素ID列表
                List <long> idarr = lst[0].IDList;

                for (int i = 0; i < idarr.Count; i++)
                {
                    oid.Int64Val = idarr[i];
                    oids.Append(oid);
                }
                rcdSet = new RecordSet(basClass);
                //添加结果集
                rcdSet.AddSet(oids);
            }
            attCtrl.SetXCls((IVectorCls)basClass, rcdSet);
            return(count);
        }
コード例 #10
0
        /// <summary>
        /// Returns a list of Documents from a provided SelectSet.  If no Documents are found, an
        /// empty list is returned.  Only unique documents objects are returned.
        /// </summary>
        /// <param name="selectSet">Inventor.SelectSet</param>
        /// <returns>List(of Documents)</returns>
        public static List <Document> GetDocumentsFromSelectSet(this SelectSet selectSet)
        {
            Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
            Debug.AutoFlush = true;
            Debug.Indent();
            Debug.WriteLine("Entering GetDocumentsFromSelectSet method...");

            List <Document> documentList = new List <Document>();

            if (selectSet.Count == 0)
            {
                //nothing is selected, return an null list!
                return(documentList);
            }

            Document tempDocument = null;

            foreach (dynamic i in selectSet)
            {
                tempDocument = GetDocumentFromObject(i);

                Debug.WriteLine("item  " + (string)i.type.ToString());

                if (tempDocument is null)
                {
                    Debug.WriteLine("this object is not a document");
                    continue;
                }

                Debug.WriteLine("this object is a document.");
                documentList.Add(tempDocument);
            }

            if (documentList != null)
            {
                documentList = documentList.Distinct().ToList();
            }

            return(documentList);
        }
コード例 #11
0
        private void 闪烁ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.mapCtrl.EndFlash();
            IVectorCls VectorCls = new SFeatureCls();

            if (!VectorCls.Open("file:///c:\\users\\tangchao\\desktop\\ppp.wp"))
            {
                int i = 0;
            }
//             DataConvert dc = new DataConvert();
//             if (dc.OpenSource(VectorCls) > 0 && dc.OpenDestination("c:\\users\\tangchao\\desktop\\ppptrr.wp") > 0)
//             {
//                 dc.Convert();
//             }
            QueryDef def1 = new QueryDef();

            def1.Filter = "NAME='黑龙江省            'or ID > 3";
            SelectOption option = null;

            option = new SelectOption();
            //类型是点、线、区、注记的图层均属于查询范围
            option.DataType = SelectDataType.AnyVector;
            //当前地图中所有图层
            option.LayerCtrl = SelectLayerControl.Visible;
            //多选
            option.SelMode = SelectMode.Multiply;
            //结果数据累加
            option.UnMode = UnionMode.Add;
            //查询
            SelectSet set = this.mapCtrl.ActiveMap.Select(def1, true, null, option);

            this.mapCtrl.FlashSelectSet();
            return;

            RecordSet rst1 = VectorCls.Select(def1);

            Map      acMap    = this.mapCtrl.ActiveMap;
            MapLayer mapLayer = null;

            if (acMap.LayerCount > 0)
            {
                mapLayer = acMap.get_Layer(0);
            }
            SFeatureCls Sfcls    = mapLayer.GetData() as SFeatureCls;
            FileLayer6x file6x   = mapLayer as FileLayer6x;
            VectorLayer veclayer = file6x.get_Item(0) as VectorLayer;

            Sfcls = veclayer.GetData() as SFeatureCls;

            QueryDef def = new QueryDef();

            def.Filter = "ID>6";
            RecordSet rst = Sfcls.Select(def);

            if (rst == null || rst.Count == 0)
            {
                MessageBox.Show("未查询到数据");
                return;
            }
            this.attCtrl.SetXCls(Sfcls, rst);
            SelectSet sleset = this.mapCtrl.ActiveMap.GetSelectSet();

            sleset.Append(mapLayer, rst);
            this.mapCtrl.FlashSelectSet();
        }
コード例 #12
0
        //用于给具有安装面的元件端口着色
        private void ColorFootprintPort(iFeature ifeature, Face face, int portCount, string netName, string portName)
        {
            PartDocument oPartDoc   = (PartDocument)m_inventorApplication.ActiveDocument;
            SelectSet    oSelectSet = oPartDoc.SelectSet;

            PartComponentDefinition oPartCompDef;

            oPartCompDef = oPartDoc.ComponentDefinition;

            double portDepth = System.Math.Round(GetValueFromExpression(m_connectToaccess.SelectConnectToAccess(portName + "depth")), 2);

            foreach (Face oFace in ifeature.Faces)
            {
                if (oFace.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
                {
                    Edges oEdges;
                    oEdges = oFace.Edges;

                    if (oEdges.Count == 2 && oEdges[1].GeometryType == CurveTypeEnum.kCircleCurve && oEdges[2].GeometryType == CurveTypeEnum.kCircleCurve)
                    {
                        double dis1 = System.Math.Round(GetDistanceBetwEdgeAndFace(oPartCompDef, oEdges[1], face), 2);
                        double dis2 = System.Math.Round(GetDistanceBetwEdgeAndFace(oPartCompDef, oEdges[2], face), 2);

                        if ((dis1 == 0 && dis2 == portDepth) || (dis2 == 0 && dis1 == portDepth))
                        {
                            Edge startEdge;
                            if (dis1 < dis2)
                            {
                                startEdge = oEdges[1];
                            }
                            else
                            {
                                startEdge = oEdges[2];
                            }

                            if (startEdge != null)
                            {
                                WorkPlane startPlane;
                                startPlane = oPartCompDef.WorkPlanes.AddByPlaneAndOffset(face, 0, true);

                                PlanarSketch oPortFaceSketch;
                                oPortFaceSketch = oPartCompDef.Sketches.Add(startPlane);

                                oPortFaceSketch.AddByProjectingEntity(startEdge);

                                Profile profile;
                                profile = oPortFaceSketch.Profiles.AddForSurface();

                                ExtrudeDefinition portFaceExtruDef;
                                portFaceExtruDef = oPartCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kSurfaceOperation);
                                portFaceExtruDef.SetDistanceExtent(portDepth, PartFeatureExtentDirectionEnum.kNegativeExtentDirection);

                                ExtrudeFeature portFaceExtru;
                                portFaceExtru      = oPartCompDef.Features.ExtrudeFeatures.Add(portFaceExtruDef);
                                portFaceExtru.Name = ifeature.Name + "-" + portName;

                                //创建底部圆锥面
                                WorkPoint coneBasePoint;
                                coneBasePoint = oPartCompDef.WorkPoints.AddAtCentroid(portFaceExtru.Faces[1].Edges[1], true);

                                WorkPlane coneStartPlane;
                                coneStartPlane = oPartCompDef.WorkPlanes.AddByPlaneAndPoint(face, coneBasePoint, true);

                                PlanarSketch oConeSketch;
                                oConeSketch = oPartCompDef.Sketches.Add(coneStartPlane);

                                oConeSketch.AddByProjectingEntity(startEdge);

                                Profile coneProfile;
                                coneProfile = oConeSketch.Profiles.AddForSurface();

                                Double dAngle = double.Parse(m_connectToaccess.SelectConnectToAccess("Angle"));
                                Double rAngle = ConvertUnit(dAngle, "degree", "radian");

                                ExtrudeDefinition coneFaceExtruDef;
                                coneFaceExtruDef = oPartCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(coneProfile, PartFeatureOperationEnum.kSurfaceOperation);
                                coneFaceExtruDef.SetThroughAllExtent(PartFeatureExtentDirectionEnum.kNegativeExtentDirection);
                                coneFaceExtruDef.TaperAngle = rAngle;

                                ExtrudeFeature coneFaceExtru;
                                coneFaceExtru      = oPartCompDef.Features.ExtrudeFeatures.Add(coneFaceExtruDef);
                                coneFaceExtru.Name = ifeature.Name + "-" + portName + "cone";

                                Asset asset = null;
                                foreach (Asset asset1 in oPartDoc.Assets)
                                {
                                    if (asset1.DisplayName == netName)
                                    {
                                        asset = asset1;
                                        break;
                                    }
                                }
                                portFaceExtru.Appearance = asset;
                                coneFaceExtru.Appearance = asset;
                                WritePortFaceAttribute(portFaceExtru, ifeature, 1, 1);
                                WritePortFaceAttribute(portFaceExtru, ifeature, portCount, portName);
                            }
                        }
                    }
                }
            }
            ConnectToAccess connectToAccessNET = new ConnectToAccess(@"F:\CavityLibrary", "项目数据库");
            string          sql = "insert into NETList(PortName," + netName + ") values('" + ifeature.Name + "-" + portName + "','" + ifeature.Name + "-" + portName + "')";

            if (connectToAccessNET.InsertInformation(sql))
            {
            }
            else
            {
                MessageBox.Show("保存网络出错!");
            }
        }
コード例 #13
0
        //没有安装面的阀或油孔的其他port着色函数
        private void ColorCavPort(iFeature ifeature, Face face, Double portDia, Double portCenterDepth, string netName, int portNumber, int portIndex)
        {
            PartDocument oPartDoc   = (PartDocument)m_inventorApplication.ActiveDocument;
            SelectSet    oSelectSet = oPartDoc.SelectSet;

            PartComponentDefinition oPartCompDef;

            oPartCompDef = oPartDoc.ComponentDefinition;

            WorkPlane portCenterPlane;

            portCenterPlane = oPartCompDef.WorkPlanes.AddByPlaneAndOffset(face, -portCenterDepth, true);

            Faces insertiFeatureFaces;

            insertiFeatureFaces = ifeature.Faces;

            string portName = (portIndex + 1).ToString();

            foreach (Face oFace in insertiFeatureFaces)
            {
                if (oFace.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
                {
                    Edges oEdges;
                    oEdges = oFace.Edges;

                    if (oEdges.Count == 2 && oEdges[1].GeometryType == CurveTypeEnum.kCircleCurve && oEdges[2].GeometryType == CurveTypeEnum.kCircleCurve)
                    {
                        double dis1 = GetDistanceBetwEdgeAndFace(oPartCompDef, oEdges[1], face);
                        double dis2 = GetDistanceBetwEdgeAndFace(oPartCompDef, oEdges[2], face);

                        if ((dis1 >= portCenterDepth && dis2 <= portCenterDepth) || (dis2 >= portCenterDepth && dis1 <= portCenterDepth))
                        {
                            PlanarSketch oPortFaceSketch;
                            oPortFaceSketch = oPartCompDef.Sketches.Add(portCenterPlane);

                            oPortFaceSketch.AddByProjectingEntity(oEdges[1]);

                            Profile profile;
                            profile = oPortFaceSketch.Profiles.AddForSurface();

                            ExtrudeDefinition portFaceExtruDef;
                            portFaceExtruDef = oPartCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kSurfaceOperation);
                            portFaceExtruDef.SetDistanceExtent(portDia, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection);

                            ExtrudeFeature portFaceExtru;
                            portFaceExtru      = oPartCompDef.Features.ExtrudeFeatures.Add(portFaceExtruDef);
                            portFaceExtru.Name = ifeature.Name + "-" + portName;

                            Asset asset = null;
                            foreach (Asset asset1 in oPartDoc.Assets)
                            {
                                if (asset1.DisplayName == netName)
                                {
                                    asset = asset1;
                                }
                            }
                            portFaceExtru.Appearance = asset;

                            WritePortFaceAttribute(portFaceExtru, ifeature, portNumber, portIndex + 1);
                            break;
                        }
                    }
                }
            }
            ConnectToAccess connectToAccessNET = new ConnectToAccess(@"F:\CavityLibrary", "项目数据库");
            string          sql = "insert into NETList(PortName," + netName + ") values('" + ifeature.Name + "-" + portName + "','" + ifeature.Name + "-" + portName + "')";

            if (connectToAccessNET.InsertInformation(sql))
            {
            }
            else
            {
                MessageBox.Show("保存网络出错!");
            }
        }
コード例 #14
0
        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;
            }
        }
コード例 #15
0
ファイル: Form1.cs プロジェクト: waztdotnet/Api2
        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;
            }
        }
コード例 #16
0
        private void Drowport(iFeature ifeature, Face face, double portDepth1, double depth0, string netName)
        {
            PartDocument oPartDoc   = (PartDocument)m_inventorApplication.ActiveDocument;
            SelectSet    oSelectSet = oPartDoc.SelectSet;

            PartComponentDefinition oPartCompDef;

            oPartCompDef = oPartDoc.ComponentDefinition;

            double    portStartDepth = portDepth1;
            WorkPlane portStartPlane;

            portStartPlane = oPartCompDef.WorkPlanes.AddByPlaneAndOffset(face, -portStartDepth, true);

            Faces insertiFeatureFaces;

            insertiFeatureFaces = ifeature.Faces;

            foreach (Face oFace in insertiFeatureFaces)
            {
                if (oFace.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
                {
                    Edges oEdges;
                    oEdges = oFace.Edges;

                    if (oEdges.Count == 2 && oEdges[1].GeometryType == CurveTypeEnum.kCircleCurve && oEdges[2].GeometryType == CurveTypeEnum.kCircleCurve)
                    {
                        double dis1 = GetDistanceBetwEdgeAndFace(oPartCompDef, oEdges[1], face);
                        double dis2 = GetDistanceBetwEdgeAndFace(oPartCompDef, oEdges[2], face);

                        if (dis1 >= portStartDepth || dis2 >= portStartDepth)
                        {
                            Edge startEdge;
                            if (dis1 >= dis2)
                            {
                                startEdge = oEdges[2];
                            }
                            else
                            {
                                startEdge = oEdges[1];
                            }

                            if (startEdge != null)
                            {
                                PlanarSketch oPortFaceSketch;
                                oPortFaceSketch = oPartCompDef.Sketches.Add(portStartPlane);

                                oPortFaceSketch.AddByProjectingEntity(startEdge);

                                Profile profile;
                                profile = oPortFaceSketch.Profiles.AddForSurface();

                                ExtrudeDefinition portFaceExtruDef;
                                portFaceExtruDef = oPartCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kSurfaceOperation);

                                //获取最后一阶孔的深度
                                double lastDepth = GetValueFromExpression(m_connectToaccess.SelectConnectToAccess("Depth8"));
                                portFaceExtruDef.SetDistanceExtent(lastDepth - portDepth1, PartFeatureExtentDirectionEnum.kNegativeExtentDirection);

                                ExtrudeFeature portFaceExtru;
                                portFaceExtru      = oPartCompDef.Features.ExtrudeFeatures.Add(portFaceExtruDef);
                                portFaceExtru.Name = ifeature.Name + "-1";

                                //创建底部圆锥面
                                WorkPoint coneBasePoint;
                                coneBasePoint = oPartCompDef.WorkPoints.AddAtCentroid(portFaceExtru.Faces[1].Edges[1], true);

                                WorkPlane coneStartPlane;
                                coneStartPlane = oPartCompDef.WorkPlanes.AddByPlaneAndPoint(face, coneBasePoint, true);

                                PlanarSketch oConeSketch;
                                oConeSketch = oPartCompDef.Sketches.Add(coneStartPlane);

                                oConeSketch.AddByProjectingEntity(startEdge);

                                Profile coneProfile;
                                coneProfile = oConeSketch.Profiles.AddForSurface();

                                Double dAngle8 = double.Parse(m_connectToaccess.SelectConnectToAccess("Angle8"));
                                Double rAngle8 = ConvertUnit(dAngle8, "degree", "radian");

                                ExtrudeDefinition coneFaceExtruDef;
                                coneFaceExtruDef = oPartCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(coneProfile, PartFeatureOperationEnum.kSurfaceOperation);
                                coneFaceExtruDef.SetThroughAllExtent(PartFeatureExtentDirectionEnum.kNegativeExtentDirection);
                                coneFaceExtruDef.TaperAngle = rAngle8;

                                ExtrudeFeature coneFaceExtru;
                                coneFaceExtru      = oPartCompDef.Features.ExtrudeFeatures.Add(coneFaceExtruDef);
                                coneFaceExtru.Name = ifeature.Name + "-1cone";

                                Asset asset = null;
                                foreach (Asset asset1 in oPartDoc.Assets)
                                {
                                    if (asset1.DisplayName == netName)
                                    {
                                        asset = asset1;
                                    }
                                }
                                portFaceExtru.Appearance = asset;
                                coneFaceExtru.Appearance = asset;
                                WritePortFaceAttribute(portFaceExtru, ifeature, 1, 1);
                                WritePortFaceAttribute(coneFaceExtru, ifeature, 1, 1);
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #17
0
 public abstract Expression CreateTypedExpressionSelectSetConditional(SelectSet selectSet, Expression subExpression);
コード例 #18
0
        public void DrawGroups(bool add)
        {
            if (mApp.Documents.Count == 0)
            {
                MessageBox.Show("Need to open an Assembly document");
                return;
            }

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

            AssemblyDocument assmbleyActiveDoc = default(AssemblyDocument);

            assmbleyActiveDoc = (AssemblyDocument)mApp.ActiveDocument; //GET ACTIVE INVENTOR WINDOW

            if (assmbleyActiveDoc.SelectSet.Count == 0)
            {
                MessageBox.Show("Nothing Selected Part or Assembly");
                return;
            }

            SelectSet selActiveSet = default(SelectSet);

            selActiveSet = assmbleyActiveDoc.SelectSet;

            try
            {
                ComponentOccurrence compOcc = default(ComponentOccurrence);
                PartDocument        mPartDoc;
                AssemblyDocument    mAssmbleyDoc;

                object obj = null;
                foreach (object obj_loopVariable in selActiveSet)
                {
                    obj = obj_loopVariable;

                    compOcc = (ComponentOccurrence)obj;
                    //System.Diagnostics.Debug.Print(compOcc.Name);

                    AttributeSets attbSets = compOcc.AttributeSets;
                    if (compOcc.DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
                    {
                        mAssmbleyDoc = (AssemblyDocument)compOcc.Definition.Document;

                        DrawAssemDoc(mAssmbleyDoc.FullDocumentName);
                    }
                    else
                    {
                        mPartDoc = (PartDocument)compOcc.Definition.Document;

                        DrawPartDoc(mPartDoc.FullDocumentName);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Is the selected item a Component?");
                MessageBox.Show(ex.ToString());
                return;
            }
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: JRobotson/InventorShims
        private static void wip_kDrawingCurveSegmentObject()
        {
            Inventor.Application oApp  = ApplicationShim.CurrentInstance();
            SelectSet            oSSet = oApp.ActiveDocument.SelectSet;

            if (oSSet.Count == 0)
            {
                return;
            }

            Inventor.Document returnDocument = null;

            dynamic obj = oSSet[2];

            switch (obj.type)
            {
            case 117478144:     //kDrawingCurveSegmentObject
                                //try to set the drawing curve object to point at the containingOccurrence object.
                                //Edge Objects and Edge Proxy Objects

                DrawingCurveSegment drawingCurveSegment = (DrawingCurveSegment)obj;
                DrawingCurve        drawingCurve        = drawingCurveSegment.Parent;


                dynamic modelGeometry;
                try
                {
                    modelGeometry = drawingCurve.ModelGeometry;
                }
                catch
                {
                    Console.WriteLine("Are you sure the object can be found?  The ModelGeometry cannot be located. exiting...");
                    Console.ReadLine();
                    return;
                }

                ComponentOccurrence componentOccurrence;

                try     //for a selected DrawingCurveSegment belonging to an assembly component
                {
                    componentOccurrence = modelGeometry.ContainingOccurrence;
                    returnDocument      = (Document)componentOccurrence.Definition.Document;
                    break;
                }
                catch { }

                try     //for a selected DrawingCurveSegment belonging to a part
                {
                    returnDocument = (Document)modelGeometry.Parent.ComponentDefinition.Document;
                    break;
                }
                catch { }
                break;
            }

            if (returnDocument == null)
            {
                Console.WriteLine("The document could not be found!");
            }
            else
            {
                Console.WriteLine("Document Type: " + returnDocument.DocumentSubType);
                Console.WriteLine(returnDocument.FullFileName);
            }

            Console.ReadLine();
        }
コード例 #20
0
 public override Expression CreateTypedExpressionSelectSetConditional(SelectSet selectSet, Expression subExpression)
 {
     return(new ExpSelectSetConditional <T>(selectSet, subExpression as TypedExpression <T>));
 }
コード例 #21
0
        public void AddExistingSetToTest(Dataset data, int testId)
        {
            this.testId = testId;
            int       setOrder = data.QuestionSetsEx.Count;
            SelectSet sS       = new SelectSet(connection, testId, setId, setOrder, this);

            sS.ShowDialog();

            if (sS.DialogResult == DialogResult.Yes)
            {
                connection.TestQuestionSetSet.TestContents.AddTestContentsRow(
                    connection.TestQuestionSetSet.Tests.FindById(testId),
                    connection.TestQuestionSetSet.QuestionSets.FindById(setId), Convert.ToByte(setOrder));
                Dataset.QuestionSetsExRow row =
                    FullDataset.QuestionSetsEx.AddQuestionSetsExRow(setId, sS.qsRow.Name, sS.qsRow.Description,
                                                                    sS.qsRow.NumberOfQuestionsToPick,
                                                                    sS.qsRow.IsTimeLimitNull()
                                                                        ? (0)
                                                                        : (sS.qsRow.TimeLimit),
                                                                    sS.qsRow.IsQuestionSubtypeIdNull()
                                                                        ? (0)
                                                                        : (sS.qsRow.QuestionSubtypeId),
                                                                    sS.qsRow.IsQuestionTypeIdNull()
                                                                        ? (0)
                                                                        : (sS.qsRow.QuestionTypeId),
                                                                    sS.qsRow.NumberOfQuestionsInZone1,
                                                                    sS.qsRow.NumberOfQuestionsInZone2,
                                                                    sS.qsRow.NumberOfQuestionsInZone3, testId,
                                                                    Convert.ToByte(setOrder));

                if (row.TimeLimit == 0)
                {
                    row.SetTimeLimitNull();
                }

                if (row.QuestionTypeId == 0)
                {
                    row.SetQuestionTypeIdNull();
                }

                if (row.QuestionSubtypeId == 0)
                {
                    row.SetQuestionSubtypeIdNull();
                }

                connection.DataProvider.AddQuestionsExToDataSet(FullDataset, row.Id);
                FullDataset.Tests.FindById(testId).Name += "";
                ApplicationController.Instance.Refresh(connection);
                OnStructureChangedInternally();

                //data.Clear();
                //connection.DataProvider.FillTest(data, testId);

                //TestQuestionSetSet tempValue = new TestQuestionSetSet();

                //tempValue.QuestionSets.AddQuestionSetsRow(setId, sS.qsEx.Name, sS.qsEx.Description, sS.qsEx.NumberOfQuestionsToPick, sS.qsEx.IsTimeLimitNull() ? (0) : (sS.qsEx.TimeLimit), sS.qsEx.IsQuestionSubtypeIdNull() ? (0) : (sS.qsEx.QuestionSubtypeId), sS.qsEx.IsQuestionTypeIdNull() ? (0) : (sS.qsEx.QuestionTypeId), sS.qsEx.NumberOfQuestionsInZone1, sS.qsEx.NumberOfQuestionsInZone2, sS.qsEx.NumberOfQuestionsInZone3);
                ////
                //if(sS.qsEx.IsTimeLimitNull())
                //{
                //    tempValue.QuestionSets[0].SetTimeLimitNull();
                //}

                //if (sS.qsEx.IsQuestionTypeIdNull())
                //{
                //    tempValue.QuestionSets[0].SetQuestionTypeIdNull();
                //}

                //if (sS.qsEx.IsQuestionSubtypeIdNull())
                //{
                //    tempValue.QuestionSets[0].SetQuestionSubtypeIdNull();
                //}

                //QuestionSet qs = new QuestionSet(tempValue.QuestionSets[0], this);
                //AddQuestionSet(qs);

                //Provider provider = connection.DataProvider;
                //provider.AddExistingSetToTest(sS.setId, testId, setOrder);
                //provider.Dispose();
            }
            else
            {
                return;
            }
        }
コード例 #22
0
 public static Expression CreateTypedExpressionSelectSetConditional(Type type, SelectSet selectSet, Expression subExpression)
 {
     return(GetExpressionFactory(type).CreateTypedExpressionSelectSetConditional(selectSet, subExpression));
 }
コード例 #23
0
ファイル: Class2.cs プロジェクト: UnderADome/InventorAppTest1
        private static void GetDrawingDimension()
        {
            try
            {
                inventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
                Console.WriteLine("查找到可用的实例");
            }
            catch { Console.WriteLine("未打开Inventor"); return; }
            DrawingDocument drawingDocument = (DrawingDocument)inventorApp.ActiveDocument;

            //在Inventor当前正在显示的工程图不一样的时候,ActiveSheet也会发生变化
            Console.WriteLine("打开的图纸:" + drawingDocument.ActiveSheet.Name + " " + drawingDocument.FullFileName);
            DrawingView drawingView = drawingDocument.ActiveSheet.DrawingViews[1];

            //特别注明:该类及其方法仅针对模型和草图文件
            GeneralDimensionsEnumerator generalDimensionsEnumerator =
                drawingDocument.ActiveSheet.DrawingDimensions.GeneralDimensions.Retrieve(drawingView);

            Console.WriteLine("generalDimensionsEnumerator.Count = " + generalDimensionsEnumerator.Count);
            if (generalDimensionsEnumerator.Count != 0)
            {
                for (int i = 1; i <= generalDimensionsEnumerator.Count; i++)
                {
                    Console.WriteLine(generalDimensionsEnumerator[i].Text);
                }
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            BaselineDimensionSets baselineDimensionSets = drawingDocument.ActiveSheet.DrawingDimensions.BaselineDimensionSets;

            Console.WriteLine("baselineDimensionSets.Count = " + baselineDimensionSets.Count);
            if (baselineDimensionSets.Count != 0)
            {
                for (int i = 1; i <= baselineDimensionSets.Count; i++)
                {
                    BaselineDimensionSet baselineDimensionSet = baselineDimensionSets[i];
                    Console.WriteLine("baselineDimensionSet.Members = " + baselineDimensionSet.Members);
                    Console.WriteLine("baselineDimensionSet.DimensionType" + baselineDimensionSet.DimensionType);
                }
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            Balloons ballons = drawingDocument.ActiveSheet.Balloons;

            Console.WriteLine("ballons.Count = " + ballons.Count);
            Balloon balloon = null;

            if (ballons.Count != 0)
            {
                for (int i = 1; i <= ballons.Count; i++)
                {
                    Console.WriteLine("\n------------------------ballons[" + i + "]------------------------");
                    balloon = ballons[i];
                    //Console.WriteLine("balloon.Leader.RootNode = " + balloon.Leader.RootNode);  //打印出 System.__ComObject
                    //Console.WriteLine("balloon.Position = " + balloon.Position);  //打印出 System.__ComObject
                    AttributeSets attributeSets = balloon.AttributeSets;
                    Console.WriteLine("attributeSets.Count = " + attributeSets.Count);
                    for (int j = 1; j <= attributeSets.Count; j++)
                    {
                        AttributeSet attributeSet = attributeSets[j];
                        Console.WriteLine("attributeSet.Name = " + attributeSet.Name);
                    }

                    BalloonValueSets balloonValueSets = balloon.BalloonValueSets;
                    for (int j = 1; j <= balloonValueSets.Count; j++)
                    {
                        BalloonValueSet balloonValueSet = balloonValueSets[j];
                        Console.WriteLine("balloonValueSet.ItemNumber = " + balloonValueSet.ItemNumber);
                        Console.WriteLine("balloonValueSet.Value = " + balloonValueSet.Value);
                        Console.WriteLine("balloonValueSet.OverrideValue = " + balloonValueSet.OverrideValue);
                        //Console.WriteLine("balloonValueSet.ReferencedFiles = " + balloonValueSet.ReferencedFiles);
                        Console.WriteLine("balloonValueSet.Type = " + balloonValueSet.Type);
                    }

                    Leader leader = balloon.Leader;
                    Console.WriteLine("leader.ArrowheadType = " + leader.ArrowheadType);
                    Console.WriteLine("leader.Type = " + leader.Type);
                    AttributeSets attributeSets_leader = leader.AttributeSets;
                    Console.WriteLine("attributeSets_leader.Count = " + attributeSets_leader.Count);
                    for (int j = 0; j < attributeSets_leader.Count; j++)
                    {
                        AttributeSet attributeSet = attributeSets[j];
                        Console.WriteLine("attributeSet_leader.Name = " + attributeSet.Name);
                    }

                    Console.WriteLine("END------------------------ballons[" + i + "]------------------------\n");
                }
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            //DrawingViews views = drawingDocument.ActiveSheet.DrawingViews;
            //Console.WriteLine("views.count = " + views.Count);

            Console.WriteLine("drawingDocument.SelectSet.Count = " + drawingDocument.SelectSet.Count);
            SelectSet           selectSet           = null;
            DrawingCurveSegment drawingCurveSegment = null;

            if (drawingDocument.SelectSet.Count == 0)
            {
                Console.WriteLine("Select a drawing view");
                DrawingView view = inventorApp.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view");
                //selectSet = inventorApp.CommandManager.Pick(SelectionFilterEnum.kDrawingSheetFilter, "Select drawing sheet!");
                drawingCurveSegment = inventorApp.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select drawing segment filter");
            }
            else
            {
                selectSet = drawingDocument.SelectSet;
            }

            //DrawingCurveSegment drawingCurveSegment = selectSet[1];//drawingDocument.SelectSet[1];
            DrawingCurve drawingCurve = drawingCurveSegment.Parent;

            //Get the mid point of the selected curve assuming that the selection curve is linear
            Point2d MidPoint = drawingCurve.MidPoint;

            //Set a reference to the TransientGeometry object.
            TransientGeometry TG = inventorApp.TransientGeometry;

            Console.WriteLine("TG : " + (TG == null));
            ObjectCollection LeaderPoints = inventorApp.TransientObjects.CreateObjectCollection();

            Console.WriteLine("LeaderPoints : " + (LeaderPoints == null));

            LeaderPoints.Add(TG.CreatePoint2d(MidPoint.X + 10, MidPoint.Y + 10));
            LeaderPoints.Add(TG.CreatePoint2d(MidPoint.X + 10, MidPoint.Y + 5));

            //Add the GeometryIntent to the leader points collection.
            //This is the geometry that the balloon will attach to.
            GeometryIntent geometryIntent = drawingDocument.ActiveSheet.CreateGeometryIntent(drawingCurve);

            LeaderPoints.Add(geometryIntent);

            //Set a reference to the parent drawing view of the selected curve
            //DrawingView
            drawingView = drawingCurve.Parent;

            //Set a reference to the referenced model document
            Document ModelDoc = drawingView.ReferencedDocumentDescriptor.ReferencedDocument;

            Console.WriteLine(ModelDoc.Type);
            //PartDocument ModelDoc = drawingView.ReferencedDocumentDescriptor.ReferencedDocument;
            //AssemblyDocument ModelDoc = drawingView.ReferencedDocumentDescriptor.ReferencedDocument;

            //Check if a partslist or a balloon has already been created for thie model
            Boolean IsDrawingBOMDefined = drawingDocument.DrawingBOMs.IsDrawingBOMDefined(ModelDoc.FullFileName);

            // Balloon balloon;

            if (IsDrawingBOMDefined)

            {   //当DrawingBOM已经被定义了
                //Just create the balloon with the leader points. All other arguments can be ignored
                Console.WriteLine("当DrawingBOM已经被定义了\n创建气泡标注");
                balloon = drawingDocument.ActiveSheet.Balloons.Add(LeaderPoints);
            }
            else
            {
                //当DrawingBOM没有被定义
                AssemblyDocument            assemblyDocument            = (AssemblyDocument)ModelDoc;
                AssemblyComponentDefinition assemblyComponentDefinition = assemblyDocument.ComponentDefinition;

                ///*
                //First check if the 'structured' BOM view has been enabled in the model
                //Set a reference to the model's BOM object
                //BOM bom = ModelDoc.ComponentDefinition.BOM;
                BOM bom = assemblyComponentDefinition.BOM;

                if (bom.StructuredViewEnabled)
                {
                    //Level needs to be specifieed. Numbering options jave already been defined.
                    //Get the Level('All levels' of 'First level only') from the model BOM view - must use the same here
                    PartsListLevelEnum Level;
                    if (bom.StructuredViewFirstLevelOnly)
                    {
                        Level = PartsListLevelEnum.kStructured;
                    }
                    else
                    {
                        Level = PartsListLevelEnum.kStructuredAllLevels;
                    }
                }
                else
                {
                    //Level and numbering options must be specifieed.
                    //The corresponding model BOM view will automatically be enabled
                    NameValueMap NumberingScheme = inventorApp.TransientObjects.CreateNameValueMap();
                    //Add the option for a comma delimiter
                    NumberingScheme.Add("Delimeter", ",");
                    //Create the balloon by specifying the level and numbering scheme
                    balloon = drawingDocument.ActiveSheet.Balloons.Add(LeaderPoints, PartsListLevelEnum.kStructuredAllLevels, NumberingScheme);
                }
                //*/
            }
        }