Esempio n. 1
0
        public static void DrawSketch(ModelDoc2 SketchDoc)
        {
            SketchManager SwSketchMrg = SketchDoc.SketchManager;//获得SketchManager对象

            SketchDoc.Extension.SelectByID2("前视基准面", "PLANE", 0, 0, 0, false, 0, null, 0);
            SwSketchMrg.InsertSketch(true);//进入编辑草图模式
            object[]      ObjRectangle = SwSketchMrg.CreateCenterRectangle(0, 0, 0, 0.075, 0.04, 0);
            SketchSegment SktCircle1   = SwSketchMrg.CreateCircle(-0.0425, 0, 0, -0.03, 0, 0);
            SketchSegment SktCircle2   = SwSketchMrg.CreateCircle(0.0425, 0, 0, 0.03, 0, 0);
            SketchSegment SktCentLine  = SwSketchMrg.CreateCenterLine(0, 0.04, 0, 0, -0.04, 0);

            SwSketchMrg.InsertSketch(true);//退出编辑草图模式
        }
Esempio n. 2
0
        /// <summary>
        /// Рисует тело, в котором будут отверстия
        /// </summary>
        /// <returns>Возвращает объект, на котором будут сделаны ячейки</returns>
        public void drawBody()
        {
            //получем ссылку на интерфейс, ответственный за рисование
            swSketchManager = application.swModel.SketchManager;
            application.swModel.Extension.SelectByID2("Сверху", "PLANE", 0, 0, 0, false, 0, null, 0); //выбрал плоскость

            swSketchManager.InsertSketch(false);
            sketch = application.swModel.GetActiveSketch2();
            //создать основание
            var rect = swSketchManager.CreateCenterRectangle(0, 0, 0, body.GetWidth() / acc / 2.0, body.GetHeight() / acc / 2.0, 0);

            //очистить буфер выбранных элементов
            application.swModel.ClearSelection();

            //вытянуть бобышку
            Feature feature = featureExtrusion(body.GetLenght() / acc);

            application.swModel.ClearSelection();

            body3d = feature;
        }
Esempio n. 3
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);
            SketchManager  sketchManager  = SwModel.SketchManager;
            FeatureManager featureManager = SwModel.FeatureManager;
            SelectionMgr   selectionMgr   = SwModel.SelectionManager;
            Feature        feature        = default(Feature);
            Entity         entity         = default(Entity);
            Face2          face2          = default(Face2);
            Array          faceArray      = default(Array);
            Array          edgeArray      = default(Array);
            Edge           swEdge         = default(Edge);

            List <double> filletedges = new List <double>();
            double        edgeL       = default(double);

            double[] TNormal = { 0, 1, 0 };  // Y up normal
            double[] LNormal = { 0, 0, 1 };  // +Z normal
            double[] RNormal = { 0, 0, -1 }; // -Z normal

            CurveParamData curveParamData = default(CurveParamData);

            double LStage = P2.x - P1.x;

            #region // add features

            helper.select_feature("RefPlane", 0, false, 0);
            SwModel.InsertSketch();

            if (splinedMethod == (object)"From Start")
            {
                sketchManager.CreateLine(P1.x, P1.y, 0, (P1.x + splinedLength), P1.y, 0); // top line
                sketchManager.CreateLine(P1.x, splinedR, 0, ((P1.x + splinedLength) - splinedArcL), splinedR, 0);
                // bottom line
                sketchManager.CreateLine(P1.x, P1.y, 0, P1.x, splinedR, 0); //left line
                sketchManager.CreateTangentArc((P1.x + (splinedLength - splinedArcL)), splinedR, 0,
                                               (P1.x + splinedLength),
                                               P1.y, 0, 1);
            }

            if (splinedMethod == (object)"From End")
            {
                sketchManager.CreateLine(P2.x, P1.y, 0, (P2.x - splinedLength), P2.y, 0); // top line
                sketchManager.CreateLine(P2.x, splinedR, 0, (P2.x - (splinedLength - splinedArcL)), splinedR, 0);
                // bottom line
                sketchManager.CreateLine(P2.x, P1.y, 0, P2.x, splinedR, 0); //left line
                sketchManager.CreateTangentArc((P2.x - (splinedLength - splinedArcL)), splinedR, 0,
                                               (P2.x - splinedLength),
                                               P1.y, 0, 0);
            }

            if (splinedMethod == (object)"Through")
            {
                sketchManager.CreateCenterRectangle((P1.x + (LStage / 2)), (splinedR + (P1.y - splinedR) / 2), 0,
                                                    P1.x, P1.y, 0);
            }


            SwModel.FeatureManager.FeatureCut3(true, false, false, 6, 0, splinedWidth, 0,
                                               false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true,
                                               false, 0, 0, false); //cut from mide plane

            #endregion

            feature   = (Feature)selectionMgr.GetSelectedObject6(1, -1);
            faceArray = feature.GetFaces() as Array;

            #region // edge filleting, 0 - pass

            if (splinedFillet != 0)

            {
                for (int j = 0; j < faceArray.Length; j++) // get face by normal 0,1,0
                {
                    face2 = faceArray.GetValue(j) as Face2;
                    var normal = face2.Normal;
                    if (TNormal.SequenceEqual(normal as double[]))
                    {
                        entity = faceArray.GetValue(j) as Entity;
                        entity.Select4(false, null);
                        //                                MessageBox.Show(j.ToString());
                        break;
                    }
                }

                face2     = selectionMgr.GetSelectedObject6(1, -1);
                edgeArray = face2.GetEdges() as Array;
                //                     MessageBox.Show(""+face2.GetEdgeCount().ToString());
                SwModel.ClearSelection();

                for (int j = 0; j < face2.GetEdgeCount(); j++) // finding of edge length
                {
                    swEdge         = edgeArray.GetValue(j) as Edge;
                    curveParamData = swEdge.GetCurveParams3();
                    edgeL          = Math.Abs(curveParamData.UMaxValue - curveParamData.UMinValue);
                    filletedges.Add(edgeL);
                }


                double max = filletedges.Max();
                for (int j = 0; j < filletedges.Count; j++) // select edges for filleting
                {
                    if (filletedges[j] == max)
                    {
                        entity = edgeArray.GetValue(j) as Entity;
                        entity.Select4(true, null);
                    }
                }

                featureManager.FeatureFillet(194, splinedFillet, 0, 0, null, null, null);
                // edges fillet 194 - target propagate off
                SwModel.ClearSelection2(true);
            }

            #endregion

            #region // edge chamfering, 0 - pass

            if (splinedChamfer != 0)
            {
                List <Face2> facesList = new List <Face2>();
                facesList.Add(default(Face2));             // empty element
                facesList.Add(default(Face2));             // empty element

                for (int j = 0; j < faceArray.Length; j++) // select faces by normal
                {
                    face2 = faceArray.GetValue(j) as Face2;
                    var normal = face2.Normal;
                    if (LNormal.SequenceEqual(normal as double[]))
                    {
                        facesList[0] = face2;
                    }
                    if (RNormal.SequenceEqual(normal as double[]))
                    {
                        facesList[1] = face2;
                    }
                }

                faceArray = facesList.ToArray() as Array; // refill array of neded face's
                int index_f0 = 0;                         // index of top edge L
                int index_f1 = 0;                         // index of top edge R

                for (int j = 0; j < faceArray.Length; j++)
                {
                    face2     = faceArray.GetValue(j) as Face2;
                    edgeArray = face2.GetEdges() as Array;
                    swEdge    = edgeArray.GetValue(0) as Edge;

                    CurveParamData cData = swEdge.GetCurveParams3() as CurveParamData;

                    var Spoint = (double[])cData.StartPoint;
                    var Epoint = (double[])cData.EndPoint;


                    for (int k = 0; k < edgeArray.Length; k++)
                    {
                        swEdge = edgeArray.GetValue(k) as Edge;
                        cData  = swEdge.GetCurveParams3() as CurveParamData;
                        var SP = (double[])cData.StartPoint;
                        var EP = (double[])cData.EndPoint;

                        if ((SP[1] >= Spoint[1]) && (EP[1] >= Epoint[1])) // check max y cordinats of the edge
                        {
                            if (Spoint[1] == Spoint[1])                   // horisontal line always have same y cordinats
                            {
                                Epoint = EP;
                                Spoint = SP;
                                if (j == 0)
                                {
                                    index_f0 = k;
                                }
                                else
                                {
                                    index_f1 = k;
                                }
                            }
                        }
                    }
                }


                // finally selecy top up edges
                face2     = faceArray.GetValue(0) as Face2;
                edgeArray = face2.GetEdges() as Array;
                entity    = edgeArray.GetValue(index_f0) as Entity;
                entity.Select4(false, null);


                face2     = faceArray.GetValue(1) as Face2;
                edgeArray = face2.GetEdges() as Array;
                entity    = edgeArray.GetValue(index_f1) as Entity;
                entity.Select4(true, null);

                int chamferOpt = 4; // target propagate by default

                if (splinedMethod == (object)"From Start" ||
                    splinedMethod == (object)"From End")
                {
                    chamferOpt = 1; // flip direction
                }
                featureManager.InsertFeatureChamfer(chamferOpt, 1, splinedChamfer, helper.ToRad(45), 0, 0, 0, 0);
                SwModel.ClearSelection2(true);
            }

            #endregion

            #region //Pattern if value less then 1 pass

            if (splinedArray > 1)
            {
                helper.select_feature("Cut", (helper.get_features_count("Cut") - 1), false, 4);
                helper.select_feature("RefAxis", 0, true, 1);

                if (splinedChamfer > 0)
                {
                    helper.select_feature("Chamfer", (helper.get_features_count("Chamfer") - 1), true, 4);
                }

                if (splinedFillet > 0)
                {
                    helper.select_feature("Fillet", (helper.get_features_count("Fillet") - 1), true, 4);
                }

                featureManager.FeatureCircularPattern4(splinedArray, helper.ToRad(360), false, "null", false, true,
                                                       false);
            }

            #endregion
            helper.HidePlanes();
        }
Esempio n. 4
0
        public static void AddConstraintAndDim(ModelDoc2 SketchDoc)
        {
            SketchManager SwSketchMrg = SketchDoc.SketchManager;//获得SketchManager对象

            SketchDoc.Extension.SelectByID2("前视基准面", "PLANE", 0, 0, 0, false, 0, null, 0);
            SwSketchMrg.InsertSketch(true);//进入编辑草图模式
            object[]      ObjRectangle = SwSketchMrg.CreateCenterRectangle(0, 0, 0, 0.075, 0.04, 0);
            SketchSegment SktCircle1   = SwSketchMrg.CreateCircle(-0.0425, 0, 0, -0.03, 0, 0);
            SketchSegment SktCircle2   = SwSketchMrg.CreateCircle(0.0425, 0, 0, 0.03, 0, 0);
            SketchSegment SktCentLine  = SwSketchMrg.CreateCenterLine(0, 0.04, 0, 0, -0.04, 0);

            #region 两个圆心添加水平
            SketchDoc.ClearSelection2(true);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", -0.0425, 0, 0, true, 0, null, 0);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", 0.0425, 0, 0, true, 0, null, 0);
            SketchDoc.SketchAddConstraints("sgHORIZONTALPOINTS2D");
            #endregion

            #region 两个圆心添加对称
            SketchDoc.ClearSelection2(true);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", -0.0425, 0, 0, true, 0, null, 0);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", 0.0425, 0, 0, true, 0, null, 0);
            SktCentLine.Select(true);
            SketchDoc.SketchAddConstraints("sgSYMMETRIC");
            #endregion

            #region 圆心与坐标原点水平
            SketchDoc.ClearSelection2(true);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", -0.0425, 0, 0, true, 0, null, 0);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", 0, 0, 0, true, 0, null, 0);
            SketchDoc.SketchAddConstraints("sgHORIZONTALPOINTS2D");
            #endregion

            #region 添加孔间距尺寸
            SketchDoc.ClearSelection2(true);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", -0.0425, 0, 0, true, 0, null, 0);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", 0.0425, 0, 0, true, 0, null, 0);
            SketchDoc.AddDimension2(0, 0.05, 0);
            #endregion

            #region 两个圆添加相同大小
            SktCircle1.Select(false);
            SktCircle2.Select(true);
            SketchDoc.SketchAddConstraints("sgSAMELENGTH");
            #endregion

            #region 添加圆尺寸
            SktCircle1.Select(false);
            SketchDoc.AddDimension2(-0.02, 0.02, 0);
            #endregion

            #region 添加矩形长
            SketchDoc.Extension.SelectByID2("", "SKETCHSEGMENT", -0.02, 0.04, 0, false, 0, null, 0);
            SketchDoc.AddDimension2(0, 0.07, 0);
            #endregion

            #region 添加矩形高
            SketchDoc.Extension.SelectByID2("", "SKETCHSEGMENT", 0.075, 0, 0, false, 0, null, 0);
            SketchDoc.AddDimension2(0.09, 0, 0);
            #endregion

            SwSketchMrg.InsertSketch(true);//退出编辑草图模式
        }
Esempio n. 5
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();
        }
Esempio n. 6
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();
        }