예제 #1
0
        public void AddFeature(SldWorks SwApp, ModelDoc2 SwModel, Point2D P1, Point2D P2)
        {
            if (CheckUsing() == false)
            {
                return;
            }

            SwModel.ClearSelection2(true);

            double         L              = P2.x - P1.x; // stage length
            SketchManager  sketchManager  = SwModel.SketchManager;
            FeatureManager featureManager = SwModel.FeatureManager;
            Helper         helper         = new Helper(SwModel, SwApp);


            helper.select_feature("RefPlane", 2, false, 0);
            if (P1.x > 0)
            // if x cordinat of first point is 0 we use stantart plane, else - make new refplane by offset
            {
                SwModel.CreatePlaneAtOffset(P1.x, false);
            }


            sketchManager.InsertSketch(true);

            #region                                //Squre

            if (keyProfileType == (object)"Squre") // make squre stage for key (out)
            {
                sketchManager.CreateCenterRectangle(0, 0, 0, (keyProfileWidth / 2),
                                                    (keyProfileWidth / 2), 0);

                featureManager.FeatureCut3(true, true, true, 0, 0, L, 0,
                                           false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true,
                                           false, 0, 0, false); // add cut feature
            }

            #endregion

            #region                                   //Special

            if (keyProfileType == (object)"Speacial") // make special stage for key (out)
            {
                double H = Math.Sqrt((Math.Pow((2 * P1.y), 2) - Math.Pow(keyProfileWidth, 2)));

                sketchManager.Create3PointArc((keyProfileWidth / 2), (H / 2), 0,
                                              (-1 * keyProfileWidth / 2), (H / 2), 0, 0, P1.y, 0); // Top arc

                sketchManager.Create3PointArc((keyProfileWidth / 2), (-1 * H / 2), 0, (-1 * keyProfileWidth / 2),
                                              (-1 * H / 2), 0, 0, (-1 * P1.y), 0); // Bottom arc

                sketchManager.CreateLine((keyProfileWidth / 2), (H / 2), 0, (keyProfileWidth / 2),
                                         (-1 * H / 2), 0); // Left line

                sketchManager.CreateLine((-1 * keyProfileWidth / 2), (H / 2), 0, (-1 * keyProfileWidth / 2),
                                         (-1 * H / 2), 0); // Rigth line

                featureManager.FeatureCut3(true, true, true, 0, 0, L, 0,
                                           false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true,
                                           false, 0, 0, false); // add cut feature
                sketchManager.InsertSketch(false);
            }

            #endregion

            #region                                  // Hexagon

            if (keyProfileType == (object)"Hexagon") // make squre stage for key (out)
            {
                sketchManager.CreatePolygon(0, 0, 0, 0, P1.y, 0, 6, false);

                featureManager.FeatureCut3(true, true, true, 0, 0, L, 0,
                                           false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true,
                                           false, 0, 0, false); // add cut feature
            }

            #endregion

            helper.HidePlanes();
        }
예제 #2
0
        public void AddFeature(SldWorks SwApp, ModelDoc2 SwModel, Point2D P1, Point2D P2)
        {
            if (CheckUsing() == false)
            {
                return;
            }
            SwModel.ClearSelection2(true);
            Helper         helper         = new Helper(SwModel, SwApp);
            SelectionMgr   selectionMgr   = SwModel.SelectionManager;
            SketchManager  sketchManager  = SwModel.SketchManager;
            FeatureManager featureManager = SwModel.FeatureManager;
            const double   Aprox          = 0.0005; // needs to make correct theard
            Sketch         swSketch       = default(Sketch);

            double L = P2.x - P1.x;

            helper.select_feature("RefPlane", 2, false, 0);

            if (P1.x > 0)
            {
                SwModel.CreatePlaneAtOffset(P1.x, false);
            }


            sketchManager.InsertSketch(true);

            // create helix
            sketchManager.CreateCircleByRadius(0, 0, 0, P1.y);
            SwModel.InsertHelix(false, theardCW, false, true, 2, L, theardPinch, 0, 0, 0);
            SwModel.ClearSelection2(true);


            #region //Triangle profile

            if (theardType == (object)"Triangle")
            {
                double XL = (P1.y - theardR) / 2;      // haf of triangle base
                double YL = XL * (double)Math.Sqrt(3); // median of triangle

                helper.select_feature("RefPlane", 1, false, 0);
                sketchManager.InsertSketch(true);
                sketchManager.CreateLine((P1.x - XL + Aprox), P1.y, 0, (P1.x + XL - Aprox), P1.y, 0);
                sketchManager.CreateLine((P1.x - XL + Aprox), P1.y, 0, P1.x, (P1.y - YL), 0);
                sketchManager.CreateLine((P1.x + XL - Aprox), P1.y, 0, P1.x, (P1.y - YL), 0);
            }

            #endregion

            #region //Trapeze profile

            if (theardType == (object)"Trapeze")
            {
                helper.select_feature("RefPlane", 1, false, 0);
                sketchManager.InsertSketch(true);
                double H    = (P1.y - theardR) / 2;            // haf of trapaze top base and heigth
                double ctgA = 1 / Math.Tan(helper.ToRad(105)); // ctg value of bottom base angle
                double A    = 2 * (H - Aprox) + 4 * H * ctgA;

                sketchManager.CreateLine((P1.x - H / 2 + Aprox), P1.y, 0, (P1.x + H / 2 - Aprox), P1.y, 0);
                sketchManager.CreateLine((P1.x - H / 2 + Aprox), P1.y, 0, (P1.x - (A / 4)), P1.y - H, 0);
                sketchManager.CreateLine((P1.x + H / 2 - Aprox), P1.y, 0, (P1.x + (A / 4)), P1.y - H, 0);
                sketchManager.CreateLine((P1.x - (A / 4)), P1.y - H, 0, (P1.x + (A / 4)), P1.y - H, 0);
            }

            #endregion

            swSketch = SwModel.GetActiveSketch2() as Sketch;
            SwModel.EditRebuild3(); // model rebuild needs to make cutsweep feature avaible

            Entity ent = swSketch as Entity;
            ent.Select2(false, 1); // select sketch using mark 1 for sweep cut
            helper.select_feature("Helix", helper.get_features_count("Helix") - 1, true, 4);

            featureManager.InsertCutSwept4(false, true, 0, false, false, 0, 0, false, 0, 0, 0, 0, true, true, 0,
                                           true, true, true, false);

            helper.HidePlanes();
        }
예제 #3
0
        public void AddFeature(SldWorks SwApp, ModelDoc2 SwModel, Point2D P1, Point2D P2)
        {
            if (CheckUsing() == false)
            {
                return;
            }

            SwModel.ClearSelection2(true);

            object[] seating_types    = new[] { "None", "Prismatic A", "Prismatic B", "Segmented" };
            object[] operations_types = new[] { "None", "Chamfer", "Fillet" }; // array of operation names
            Helper   helper           = new Helper(SwModel, SwApp);

            FeatureManager featureManager = SwModel.FeatureManager;
            SketchManager  sketchManager  = SwModel.SketchManager;
            SelectionMgr   selectionMgr   = (SelectionMgr)SwModel.SelectionManager;
            Entity         ent            = default(Entity);
            Array          facesArray     = default(Array);
            Array          edgesArray     = default(Array);
            Feature        swFeature      = default(Feature);
            Face2          face2          = default(Face2); // neds to get edges of selected face
            double         LStage         = 0;
            double         x_center       = 0;
            double         y_center       = 0;
            double         L      = 0;
            double         W      = 0;
            bool           append = false;

            LStage   = P2.x - P1.x;                         // length of current stage
            x_center = P1.x + (LStage / 2) + seatingOffset; // center of current stage
            y_center = 0;
            L        = x_center + seatingLength / 2;
            W        = seatingWidth / 2;


            SwModel.ClearSelection2(true);

            #region                              // make prismatic A keyseat

            if (seatingType == seating_types[1]) //Prismatic A
            {
                helper.select_feature("RefPlane", 1, false, 0);
                SwModel.CreatePlaneAtOffset(P1.y, false);
                sketchManager.InsertSketch(true);

                sketchManager.CreateCenterRectangle(x_center, y_center, 0, L, W, 0);
                SwModel.FeatureManager.FeatureCut3(true, false, false, 0, 0, seatingDepth, 0,
                                                   false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true,
                                                   false, 0, 0, false); // add cut feature

                if (seatingOpearationType != operations_types[0])       // add chamfer or fillet, if none or value is 0 - pass
                {
                    swFeature  = (Feature)selectionMgr.GetSelectedObject6(1, -1);
                    facesArray = (Array)swFeature.GetFaces();
                    ent        = facesArray.GetValue(0) as Entity;
                    ent.Select4(false, null);

                    if (seatingOpearationType == operations_types[1])
                    {
                        featureManager.InsertFeatureChamfer(4, 1, seatingChamferFilletValue, helper.ToRad(45), 0, 0, 0,
                                                            0);
                    }
                    if (seatingOpearationType == operations_types[2])
                    {
                        SwModel.FeatureManager.FeatureFillet(195, seatingChamferFilletValue, 0,
                                                             0, null, null, null);
                    }

                    swFeature = selectionMgr.GetSelectedObject6(1, -1);
                    swFeature.Select2(false, 4); //create selection for pattern
                    append = true;
                }


                CreatePattern(helper, append, SwModel, swFeature, selectionMgr);
            }

            #endregion

            #region                              // make prismatic B keyseat

            if (seatingType == seating_types[2]) //Prismatic B
            {
                W = seatingWidth;                //Width

                helper.select_feature("RefPlane", 1, false, 0);
                SwModel.CreatePlaneAtOffset(P1.y, false);
                sketchManager.InsertSketch(true);
                sketchManager.CreateSketchSlot((int)swSketchSlotCreationType_e.swSketchSlotCreationType_line,
                                               (int)swSketchSlotLengthType_e.swSketchSlotLengthType_CenterCenter, W, L - seatingLength, 0, 0, L, 0,
                                               0,
                                               0, 0, 0, 1, false);
                SwModel.FeatureManager.FeatureCut3(true, false, false, 0, 0, seatingDepth, 0,
                                                   false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true,
                                                   false, 0, 0, false);

                if (seatingOpearationType != operations_types[0]) // add chamfer or fillet, if none or value is 0 - pass
                {
                    swFeature  = (Feature)selectionMgr.GetSelectedObject6(1, -1);
                    facesArray = (Array)swFeature.GetFaces();
                    ent        = facesArray.GetValue(0) as Entity;
                    ent.Select4(false, null);

                    if (seatingOpearationType == operations_types[1])
                    {
                        featureManager.InsertFeatureChamfer(4, 1,
                                                            seatingChamferFilletValue, helper.ToRad(45), 0, 0, 0, 0);
                    }
                    if (seatingOpearationType == operations_types[2])
                    {
                        SwModel.FeatureManager.FeatureFillet(195, seatingChamferFilletValue, 0,
                                                             0, null, null, null);
                    }


                    swFeature = selectionMgr.GetSelectedObject6(1, -1);
                    swFeature.Select2(false, 4); //create selection for pattern
                    append = true;
                }


                CreatePattern(helper, append, SwModel, swFeature, selectionMgr);
            }

            #endregion

            #region                              // make segmented seatkey

            if (seatingType == seating_types[3]) //Segmented
            {
                helper.select_feature("RefPlane", 0, false, 0);
                sketchManager.InsertSketch(true);
                sketchManager.Create3PointArc(L - seatingLength, P1.y, 0, L, P1.y, 0, x_center, (P1.y - seatingDepth), 0);
                sketchManager.CreateLine(L - seatingLength, P1.y, 0, L, P1.y, 0); //close sketsh
                SwModel.FeatureManager.FeatureCut3(true, false, false, 6, 0, (seatingWidth), 0,
                                                   false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true,
                                                   false, 0, 0, false); //cut from mide plane

                if (SeatingOpearationType != operations_types[0])       // add chamfer or fillet, if nono or value is 0 - pass
                {
                    // select edges for chamfering or filleting
                    swFeature  = (Feature)selectionMgr.GetSelectedObject6(1, -1);
                    facesArray = (Array)swFeature.GetFaces();
                    SelectData selectData = selectionMgr.CreateSelectData();
                    ent = facesArray.GetValue(2) as Entity;
                    ent.Select4(false, selectData);
                    face2      = selectionMgr.GetSelectedObject6(1, -1);
                    edgesArray = (Array)face2.GetEdges();
                    ent        = edgesArray.GetValue(0) as Entity;
                    ent.Select4(false, null);
                    ent = edgesArray.GetValue(2) as Entity;
                    ent.Select4(true, null);
                    // select edges for chamfering or filleting
                    //  MessageBox.Show("" + face2.GetEdgeCount());

                    if (seatingOpearationType == operations_types[1])
                    {
                        featureManager.InsertFeatureChamfer(4, 1, seatingChamferFilletValue, helper.ToRad(45), 0, 0, 0,
                                                            0);
                    }

                    if (seatingOpearationType == operations_types[2])
                    {
                        SwModel.FeatureManager.FeatureFillet(195, seatingChamferFilletValue, 0, 0, null, null, null);
                    }


                    swFeature = selectionMgr.GetSelectedObject6(1, -1);
                    swFeature.Select2(false, 4); //create selection for pattern
                    append = true;
                }

                CreatePattern(helper, append, SwModel, swFeature, selectionMgr);
            }

            #endregion

            helper.HidePlanes();
        }