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);
            }
        }
Ejemplo n.º 2
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.Sketchs                     sketches        = null;
            SolidEdgePart.Sketch                      sketch          = null;
            SolidEdgePart.Profiles                    profiles        = null;
            SolidEdgePart.Profile                     profile         = null;
            SolidEdgeFrameworkSupport.BSplineCurves2d bsplineCurves2d = null;
            SolidEdgeFrameworkSupport.BSplineCurve2d  bsplineCurve2d1 = null;
            SolidEdgeFrameworkSupport.BSplineCurve2d  bsplineCurve2d2 = null;
            double startX = 0;
            double startY = 0;
            double endX   = 0;
            double endY   = 0;

            SolidEdgeFrameworkSupport.Arcs2d      arcs2d      = null;
            SolidEdgeFrameworkSupport.Arc2d       arc2d       = null;
            SolidEdgeFrameworkSupport.Relations2d relations2d = 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 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 front RefPlane.
                refPlane = refPlanes.GetFrontPlane();

                // Get a reference to the Sketches collection.
                sketches = partDocument.Sketches;

                // Create a new sketch.
                sketch = sketches.Add();

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

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

                // Get a reference to the BSplineCurves2d collection.
                bsplineCurves2d = profile.BSplineCurves2d;

                List <double> points = new List <double>();
                points.Add(10.0 / 1000);
                points.Add(0.0 / 1000);
                points.Add(9.0 / 1000);
                points.Add(6.0 / 1000);
                points.Add(3.0 / 1000);
                points.Add(12.0 / 1000);

                // Create initial b-spline.
                bsplineCurve2d1 = bsplineCurves2d.AddByPoints(
                    Order: 6,
                    ArraySize: 3,
                    Array: points.ToArray());

                // Mirror initial b-spline.
                bsplineCurve2d2 = (SolidEdgeFrameworkSupport.BSplineCurve2d)
                                  bsplineCurve2d1.Mirror(
                    x1: 0.0,
                    y1: 1.0,
                    x2: 0.0,
                    y2: -1.0,
                    BooleanCopyFlag: true);

                bsplineCurve2d1.GetNode(
                    Index: bsplineCurve2d1.NodeCount,
                    x: out startX,
                    y: out startY);

                bsplineCurve2d2.GetNode(
                    Index: bsplineCurve2d2.NodeCount,
                    x: out endX,
                    y: out endY);

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

                // Draw arc to connect the two b-splines.
                arc2d = arcs2d.AddByCenterStartEnd(
                    xCenter: 0.0,
                    yCenter: 0.0,
                    xStart: startX,
                    yStart: startY,
                    xEnd: endX,
                    yEnd: endY);

                int endKeyPointIndex1 = GetBSplineCurves2dEndKeyPointIndex(bsplineCurve2d1);
                int endKeyPointIndex2 = GetBSplineCurves2dEndKeyPointIndex(bsplineCurve2d2);

                // Get a reference to the Relations2d collection.
                relations2d = (SolidEdgeFrameworkSupport.Relations2d)
                              profile.Relations2d;

                // Connect BSplineCurve2d and arc.
                relations2d.AddKeypoint(
                    Object1: bsplineCurve2d1,
                    Index1: endKeyPointIndex1,
                    Object2: arc2d,
                    Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igArcStart);

                // Connect BSplineCurve2d and arc.
                relations2d.AddKeypoint(
                    Object1: bsplineCurve2d2,
                    Index1: endKeyPointIndex2,
                    Object2: arc2d,
                    Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igArcEnd);

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Ejemplo n.º 3
0
    public static SolidEdgePart.Model CreateFiniteRevolvedProtrusion(SolidEdgePart.PartDocument partDocument)
    {
        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;

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

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

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

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

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

        return(model);
    }
        static void CreateBSplineCurve2d(SolidEdgePart.PartDocument partDocument)
        {
            SolidEdgePart.RefPlanes refPlanes = null;
            SolidEdgePart.RefPlane  refPlane  = null;
            SolidEdgePart.Sketchs   sketches  = null;
            SolidEdgePart.Sketch    sketch    = null;
            SolidEdgePart.Profiles  profiles  = null;
            SolidEdgePart.Profile   profile   = null;
            SolidEdgeFrameworkSupport.BSplineCurves2d bsplineCurves2d = null;
            SolidEdgeFrameworkSupport.BSplineCurve2d  bsplineCurve2d1 = null;
            SolidEdgeFrameworkSupport.BSplineCurve2d  bsplineCurve2d2 = null;
            double startX = 0;
            double startY = 0;
            double endX   = 0;
            double endY   = 0;

            SolidEdgeFrameworkSupport.Arcs2d      arcs2d      = null;
            SolidEdgeFrameworkSupport.Arc2d       arc2d       = null;
            SolidEdgeFrameworkSupport.Relations2d relations2d = null;

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

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

            // Get a reference to the Sketches collection.
            sketches = partDocument.Sketches;

            // Create a new sketch.
            sketch = sketches.Add();

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

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

            // Get a reference to the BSplineCurves2d collection.
            bsplineCurves2d = profile.BSplineCurves2d;

            List <double> points = new List <double>();

            points.Add(10.0 / 1000);
            points.Add(0.0 / 1000);
            points.Add(9.0 / 1000);
            points.Add(6.0 / 1000);
            points.Add(3.0 / 1000);
            points.Add(12.0 / 1000);

            // Create initial b-spline.
            bsplineCurve2d1 = bsplineCurves2d.AddByPoints(
                Order: 6,
                ArraySize: 3,
                Array: points.ToArray());

            // Mirror initial b-spline.
            bsplineCurve2d2 = (SolidEdgeFrameworkSupport.BSplineCurve2d)
                              bsplineCurve2d1.Mirror(
                x1: 0.0,
                y1: 1.0,
                x2: 0.0,
                y2: -1.0,
                BooleanCopyFlag: true);

            bsplineCurve2d1.GetNode(
                Index: bsplineCurve2d1.NodeCount,
                x: out startX,
                y: out startY);

            bsplineCurve2d2.GetNode(
                Index: bsplineCurve2d2.NodeCount,
                x: out endX,
                y: out endY);

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

            // Draw arc to connect the two b-splines.
            arc2d = arcs2d.AddByCenterStartEnd(
                xCenter: 0.0,
                yCenter: 0.0,
                xStart: startX,
                yStart: startY,
                xEnd: endX,
                yEnd: endY);

            int endKeyPointIndex1 = GetBSplineCurves2dEndKeyPointIndex(bsplineCurve2d1);
            int endKeyPointIndex2 = GetBSplineCurves2dEndKeyPointIndex(bsplineCurve2d2);

            // Get a reference to the Relations2d collection.
            relations2d = (SolidEdgeFrameworkSupport.Relations2d)
                          profile.Relations2d;

            // Connect BSplineCurve2d and arc.
            relations2d.AddKeypoint(
                Object1: bsplineCurve2d1,
                Index1: endKeyPointIndex1,
                Object2: arc2d,
                Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igArcStart);

            // Connect BSplineCurve2d and arc.
            relations2d.AddKeypoint(
                Object1: bsplineCurve2d2,
                Index1: endKeyPointIndex2,
                Object2: arc2d,
                Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igArcEnd);
        }