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);
        }
        // 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;
        }
        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);
        }
Exemplo n.º 4
0
        //creates a cutout
        private void Create_Cutout(double PointOnGraphic_X, double PointOnGraphic_Y, double PointOnGraphic_Z, SolidEdgeGeometry.Face selected_face,
                                   int[] face_norm, string selected_face_normal)
        {
            PartDocument _doc = _application.ActiveDocument as PartDocument;

            RefPlanes refPlanes = null;
            RefPlane  refPlane  = null;

            refPlanes = _doc.RefPlanes;
            //Adding parallel refplane to the selected face
            refPlane = refPlanes.AddParallelByDistance(selected_face, 0.0, ReferenceElementConstants.igNormalSide, false, false, true, false);

            Relations2d     relations2D     = null;
            ProfileSets     profileSets     = null;
            ProfileSet      profileSet      = null;
            Profiles        profiles        = null;
            Profile         profile         = null;
            Lines2d         lines2D         = null;
            Models          models          = null;
            Model           model           = null;
            Sketchs         sketchs         = null;
            Sketch          sketch          = null;
            ExtrudedCutouts extrudedCutouts = null;


            sketchs = _doc.Sketches;
            sketch  = sketchs.Add();

            profileSets = _doc.ProfileSets;
            profileSet  = profileSets.Add();
            profiles    = sketch.Profiles;

            profile     = profiles.Add(refPlane);
            lines2D     = profile.Lines2d;
            relations2D = (Relations2d)profile.Relations2d;

            //adding a 2D profile for the cutout
            lines2D.AddBy2Points(0.03, -0.055, 0.045, -0.055);
            lines2D.AddBy2Points(0.045, -0.055, 0.045, -0.04);
            lines2D.AddBy2Points(0.045, -0.04, 0.03, -0.04);
            lines2D.AddBy2Points(0.03, -0.04, 0.03, -0.055);

            profile.End(ProfileValidationType.igProfileClosed);

            models = _doc.Models;
            model  = models.Item(1);

            extrudedCutouts = model.ExtrudedCutouts;

            //adding a new extruded cutout
            extrudedCutouts.AddThroughNext(Profile: profile,
                                           ProfileSide: FeaturePropertyConstants.igLeft,
                                           ProfilePlaneSide: FeaturePropertyConstants.igLeft
                                           );
        }
Exemplo n.º 5
0
        //creates a slot
        private void Create_Slot(double PointOnGraphic_X, double PointOnGraphic_Y, double PointOnGraphic_Z, SolidEdgeGeometry.Face selected_face,
                                 int[] face_norm, string selected_face_normal)
        {
            PartDocument _doc = _application.ActiveDocument as PartDocument;

            RefPlanes refPlanes = null;
            RefPlane  refPlane  = null;

            refPlanes = _doc.RefPlanes;
            //Adding a parallel refplane to the selected face
            refPlane = refPlanes.AddParallelByDistance(selected_face, 0.0, ReferenceElementConstants.igNormalSide, false, false, true, false);

            ProfileSets profileSets = null;
            ProfileSet  profileSet  = null;
            Profiles    profiles    = null;
            Profile     profile     = null;
            Lines2d     lines2D     = null;
            Models      models      = null;
            Model       model       = null;
            Sketchs     sketchs     = null;
            Sketch      sketch      = null;
            Slots       slots       = null;
            Slot        slot        = null;

            sketchs = _doc.Sketches;
            sketch  = sketchs.Add();

            profileSets = _doc.ProfileSets;
            profileSet  = profileSets.Add();
            profiles    = sketch.Profiles;

            //Adding the refplane to the profile
            profile = profiles.Add(refPlane);
            lines2D = profile.Lines2d;


            lines2D.AddBy2Points(0.02, 0, 0.02, 0.02);

            profile.End(ProfileValidationType.igProfileClosed);

            models = _doc.Models;
            model  = models.Item(1);

            slots = model.Slots;

            //Adding a new slot
            slots.Add(Profile: profile,
                      SlotType: FeaturePropertyConstants.igRegularSlot,
                      SlotEndCondition: FeaturePropertyConstants.igFormedEnd,
                      SlotWidth: 0.005,
                      SlotOffsetWidth: 0,
                      SlotOffsetDepth: 0,
                      ExtentType: FeaturePropertyConstants.igThroughAll,
                      ExtentSide: FeaturePropertyConstants.igLeft,
                      FiniteDistance: 0,
                      KeyPointFlags: KeyPointExtentConstants.igTangentNormal,
                      KeyPointOrTangentFace: null,
                      ExtentType2: FeaturePropertyConstants.igNone,
                      ExtentSide2: FeaturePropertyConstants.igNone,
                      FiniteDistance2: 0,
                      KeyPointFlags2: KeyPointExtentConstants.igTangentNormal,
                      KeyPointOrTangentFace2: null,
                      FromFaceOrPlane: null,
                      FromOffsetSide: OffsetSideConstants.seOffsetNone,
                      FromOffsetDistance: 0,
                      ToFaceOrPlane: null,
                      ToOffsetSide: OffsetSideConstants.seOffsetNone,
                      ToOffsetDistance: 0
                      );
        }
Exemplo n.º 6
0
        //creates a hole
        private void create_hole(double PointOnGraphic_X, double PointOnGraphic_Y, double PointOnGraphic_Z, SolidEdgeGeometry.Face selected_face,
                                 int[] face_norm, string selected_face_normal)
        {
            // var selected_face = pGraphicDispatch as SolidEdgeGeometry.Face;
            PartDocument _doc = _application.ActiveDocument as PartDocument;

            RefPlanes refPlanes = null;
            RefPlane  refPlane  = null;

            refPlanes = _doc.RefPlanes;
            //Adding parallel refplane to the selected face
            refPlane = refPlanes.AddParallelByDistance(selected_face, 0.0, ReferenceElementConstants.igNormalSide, false, false, true, false);



            //Running windows form application
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.Run(new Form1());

            MessageBox.Show("Cancel Hole Dimension?");
            Form1 form1 = new Form1();

            //Hole diameter from user input
            double cc = form1.Hole_dia;

            while (cc < 0.0)
            {
                MessageBox.Show("Enter valid dimension");
                System.Windows.Forms.Application.EnableVisualStyles();
                System.Windows.Forms.Application.Run(new Form1());
                Form1  form2 = new Form1();
                double dd    = form2.Hole_dia;
                MessageBox.Show("Cancel diamension?");
                if (cc == dd)
                {
                    MessageBox.Show("invalid argument");
                    dd = 0.0;
                }
                cc = dd;
            }

            ProfileSets        profileSets        = null;
            ProfileSet         profileSet         = null;
            Profiles           profiles           = null;
            Profile            profile            = null;
            Models             models             = null;
            HoleDataCollection holeDataCollection = null;
            HoleData           holeData           = null;
            Holes2d            holes2D            = null;
            Holes   holes   = null;
            Sketchs sketchs = null;
            Sketch  sketch  = null;


            Array ref_dir = new double[3] as Array;

            //getting the unit vector of the reference direction
            refPlane.GetReferenceDirection(ref ref_dir);
            var Ref_dirX = ref_dir as double[];

            Array root_point = new double[3] as Array;

            refPlane.GetRootPoint(ref root_point);
            var Root_point = root_point as double[];

            //calculating the cross-product between ref_dir and normal vector
            double[] Ref_dirY = new double[3]
            {
                Ref_dirX[2] * face_norm[1] - Ref_dirX[1] * face_norm[2],
                Ref_dirX[0] * face_norm[2] - Ref_dirX[2] * face_norm[0],
                Ref_dirX[1] * face_norm[0] - Ref_dirX[0] * face_norm[1]
            };

            double Xcenter = -0.06; //local coordinates
            double Ycenter = -0.06;

            //calculating global coordinates from local coordinates
            double[] X_bar = new double[3]
            {
                Xcenter *Ref_dirX[0] + Ycenter * Ref_dirY[0] + Root_point[0],
                     Xcenter *Ref_dirX[1] + Ycenter * Ref_dirY[1] + Root_point[1],
                     Xcenter *Ref_dirX[2] + Ycenter * Ref_dirY[2] + Root_point[2]
            };

            //Calculating the angle between vectors root_point and global
            double[] OX = new double[3]
            {
                PointOnGraphic_X - Root_point[0],
                PointOnGraphic_Y - Root_point[1],
                PointOnGraphic_Z - Root_point[2]
            };

            //calculating the modulus of vector OX
            double OX_Mod = Math.Sqrt(Math.Pow(OX[0], 2) + Math.Pow(OX[1], 2) + Math.Pow(OX[2], 2));

            //calculating the modulus of vector Ref_dirX
            double Ref_dirX_Mod = Math.Sqrt(Math.Pow(Ref_dirX[0], 2) + Math.Pow(Ref_dirX[1], 2) + Math.Pow(Ref_dirX[2], 2));

            //calculating the modulus of the vector ReF_dirY
            double Ref_dirY_Mod = Math.Sqrt(Math.Pow(Ref_dirY[0], 2) + Math.Pow(Ref_dirY[1], 2) + Math.Pow(Ref_dirY[2], 2));

            //calculating the dot product between vector OX and Ref_dirY
            double dotY = (OX[0] * Ref_dirY[0]) + (OX[1] * Ref_dirY[1]) + (OX[2] * Ref_dirY[2]);

            //calculating the dot product between vector OX and Ref_dirX
            double dotX = (OX[0] * Ref_dirX[0]) + (OX[1] * Ref_dirX[1]) + (OX[2] * Ref_dirX[2]);

            //calculating the angle between vector OX and Ref_dirY
            double angleY = Math.Acos(dotY / (OX_Mod * Ref_dirY_Mod));

            //calculating the angle between vector OX and Ref_dirX
            double angleX = Math.Acos(dotX / (OX_Mod * Ref_dirX_Mod));

            double X_dir = 0.0;
            double Y_dir = 0.0;


            if (angleY > Math.PI / 2)
            {
                X_dir = OX_Mod * Math.Cos(-angleX);

                Y_dir = OX_Mod * Math.Sin(-angleX);
            }
            else
            {
                X_dir = OX_Mod * Math.Cos(angleX);
                Y_dir = OX_Mod * Math.Sin(angleX);
            }

            if (OX_Mod == 0.0)
            {
                X_dir = 0.0;
                Y_dir = 0.0;
            }

            if (cc > 0.0)
            {
                sketchs = _doc.Sketches;
                sketch  = sketchs.Add();

                holeDataCollection = _doc.HoleDataCollection;

                //Defining hole properties
                holeData = holeDataCollection.Add(
                    HoleType: SolidEdgePart.FeaturePropertyConstants.igRegularHole,
                    HoleDiameter: cc / 1000);

                profileSets = _doc.ProfileSets;
                profileSet  = profileSets.Add();
                //profiles = profileSet.Profiles;
                profiles = sketch.Profiles;

                profile = profiles.Add(refPlane);
                holes2D = profile.Holes2d;

                var dd = holes2D.Add(X_dir, Y_dir);


                profile.End(ProfileValidationType.igProfileClosed);

                // dd.Move(X_dir, Y_dir, 0.0, 0.0);
                //_application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewLookatFace);

                //getting the hole collection and creating a simple hole
                Model model = _doc.Models.Item(1);
                holes = model.Holes;
                holes.AddThroughNext(
                    Profile: profile,
                    ProfilePlaneSide: SolidEdgePart.FeaturePropertyConstants.igBoth,
                    Data: holeData);
            }
        }
Exemplo n.º 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.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();
            }
        }
Exemplo 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.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);
            }
        }
Exemplo n.º 10
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;
            SolidEdgeGeometry.Faces        faces        = null;
            SolidEdgeGeometry.Face         face         = null;
            SolidEdgePart.Thickens         thickens     = null;
            SolidEdgePart.Thicken          thicken      = 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;

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

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

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

                body = (SolidEdgeGeometry.Body)model.Body;

                faces = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];

                thickens = model.Thickens;

                Type type   = typeof(SolidEdgePart.FeaturePropertyConstants);
                var  fields = type.GetFields();

                for (int i = 1; i <= faces.Count; i++)
                {
                    model    = models.Item(1);
                    body     = (SolidEdgeGeometry.Body)model.Body;
                    faces    = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];
                    thickens = model.Thickens;

                    face = faces.Item(i) as SolidEdgeGeometry.Face;

                    Array facesArray = Array.CreateInstance(typeof(SolidEdgeGeometry.Face), 1);

                    facesArray.SetValue(face, 0);

                    foreach (var field in fields)
                    {
                        if (field.IsSpecialName)
                        {
                            continue;
                        }
                        SolidEdgePart.FeaturePropertyConstants side = (SolidEdgePart.FeaturePropertyConstants)field.GetRawConstantValue();

                        try
                        {
                            thicken = thickens.Add(side, 0.0254, 1, ref facesArray);

                            thicken.Delete();
                            break;
                        }
                        catch
                        {
                        }
                    }
                    //thicken = thickens.Add(SolidEdgePart.FeaturePropertyConstants.igReverseNormalSideDummy, 0.0254, 1, ref facesArray);

                    //selectSet = application.ActiveSelectSet;
                    //selectSet.RemoveAll();
                    //selectSet.Add(faces.Item(1));
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Exemplo n.º 11
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();
            }
        }