// 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;
        }
Exemple #2
0
        public static double AngleBetweenThreePoints(SolidEdgeGeometry.Vertex Start, SolidEdgeGeometry.Vertex Center, SolidEdgeGeometry.Vertex End)//, Vector3D up)
        {
            //Vertexs.GetPointData

            Array p1 = Array.CreateInstance(typeof(double), 0);
            Array p2 = Array.CreateInstance(typeof(double), 0);
            Array p3 = Array.CreateInstance(typeof(double), 0);

            double[] pointStart;
            double[] pointCenter;
            double[] pointEnd;

            Start.GetPointData(ref p1);
            Center.GetPointData(ref p2);
            End.GetPointData(ref p3);

            pointStart  = (double[])p1;
            pointCenter = (double[])p2;
            pointEnd    = (double[])p3;

            double x1 = 0 - pointCenter[0];
            double y1 = 0 - pointCenter[1];
            double z1 = 0 - pointCenter[2];

            Vector3D vt1 = new Vector3D(pointStart[0] + x1, pointStart[1] + y1, pointStart[2] + z1);
            Vector3D vt3 = new Vector3D(pointEnd[0] + x1, pointEnd[1] + y1, pointEnd[2] + z1);

            return(Math.Round(Vector3D.AngleBetween(vt1, vt3)));
        }
Exemple #3
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);
                }
            }
        }
Exemple #4
0
        public SEEdge(SolidEdgeGeometry.Edge edge)
        {
            this.edge = edge;

            Array StartPoint = Array.CreateInstance(typeof(double), 0);
            Array EndPoint   = Array.CreateInstance(typeof(double), 0);

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

            VertexStart.GetPointData(ref StartPoint);
            VertexEnd.GetPointData(ref EndPoint);

            StartP = (double[])StartPoint;
            EndP   = (double[])EndPoint;

            Len = EdgeLen(StartP, EndP);
        }
        static void CreateFaceRotateByPoints(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.Vertices vertices    = null;
            SolidEdgeGeometry.Vertex   point1      = null;
            SolidEdgeGeometry.Vertex   point2      = null;
            double angle = 0.0872664625997165;

            // 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(1);

            vertices = (SolidEdgeGeometry.Vertices)face.Vertices;
            point1   = (SolidEdgeGeometry.Vertex)vertices.Item(1);
            point2   = (SolidEdgeGeometry.Vertex)vertices.Item(2);

            faceRotates = model.FaceRotates;

            // Add face rotate.
            faceRotate = faceRotates.Add(
                face,
                SolidEdgePart.FaceRotateConstants.igFaceRotateByPoints,
                SolidEdgePart.FaceRotateConstants.igFaceRotateRecreateBlends,
                point1,
                point2,
                null,
                SolidEdgePart.FaceRotateConstants.igFaceRotateNone,
                angle);
        }
Exemple #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;
                    }
                }
            }
        }
Exemple #7
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.Vertices     vertices     = null;
            SolidEdgeGeometry.Vertex       point1       = null;
            SolidEdgeGeometry.Vertex       point2       = null;
            SolidEdgeFramework.SelectSet   selectSet    = null;
            double angle = 0.0872664625997165;

            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();

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

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

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

                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(1);

                vertices = (SolidEdgeGeometry.Vertices)face.Vertices;
                point1   = (SolidEdgeGeometry.Vertex)vertices.Item(1);
                point2   = (SolidEdgeGeometry.Vertex)vertices.Item(2);

                faceRotates = model.FaceRotates;

                // Add face rotate.
                faceRotate = faceRotates.Add(
                    face,
                    SolidEdgePart.FaceRotateConstants.igFaceRotateByPoints,
                    SolidEdgePart.FaceRotateConstants.igFaceRotateRecreateBlends,
                    point1,
                    point2,
                    null,
                    SolidEdgePart.FaceRotateConstants.igFaceRotateNone,
                    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();
            }
        }
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application   application        = null;
            SolidEdgeFramework.Documents     documents          = null;
            SolidEdgePart.SheetMetalDocument sheetMetalDocument = null;
            SolidEdgePart.FlatPatternModels  flatPatternModels  = null;
            SolidEdgePart.FlatPatternModel   flatPatternModel   = null;
            SolidEdgePart.Models             models             = null;
            SolidEdgePart.Model      model  = null;
            SolidEdgeGeometry.Face   face   = null;
            SolidEdgeGeometry.Edge   edge   = null;
            SolidEdgeGeometry.Vertex vertex = null;
            bool   useFlatPattern           = true;
            bool   flatPatternIsUpToDate    = false;
            string outFile = 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 Solid Edge,
                application = SolidEdgeUtils.Connect(false);

                // 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;

                // This check is necessary because application.ActiveDocument will throw an
                // exception if no documents are open...
                if (documents.Count > 0)
                {
                    // Attempt to open specified SheetMetalDocument.
                    sheetMetalDocument = application.ActiveDocument as SolidEdgePart.SheetMetalDocument;
                }

                if (sheetMetalDocument == null)
                {
                    throw new System.Exception("No active Sheet Metal 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;
                    }
                }

                Console.WriteLine("Determining desired face, edge & vertex for SaveAsFlatDXFEx().");

                // Some routine to get face, edge & vertex.
                GetFaceEdgeVertexForModel(model, out face, out edge, out vertex);

                outFile = Path.ChangeExtension(sheetMetalDocument.FullName, ".dxf");
                //outFile = Path.ChangeExtension(sheetMetalDocument.FullName, ".par");
                //outFile = Path.ChangeExtension(sheetMetalDocument.FullName, ".psm");

                // 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;
                Console.WriteLine("Saving '{0}'.", outFile);
                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)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                Console.WriteLine(ex.Message);
            }
        }
Exemple #9
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();
            }
        }