static void CreateFaceRotateByGeometry(SolidEdgePart.PartDocument partDocument)
        {
            SolidEdgePart.Models      models      = null;
            SolidEdgePart.Model       model       = null;
            SolidEdgeGeometry.Body    body        = null;
            SolidEdgePart.FaceRotates faceRotates = null;
            SolidEdgePart.FaceRotate  faceRotate  = null;
            SolidEdgeGeometry.Faces   faces       = null;
            SolidEdgeGeometry.Face    face        = null;
            SolidEdgeGeometry.Edges   edges       = null;
            SolidEdgeGeometry.Edge    edge        = null;
            double angle = 0.5;

            // Get a reference to the models collection.
            models = partDocument.Models;
            model  = models.Item(1);
            body   = (SolidEdgeGeometry.Body)model.Body;
            faces  = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];
            face   = (SolidEdgeGeometry.Face)faces.Item(2);
            edges  = (SolidEdgeGeometry.Edges)body.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];
            edge   = (SolidEdgeGeometry.Edge)edges.Item(5);

            faceRotates = model.FaceRotates;

            // Add face rotate.
            faceRotate = faceRotates.Add(
                face,
                SolidEdgePart.FaceRotateConstants.igFaceRotateByGeometry,
                SolidEdgePart.FaceRotateConstants.igFaceRotateRecreateBlends,
                null,
                null,
                edge,
                SolidEdgePart.FaceRotateConstants.igFaceRotateAxisEnd,
                angle);
        }
Esempio n. 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            // Connect to or start Solid Edge.
            YCC_solidedge.getEdgeApplication(ref SEApp, true);


            SolidEdgeAssembly.AssemblyDocument asydoc = (SolidEdgeAssembly.AssemblyDocument)SEApp.ActiveDocument;

            SolidEdgeAssembly.Occurrences occs = (SolidEdgeAssembly.Occurrences)asydoc.Occurrences;
            SolidEdgeAssembly.Occurrence  occ  = (SolidEdgeAssembly.Occurrence)occs.Item(2);

            Array MinRangePoint = Array.CreateInstance(typeof(double), 0);
            Array MaxRangePoint = Array.CreateInstance(typeof(double), 0);

            //object[] w = new object[3];

            occ.GetRangeBox(ref MinRangePoint, ref MaxRangePoint);


            SolidEdgePart.PartDocument ps = (SolidEdgePart.PartDocument)occ.OccurrenceDocument;
            //SolidEdgePart.Models ms = (SolidEdgePart.Models)ps.Models.Item[1];
            SolidEdgePart.Model m = (SolidEdgePart.Model)ps.Models.Item(1);

            SolidEdgeGeometry.Body b = (SolidEdgeGeometry.Body)m.Body;

            SolidEdgeGeometry.Edges ees = (SolidEdgeGeometry.Edges)b.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];
            SolidEdgeGeometry.Edge  ee  = (SolidEdgeGeometry.Edge)ees.Item(1);

            //ee.GetRange(ref MinRangePoint, ref MaxRangePoint);


            b.GetRange(ref MinRangePoint, ref MaxRangePoint);
        }
        // In a real world scenario, you would want logic (or user input) to pick the desired
        // face, edge & *vertex. Here, we just grab the 1st we can find. *Vertex can be null.
        static void GetFaceEdgeVertexForModel(
            SolidEdgePart.Model model,
            out SolidEdgeGeometry.Face face,
            out SolidEdgeGeometry.Edge edge,
            out SolidEdgeGeometry.Vertex vertex)
        {
            SolidEdgeGeometry.Body  body = null;
            SolidEdgeGeometry.Faces faces;
            SolidEdgeGeometry.Edges edges = null;

            // Get a reference to the model's body.
            body = (SolidEdgeGeometry.Body)model.Body;

            // Query for all faces in the body.
            faces = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];

            // Get a reference to the first face.
            face = (SolidEdgeGeometry.Face)faces.Item(1);

            // Get a reference to the face's Edges collection,
            edges = (SolidEdgeGeometry.Edges)face.Edges;

            // Get a reference to the first edge.
            edge = (SolidEdgeGeometry.Edge)edges.Item(1);

            // Not using vertex in this example.
            vertex = null;
        }
Esempio n. 4
0
        private void GetOtherEdge(SolidEdgeGeometry.Vertex Vertex, SolidEdgeGeometry.Edge Edge)
        {
            SolidEdgeGeometry.Edges Edges = (SolidEdgeGeometry.Edges)Vertex.Edges;

            foreach (SolidEdgeGeometry.Edge _edge in Edges)
            {
                if (_edge == Edge)
                {
                    continue;
                }

                if (!ListOtherHexagonEdge.Contains(_edge))
                {
                    ListOtherHexagonEdge.Add(_edge);
                }
            }
        }
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application        application  = null;
            SolidEdgeFramework.Documents          documents    = null;
            SolidEdgePart.PartDocument            partDocument = null;
            SolidEdgePart.RefPlanes               refPlanes    = null;
            SolidEdgePart.RefPlane                refPlane     = null;
            SolidEdgePart.ProfileSets             profileSets  = null;
            SolidEdgePart.ProfileSet              profileSet   = null;
            SolidEdgePart.Profiles                profiles     = null;
            SolidEdgePart.Profile                 profile      = null;
            SolidEdgePart.Models                  models       = null;
            SolidEdgePart.Model                   model        = null;
            SolidEdgeFrameworkSupport.Lines2d     lines2d      = null;
            SolidEdgeFrameworkSupport.Line2d      axis         = null;
            SolidEdgeFrameworkSupport.Arcs2d      arcs2d       = null;
            SolidEdgeFrameworkSupport.Relations2d relations2d  = null;
            SolidEdgePart.RefAxis                 refaxis      = null;
            Array aProfiles = null;

            SolidEdgeGeometry.Edges           edges  = null;
            SolidEdgeGeometry.Circle          circle = null;
            SolidEdgePart.RevolvedProtrusions revolvedProtrusions = null;
            SolidEdgePart.RevolvedProtrusion  revolvedProtrusion  = null;
            Array center = null;

            SolidEdgePart.Rounds rounds = null;

            try
            {
                Console.WriteLine("Registering OleMessageFilter.");

                // Register with OLE to handle concurrency issues on the current thread.
                OleMessageFilter.Register();

                Console.WriteLine("Connecting to Solid Edge.");

                // Connect to or start Solid Edge.
                application = SolidEdgeUtils.Connect(true);

                // Make sure user can see the GUI.
                application.Visible = true;

                // Bring Solid Edge to the foreground.
                application.Activate();

                // Get a reference to the Documents collection.
                documents = application.Documents;

                Console.WriteLine("Creating a new part document.");

                // Create a new PartDocument.
                partDocument = (SolidEdgePart.PartDocument)
                               documents.Add("SolidEdge.PartDocument");

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                Console.WriteLine("Drawing part.");

                // Get a reference to the models collection.
                models = (SolidEdgePart.Models)partDocument.Models;


                // D1 to FA are parameters in a form, introduced by the user.
                double D1 = 0.020;
                double D2 = 0.026;
                double D3 = 0.003;
                double D4 = 0.014;
                double L1 = 0.040;
                double L2 = 0.030;
                double L3 = 0.005;
                double FA = 0.0005; // round

                // Get a reference to the ref planes collection.
                refPlanes = partDocument.RefPlanes;

                // Front (xz).
                refPlane = refPlanes.Item(3);

                // Get a reference to the profile sets collection.
                profileSets = (SolidEdgePart.ProfileSets)partDocument.ProfileSets;

                // Create a new profile set.
                profileSet = profileSets.Add();

                // Get a reference to the profiles collection.
                profiles = profileSet.Profiles;

                // Create a new profile.
                profile = profiles.Add(refPlane);

                // Get a reference to the profile lines2d collection.
                lines2d = profile.Lines2d;

                // Get a reference to the profile arcs2d collection.
                arcs2d = profile.Arcs2d;

                double H = L1 - L2;
                double y = L1 - L3 - (D4 - D3) / (2 * Math.Tan((118 / 2) * (Math.PI / 180)));

                lines2d.AddBy2Points(D3 / 2, 0, D2 / 2, 0);        // Line1
                lines2d.AddBy2Points(D2 / 2, 0, D2 / 2, H);        // Line2
                lines2d.AddBy2Points(D2 / 2, H, D1 / 2, H);        // Line3
                lines2d.AddBy2Points(D1 / 2, H, D1 / 2, L1);       // Line4
                lines2d.AddBy2Points(D1 / 2, L1, D4 / 2, L1);      // Line5
                lines2d.AddBy2Points(D4 / 2, L1, D4 / 2, L1 - L3); // Line6
                lines2d.AddBy2Points(D4 / 2, L1 - L3, D3 / 2, y);  // Line7
                lines2d.AddBy2Points(D3 / 2, y, D3 / 2, 0);        // Line8

                axis = lines2d.AddBy2Points(0, 0, 0, L1);
                profile.ToggleConstruction(axis);

                // relations
                relations2d = (SolidEdgeFrameworkSupport.Relations2d)profile.Relations2d;
                relations2d.AddKeypoint(lines2d.Item(1), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(2), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(2), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(3), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(3), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(4), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(4), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(5), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(5), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(6), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(6), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(7), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(7), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(8), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(8), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(1), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);

                refaxis = (SolidEdgePart.RefAxis)profile.SetAxisOfRevolution(axis);

                // Close the profile.
                int status = profile.End(SolidEdgePart.ProfileValidationType.igProfileRefAxisRequired);
                profile.Visible = false;

                // Create a new array of profile objects.
                aProfiles = Array.CreateInstance(typeof(SolidEdgePart.Profile), 1);
                aProfiles.SetValue(profile, 0);

                Console.WriteLine("Creating finite revolved protrusion.");

                // add Finite Revolved Protrusion.
                model = models.AddFiniteRevolvedProtrusion(1, ref aProfiles, refaxis, SolidEdgePart.FeaturePropertyConstants.igRight, 2 * Math.PI, null, null);

                Console.WriteLine("Creating adding rounds.");

                SolidEdgeGeometry.Edge[] arrEdges = { null };
                double[] arrRadii = { FA };

                revolvedProtrusions = model.RevolvedProtrusions;
                revolvedProtrusion  = revolvedProtrusions.Item(1);
                edges = (SolidEdgeGeometry.Edges)revolvedProtrusion.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];

                foreach (SolidEdgeGeometry.Edge edge in edges)
                {
                    circle = (SolidEdgeGeometry.Circle)edge.Geometry;
                    if (circle.Radius == D2 / 2)
                    {
                        center = Array.CreateInstance(typeof(double), 3);
                        circle.GetCenterPoint(ref center);
                        if ((double)center.GetValue(0) == 0 && (double)center.GetValue(1) == 0 && (double)center.GetValue(2) == H)
                        {
                            arrEdges[0] = edge;
                            break;
                        }
                    }
                }

                rounds = model.Rounds;
                object optArg = Type.Missing;
                rounds.Add(1, arrEdges, arrRadii, optArg, optArg, optArg, optArg);

                Console.WriteLine("Switching to ISO view.");

                // Switch to ISO view.
                application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 6
0
        public void validpoint(SolidEdgeGeometry.Edge Edge)
        {
            if (ListHexagonEdge.Count() != 0 && Edge == StandardEdge)
            {
                return;
            }
            SolidEdgeGeometry.Vertex VertexStart;
            SolidEdgeGeometry.Vertex VertexEnd;

            VertexStart = (SolidEdgeGeometry.Vertex)Edge.StartVertex;
            VertexEnd   = (SolidEdgeGeometry.Vertex)Edge.EndVertex;

            SolidEdgeGeometry.Edges EdgesStartPoint = (SolidEdgeGeometry.Edges)VertexStart.Edges;

            SolidEdgeGeometry.Edge HexagonEdge;
            SolidEdgeGeometry.Edge HoleEdge;

            //edge가 2개일 경
            if (EdgesStartPoint.Count != 3)
            {
                return;
            }

            foreach (SolidEdgeGeometry.Edge _edge in EdgesStartPoint)
            {
                if (_edge == Edge)
                {
                    continue;
                }

                if (_edge.StartVertex != VertexStart)
                {
                    SolidEdgeGeometry.Vertex newVertex = (SolidEdgeGeometry.Vertex)_edge.StartVertex;
                    double angle = AngleBetweenThreePoints(VertexEnd, VertexStart, newVertex);

                    if (angle == 120)
                    {
                        HexagonEdge = _edge;
                        ListHexagonEdge.Add(_edge);

                        Array p1 = Array.CreateInstance(typeof(double), 0);
                        newVertex.GetPointData(ref p1);
                        //sk.Points3D.Add(3, p1);

                        validpoint(_edge);
                    }
                    else if (angle == 90)
                    {
                        HoleEdge = _edge;
                        ListHoleEdge.Add(_edge);
                        GetOtherEdge(newVertex, _edge);

                        //Array p1 = Array.CreateInstance(typeof(double), 0);
                        //newVertex.GetPointData(ref p1);
                        //sk.Points3D.Add(3, p1);
                    }
                    else
                    {
                        //
                        return;
                    }
                }
                else
                {
                    SolidEdgeGeometry.Vertex newVertex = (SolidEdgeGeometry.Vertex)_edge.EndVertex;
                    double angle = AngleBetweenThreePoints(VertexEnd, VertexStart, newVertex);

                    if (angle == 120)
                    {
                        HexagonEdge = _edge;
                        ListHexagonEdge.Add(_edge);
                        validpoint(_edge);
                    }
                    else if (angle == 90)
                    {
                        HoleEdge = _edge;
                        ListHoleEdge.Add(_edge);
                        GetOtherEdge(newVertex, _edge);

                        //Array p1 = Array.CreateInstance(typeof(double), 0);
                        //newVertex.GetPointData(ref p1);
                        //sk.Points3D.Add(3, p1);
                    }
                    else
                    {
                        //
                        return;
                    }
                }
            }
        }
Esempio n. 7
0
        private void button4_Click(object sender, EventArgs e)
        {
            YCC_solidedge.getEdgeApplication(ref SEApp, true);
            partDoc = (SolidEdgePart.PartDocument)SEApp.ActiveDocument;
            SolidEdgePart.Model     md = partDoc.Models.Item(1);
            SolidEdgeGeometry.Body  by = (SolidEdgeGeometry.Body)md.Body;
            SolidEdgeGeometry.Edges ed = (SolidEdgeGeometry.Edges)by.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryStraight];

            List <SolidEdgeGeometry.Edge> ListExceptionEdge = new List <SolidEdgeGeometry.Edge>();

            int Count = 0;

            foreach (SolidEdgeGeometry.Edge _e in ed)
            {
                if (ListExceptionEdge.Contains(_e))
                {
                    continue;
                }

                SEEdge newpoint = new SEEdge(_e);

                if (newpoint.Len == 23.09 || newpoint.Len == 11.55)
                {
                    POP newPOP = new POP(newpoint);
                    Count = Count + 1;

                    if (newPOP.ListHexagonEdge.Count == 6)
                    {
                        foreach (SolidEdgeGeometry.Edge _edge in newPOP.ListHexagonEdge)
                        {
                            ListExceptionEdge.Add(_edge);
                        }
                        foreach (SolidEdgeGeometry.Edge _edge in newPOP.ListHoleEdge)
                        {
                            ListExceptionEdge.Add(_edge);
                        }
                        foreach (SolidEdgeGeometry.Edge _edge in newPOP.ListOtherHexagonEdge)
                        {
                            ListExceptionEdge.Add(_edge);
                        }
                    }
                }
            }


            //bool done = true;
            //int count = 0;
            //while (done)
            //{
            //    foreach (SEEdge _p in point23)
            //    {
            //        if (www(ref point23, _p))
            //        {
            //            count++;
            //            break;
            //        }

            //        if (_p == point23[point23.Count() - 1]) done = false;
            //    }

            //    if (point23.Count == 0) done = false;
            //}
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application        application  = null;
            SolidEdgeFramework.Documents          documents    = null;
            SolidEdgePart.PartDocument            partDocument = null;
            SolidEdgePart.RefPlanes               refPlanes    = null;
            SolidEdgePart.RefPlane                refPlane     = null;
            SolidEdgePart.ProfileSets             profileSets  = null;
            SolidEdgePart.ProfileSet              profileSet   = null;
            SolidEdgePart.Profiles                profiles     = null;
            SolidEdgePart.Profile                 profile      = null;
            SolidEdgeFrameworkSupport.Lines2d     lines2d      = null;
            SolidEdgeFrameworkSupport.Line2d      line2d       = null;
            SolidEdgeFrameworkSupport.Relations2d relations2d  = null;
            SolidEdgeFrameworkSupport.Relation2d  relation2d   = null;
            SolidEdgePart.Models         models      = null;
            SolidEdgePart.Model          model       = null;
            List <SolidEdgePart.Profile> profileList = new List <SolidEdgePart.Profile>();
            int status = 0;

            SolidEdgePart.ExtrudedProtrusions extrudedProtrusions = null;
            SolidEdgePart.ExtrudedProtrusion  extrudedProtrusion  = null;
            SolidEdgeGeometry.Edges           edges = null;
            List <object> edgeList = new List <object>();

            SolidEdgeGeometry.Faces faces    = null;
            SolidEdgePart.Chamfers  chamfers = null;
            SolidEdgePart.Chamfer   chamfer  = null;

            try
            {
                // Register with OLE to handle concurrency issues on the current thread.
                SolidEdgeCommunity.OleMessageFilter.Register();

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Bring Solid Edge to the foreground.
                application.Activate();

                // Get a reference to the documents collection.
                documents = application.Documents;

                // Create a new part document.
                partDocument = documents.AddPartDocument();

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                refPlanes = partDocument.RefPlanes;
                refPlane  = refPlanes.Item(1);

                profileSets = partDocument.ProfileSets;
                profileSet  = profileSets.Add();

                profiles = profileSet.Profiles;
                profile  = profiles.Add(refPlane);
                profileList.Add(profile);

                lines2d = profile.Lines2d;
                line2d  = lines2d.AddBy2Points(0, 0, 0.06, 0);
                line2d  = lines2d.AddBy2Points(0.06, 0, 0.06, 0.06);
                line2d  = lines2d.AddBy2Points(0.06, 0.06, 0, 0.06);
                line2d  = lines2d.AddBy2Points(0, 0.06, 0, 0);

                relations2d = (SolidEdgeFrameworkSupport.Relations2d)profile.Relations2d;
                relation2d  = relations2d.AddKeypoint(
                    Object1: lines2d.Item(1),
                    Index1: (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                    Object2: lines2d.Item(2),
                    Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);

                relation2d = relations2d.AddKeypoint(
                    Object1: lines2d.Item(2),
                    Index1: (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                    Object2: lines2d.Item(3),
                    Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);

                relation2d = relations2d.AddKeypoint(
                    Object1: lines2d.Item(3),
                    Index1: (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                    Object2: lines2d.Item(4),
                    Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);

                relation2d = relations2d.AddKeypoint(
                    Object1: lines2d.Item(4),
                    Index1: (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                    Object2: lines2d.Item(1),
                    Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);

                // Make sure profile is closed.
                status = profile.End(SolidEdgePart.ProfileValidationType.igProfileClosed);

                if (status != 0)
                {
                    throw new System.Exception("Profile not closed.");
                }

                models = partDocument.Models;

                model = models.AddFiniteExtrudedProtrusion(
                    NumberOfProfiles: profileList.Count,
                    ProfileArray: profileList.ToArray(),
                    ProfilePlaneSide: SolidEdgePart.FeaturePropertyConstants.igRight,
                    ExtrusionDistance: 0.02);

                profile.Visible = false;

                extrudedProtrusions = model.ExtrudedProtrusions;
                extrudedProtrusion  = extrudedProtrusions.Item(1);

                //edges = (SolidEdgeGeometry.Edges)extrudedProtrusion.get_Edges(
                //    SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll);

                //edgeList.Add(edges.Item(5));
                //edgeList.Add(edges.Item(8));

                faces = (SolidEdgeGeometry.Faces)
                        extrudedProtrusion.get_Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll);

                chamfers = model.Chamfers;

                SolidEdgeGeometry.Face face = (SolidEdgeGeometry.Face)faces.Item(1);
                double setbackDistance1     = 0.009;
                double setbackDistance2     = 0.001;

                edges = (SolidEdgeGeometry.Edges)face.Edges;
                edgeList.Add(edges.Item(1));

                chamfer = chamfers.AddUnequalSetback(
                    ReferenceFace: face,
                    NumberOfEdgeSets: edgeList.Count,
                    EdgeSetArray: edgeList.ToArray(),
                    SetbackDistance1: setbackDistance1,
                    SetbackDistance2: setbackDistance2);

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application  = null;
            SolidEdgeFramework.Documents   documents    = null;
            SolidEdgePart.PartDocument     partDocument = null;
            SolidEdgePart.RefPlanes        refPlanes    = null;
            SolidEdgePart.RefPlane         refPlane     = null;
            SolidEdgePart.Models           models       = null;
            SolidEdgePart.Model            model        = null;
            SolidEdgeGeometry.Body         body         = null;
            SolidEdgePart.FaceRotates      faceRotates  = null;
            SolidEdgePart.FaceRotate       faceRotate   = null;
            SolidEdgeGeometry.Faces        faces        = null;
            SolidEdgeGeometry.Face         face         = null;
            SolidEdgeGeometry.Edges        edges        = null;
            SolidEdgeGeometry.Edge         edge         = null;
            SolidEdgeFramework.SelectSet   selectSet    = null;
            double angle = 0.5;

            try
            {
                // Register with OLE to handle concurrency issues on the current thread.
                SolidEdgeCommunity.OleMessageFilter.Register();

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the documents collection.
                documents = application.Documents;

                // Create a new part document.
                partDocument = documents.AddPartDocument();

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                // Get a reference to the RefPlanes collection.
                refPlanes = partDocument.RefPlanes;

                // Get a reference to a RefPlane.
                refPlane = refPlanes.GetFrontPlane();

                List <double[]> linesArray = new List <double[]>();
                linesArray.Add(new double[] { 0, 0, 0.08, 0 });
                linesArray.Add(new double[] { 0.08, 0, 0.08, 0.06 });
                linesArray.Add(new double[] { 0.08, 0.06, 0.064, 0.06 });
                linesArray.Add(new double[] { 0.064, 0.06, 0.064, 0.02 });
                linesArray.Add(new double[] { 0.064, 0.02, 0.048, 0.02 });
                linesArray.Add(new double[] { 0.048, 0.02, 0.048, 0.06 });
                linesArray.Add(new double[] { 0.048, 0.06, 0.032, 0.06 });
                linesArray.Add(new double[] { 0.032, 0.06, 0.032, 0.02 });
                linesArray.Add(new double[] { 0.032, 0.02, 0.016, 0.02 });
                linesArray.Add(new double[] { 0.016, 0.02, 0.016, 0.06 });
                linesArray.Add(new double[] { 0.016, 0.06, 0, 0.06 });
                linesArray.Add(new double[] { 0, 0.06, 0, 0 });

                // Call helper method to create the actual geometry.
                PartHelper.CreateFiniteExtrudedProtrusion(partDocument, refPlane, linesArray.ToArray(), SolidEdgePart.FeaturePropertyConstants.igRight, 0.005);

                // Get a reference to the models collection.
                models = partDocument.Models;
                model  = models.Item(1);
                body   = (SolidEdgeGeometry.Body)model.Body;
                faces  = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];
                face   = (SolidEdgeGeometry.Face)faces.Item(2);
                edges  = (SolidEdgeGeometry.Edges)body.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];
                edge   = (SolidEdgeGeometry.Edge)edges.Item(5);

                faceRotates = model.FaceRotates;

                // Add face rotate.
                faceRotate = faceRotates.Add(
                    face,
                    SolidEdgePart.FaceRotateConstants.igFaceRotateByGeometry,
                    SolidEdgePart.FaceRotateConstants.igFaceRotateRecreateBlends,
                    null,
                    null,
                    edge,
                    SolidEdgePart.FaceRotateConstants.igFaceRotateAxisEnd,
                    angle);

                // Get a reference to the ActiveSelectSet.
                selectSet = application.ActiveSelectSet;

                // Empty ActiveSelectSet.
                selectSet.RemoveAll();

                // Add new FaceRotate to ActiveSelectSet.
                selectSet.Add(faceRotate);

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application   application        = null;
            SolidEdgeFramework.Documents     documents          = null;
            SolidEdgePart.SheetMetalDocument sheetMetalDocument = null;
            SolidEdgePart.Models             models             = null;
            SolidEdgePart.Model             model             = null;
            SolidEdgePart.FlatPatternModels flatPatternModels = null;
            SolidEdgePart.FlatPatternModel  flatPatternModel  = null;
            SolidEdgeGeometry.Body          body = null;
            SolidEdgeGeometry.Faces         faces;
            SolidEdgeGeometry.Face          face   = null;
            SolidEdgeGeometry.Edges         edges  = null;
            SolidEdgeGeometry.Edge          edge   = null;
            SolidEdgeGeometry.Vertex        vertex = null;
            bool   useFlatPattern        = true;
            bool   flatPatternIsUpToDate = false;
            string outFile = null;

            try
            {
                // Register with OLE to handle concurrency issues on the current thread.
                SolidEdgeCommunity.OleMessageFilter.Register();

                // Connect to Solid Edge,
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(false);

                // Get a reference to the Documents collection.
                documents = application.Documents;

                // Get a refernce to the active sheetmetal document.
                sheetMetalDocument = application.GetActiveDocument <SolidEdgePart.SheetMetalDocument>(false);

                if (sheetMetalDocument == null)
                {
                    throw new System.Exception("No active document.");
                }

                // Get a reference to the Models collection,
                models = sheetMetalDocument.Models;

                // Check for geometry.
                if (models.Count == 0)
                {
                    throw new System.Exception("No geometry defined.");
                }

                // Get a reference to the one and only model.
                model = models.Item(1);

                // Get a reference to the FlatPatternModels collection,
                flatPatternModels = sheetMetalDocument.FlatPatternModels;

                // Observation: SaveAsFlatDXFEx() will fail if useFlatPattern is specified and
                // flatPatternModels.Count = 0.
                // The following code will turn off the useFlatPattern switch if flatPatternModels.Count = 0.
                if (useFlatPattern)
                {
                    if (flatPatternModels.Count > 0)
                    {
                        for (int i = 1; i <= flatPatternModels.Count; i++)
                        {
                            flatPatternModel      = flatPatternModels.Item(i);
                            flatPatternIsUpToDate = flatPatternModel.IsUpToDate;

                            // If we find one that is up to date, call it good and bail.
                            if (flatPatternIsUpToDate)
                            {
                                break;
                            }
                        }

                        if (flatPatternIsUpToDate == false)
                        {
                            // Flat patterns exist but are out of date.
                            useFlatPattern = false;
                        }
                    }
                    else
                    {
                        // Can't use flat pattern if none exist.
                        useFlatPattern = false;
                    }
                }


                // In a real world scenario, you would want logic (or user input) to pick the desired
                // face, edge & *vertex. Here, we just grab the 1st we can find. *Vertex can be null.

                // Get a reference to the model's body.
                body = (SolidEdgeGeometry.Body)model.Body;

                // Query for all faces in the body.
                faces = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];

                // Get a reference to the first face.
                face = (SolidEdgeGeometry.Face)faces.Item(1);

                // Get a reference to the face's Edges collection,
                edges = (SolidEdgeGeometry.Edges)face.Edges;

                // Get a reference to the first edge.
                edge = (SolidEdgeGeometry.Edge)edges.Item(1);

                // Not using vertex in this example.
                vertex = null;

                outFile = System.IO.Path.ChangeExtension(sheetMetalDocument.FullName, ".dxf");

                // Observation: If .par or .psm is specified in outFile, SE will open the file.
                // Even if useFlatPattern = true, it's a good idea to specify defaults for face, edge & vertex.
                // I've seen where outFile of .dxf would work but .psm would fail if the defaults were null;
                models.SaveAsFlatDXFEx(outFile, face, edge, vertex, useFlatPattern);

                if (useFlatPattern)
                {
                    Console.WriteLine("Saved '{0}' using Flat Pattern.", outFile);
                }
                else
                {
                    Console.WriteLine("Saved '{0}' without using Flat Pattern.", outFile);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application    application         = null;
            SolidEdgeFramework.Documents      documents           = null;
            SolidEdgePart.PartDocument        partDocument        = null;
            SolidEdgePart.Model               model               = null;
            SolidEdgePart.RevolvedProtrusions revolvedProtrusions = null;
            SolidEdgePart.RevolvedProtrusion  revolvedProtrusion  = null;
            SolidEdgeGeometry.Edges           edges               = null;
            SolidEdgePart.Rounds              rounds              = null;
            SolidEdgePart.Round               round               = null;
            SolidEdgeFramework.SelectSet      selectSet           = null;

            try
            {
                // Register with OLE to handle concurrency issues on the current thread.
                SolidEdgeCommunity.OleMessageFilter.Register();

                // Connect to or start Solid Edge.
                application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true);

                // Get a reference to the Documents collection.
                documents = application.Documents;

                // Create a new PartDocument.
                partDocument = documents.AddPartDocument();

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                // Call helper method to create the actual geometry.
                model = PartHelper.CreateFiniteRevolvedProtrusion(partDocument);

                // Get a reference to the RevolvedProtrusions collection.
                revolvedProtrusions = model.RevolvedProtrusions;

                // Get a reference to the new RevolvedProtrusion.
                revolvedProtrusion = revolvedProtrusions.Item(1);

                // Get a all Edges.
                edges = (SolidEdgeGeometry.Edges)revolvedProtrusion.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];

                List <SolidEdgeGeometry.Edge> edgeList = new List <SolidEdgeGeometry.Edge>();
                List <double> radiusList = new List <double>();

                // Build arrays.
                foreach (SolidEdgeGeometry.Edge edge in edges)
                {
                    edgeList.Add(edge);
                    radiusList.Add(0.002);
                }

                // Get a reference to the Rounds collection.
                rounds = model.Rounds;

                // Add single round with multiple Edges.
                round = rounds.Add(edgeList.Count, edgeList.ToArray(), radiusList.ToArray());

                // Get a reference to the ActiveSelectSet.
                selectSet = application.ActiveSelectSet;

                // Empty ActiveSelectSet.
                selectSet.RemoveAll();

                // Add new Round to ActiveSelectSet.
                selectSet.Add(round);

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }