public void MakeTriangles()
        {
            swSketchManager = modDoc.SketchManager;
            var i = 0;

            foreach (var verts in stlSurfaceVertices)
            {
                swSketchManager.Insert3DSketch(true);
                var p1 = verts[0];
                var p2 = verts[1];
                var p3 = verts[2];
                stlSurfaces[i].l1 = swSketchManager.CreateLine((double)p1.x, (double)p1.y, (double)p1.z, (double)p2.x, (double)p2.y, (double)p2.z) as SketchLine;
                stlSurfaces[i].l2 = swSketchManager.CreateLine((double)p2.x, (double)p2.y, (double)p2.z, (double)p3.x, (double)p3.y, (double)p3.z) as SketchLine;
                stlSurfaces[i].l3 = swSketchManager.CreateLine((double)p3.x, (double)p3.y, (double)p3.z, (double)p1.x, (double)p1.y, (double)p1.z) as SketchLine;
                var plane = modDoc.InsertPlanarRefSurface();
                var name  = "Surface-Plane" + (i + 1).ToString();
                modDoc.Extension.SelectByID(name, "SURFACEBODY", 0, 0, 0, false, 0, null);
                Body2 body = modDoc.ISelectionManager.GetSelectedObject(1);
                body.SetMaterialProperty("Default", "solidworks materials.sldmat", "Pure Gold");
                stlSurfaces[i].b = body;
                i++;
            }
            modDoc.ViewZoomtofit2();
            //swSketchManager.InsertSketch(true);
            Finish();
        }
        public void DrawSwLine(SwLine swLine)
        {
            var p1 = swLine.p1;
            var p2 = swLine.p2;

            swLine.ThisSketchLine = swSketchManager.CreateLine(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z) as SketchLine;
        }
Beispiel #3
0
 public PointD draw(SketchManager sm)
 {
     sketch = sm.CreateLine(start.X, start.Y, start.Z, end.X, end.Y, end.Z);
     if (sketch != null)
     {
         sketch.Select(false);
     }
     return(end);
 }
Beispiel #4
0
        public void DrawShaftBase() //draw base sketch of shaft
        {
            SketchManager sketchManager = SwModel.SketchManager;

            sketchManager.InsertSketch(true);

            GetPoints2D();

            for (int i = 0; i < points_of_base.Count; i++)
            {
                if (i != (points_of_base.Count - 1))
                {
                    sketchManager.CreateLine(points_of_base[i].x, points_of_base[i].y, 0, points_of_base[i + 1].x,
                                             points_of_base[i + 1].y, 0); //draw sketch lines
                }
                else
                {
                    sketchManager.CreateLine(points_of_base[0].x, points_of_base[0].y, 0,
                                             points_of_base[points_of_base.Count - 1].x,
                                             points_of_base[points_of_base.Count - 1].y, 0); //close sketch
                }
            }
        }
        public static SketchSegment[] CreateLinesByPoints(this SketchManager manager, params double[] points)
        {
            manager.InsertSketch(true);

            manager.AddToDB = true;
            var segments = new List <SketchSegment>();

            for (var i = 0; i < points.Length - 3; i += 3)
            {
                segments.Add(manager.CreateLine(points[i], points[i + 1], points[i + 2], points[i + 3], points[i + 4], points[i + 5]));
            }
            manager.AddToDB = false;
            return(segments.ToArray());
        }
Beispiel #6
0
        public static void CreatePlane(ModelDoc2 FeatDoc)
        {
            SketchManager SwSketchMrg = FeatDoc.SketchManager;//获得SketchManager对象

            FeatDoc.Extension.SelectByID2("前视基准面", "PLANE", 0, 0, 0, false, 0, null, 0);
            SwSketchMrg.InsertSketch(true); //进入编辑草图模式
            SwSketchMrg.CreateLine(0, 0, 0, 0.01, 0.01, 0);
            SwSketchMrg.InsertSketch(true); //退出编辑草图模式
            FeatDoc.ClearSelection2(true);
            FeatureManager SwFeatMrg = FeatDoc.FeatureManager;

            FeatDoc.Extension.SelectByID2("Point2@草图1", "EXTSKETCHPOINT", 0, 0, 0, false, 0, null, 0);
            FeatDoc.Extension.SelectByID2("Line1@草图1", "EXTSKETCHSEGMENT", 0, 0, 0, true, 1, null, 0);
            SwFeatMrg.InsertRefPlane(4, 0, 2, 0, 0, 0);
        }
            protected override void Command()
            {
                String TypeSel = "";

                MdlBase.Extension.SelectByID2(Plan.GetNameForSelection(out TypeSel), TypeSel, 0, 0, 0, false, -1, null, 0);

                SketchManager Sk = MdlBase.SketchManager;

                Sk.InsertSketch(true);


                SketchSegment F = Sk.CreateLine(0, 0, 0, -0.064085, 0.171639, 0);

                Sk.InsertSketch(true);

                MdlBase.EditRebuild3();
            }
        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();
        }
Beispiel #9
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();
        }
Beispiel #10
0
        /// <summary>
        /// 这里提供获取当前装配体的 bounding box
        /// </summary>
        /// <returns>返回 LxWxH</returns>
        private string GetActionAssemlbyBOX()
        {
            BoxSize newboxSize = new BoxSize();

            ModelDoc2 swModel = default(ModelDoc2);

            double L = 0;
            double W = 0;
            double H = 0;

            double[] BoxFeatureDblArray = new double[7];

            double[] BoxFaceDblArray = new double[7];

            SketchPoint[]   swSketchPt  = new SketchPoint[9];
            SketchSegment[] swSketchSeg = new SketchSegment[13];

            swModel = (ModelDoc2)iswApp.IActiveDoc2;

            AssemblyDoc assemblyDoc = (AssemblyDoc)swModel;

            BoxFeatureDblArray = (double[])assemblyDoc.GetBox((int)swBoundingBoxOptions_e.swBoundingBoxIncludeRefPlanes);

            L = (BoxFeatureDblArray[3] - BoxFeatureDblArray[0]) * 1000;
            W = (BoxFeatureDblArray[4] - BoxFeatureDblArray[1]) * 1000;
            H = (BoxFeatureDblArray[5] - BoxFeatureDblArray[2]) * 1000;

            List <double> myList = new List <double> {
                L, W, H
            };

            myList.Sort();

            newboxSize.Length = myList[2];
            newboxSize.Weigth = myList[1];
            newboxSize.Height = myList[0];

            bool b = swModel.Extension.SelectByID2("Size", "SKETCH", 0, 0, 0, false, 0, null, 0);

            if (b == false)
            {
                swModel.Insert3DSketch2(true);
                swModel.SetAddToDB(true);
                swModel.SetDisplayWhenAdded(false);

                SketchManager swSketchMgr = default(SketchManager);

                swSketchMgr = (SketchManager)swModel.SketchManager;
                // Draw points at each corner of bounding box
                swSketchPt[0] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[1], BoxFeatureDblArray[5]);
                swSketchPt[1] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[1], BoxFeatureDblArray[5]);
                swSketchPt[2] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[1], BoxFeatureDblArray[2]);
                swSketchPt[3] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[1], BoxFeatureDblArray[2]);
                swSketchPt[4] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[4], BoxFeatureDblArray[5]);
                swSketchPt[5] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[4], BoxFeatureDblArray[5]);
                swSketchPt[6] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[4], BoxFeatureDblArray[2]);
                swSketchPt[7] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[4], BoxFeatureDblArray[2]);
                // Now draw bounding box
                swSketchSeg[0]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[0].X, swSketchPt[0].Y, swSketchPt[0].Z, swSketchPt[1].X, swSketchPt[1].Y, swSketchPt[1].Z);
                swSketchSeg[1]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[1].X, swSketchPt[1].Y, swSketchPt[1].Z, swSketchPt[2].X, swSketchPt[2].Y, swSketchPt[2].Z);
                swSketchSeg[2]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[2].X, swSketchPt[2].Y, swSketchPt[2].Z, swSketchPt[3].X, swSketchPt[3].Y, swSketchPt[3].Z);
                swSketchSeg[3]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[3].X, swSketchPt[3].Y, swSketchPt[3].Z, swSketchPt[0].X, swSketchPt[0].Y, swSketchPt[0].Z);
                swSketchSeg[4]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[0].X, swSketchPt[0].Y, swSketchPt[0].Z, swSketchPt[4].X, swSketchPt[4].Y, swSketchPt[4].Z);
                swSketchSeg[5]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[1].X, swSketchPt[1].Y, swSketchPt[1].Z, swSketchPt[5].X, swSketchPt[5].Y, swSketchPt[5].Z);
                swSketchSeg[6]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[2].X, swSketchPt[2].Y, swSketchPt[2].Z, swSketchPt[6].X, swSketchPt[6].Y, swSketchPt[6].Z);
                swSketchSeg[7]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[3].X, swSketchPt[3].Y, swSketchPt[3].Z, swSketchPt[7].X, swSketchPt[7].Y, swSketchPt[7].Z);
                swSketchSeg[8]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[4].X, swSketchPt[4].Y, swSketchPt[4].Z, swSketchPt[5].X, swSketchPt[5].Y, swSketchPt[5].Z);
                swSketchSeg[9]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[5].X, swSketchPt[5].Y, swSketchPt[5].Z, swSketchPt[6].X, swSketchPt[6].Y, swSketchPt[6].Z);
                swSketchSeg[10] = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[6].X, swSketchPt[6].Y, swSketchPt[6].Z, swSketchPt[7].X, swSketchPt[7].Y, swSketchPt[7].Z);
                swSketchSeg[11] = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[7].X, swSketchPt[7].Y, swSketchPt[7].Z, swSketchPt[4].X, swSketchPt[4].Y, swSketchPt[4].Z);

                swModel.SetDisplayWhenAdded(true);
                swModel.SetAddToDB(false);

                //string actionSketchname = swModel.SketchManager.ActiveSketch.Name;

                swModel.Insert3DSketch2(true);

                swModel.SelectedFeatureProperties(0, 0, 0, 0, 0, 0, 0, true, false, "Size");
                swModel.ClearSelection2(true);

                swModel.Extension.SelectByID2("Size", "SKETCH", 0, 0, 0, false, 0, null, 0);

                swModel.BlankSketch();

                swModel.ClearSelection2(true);
            }

            BoxSize boxSize = new BoxSize();

            boxSize.Length = Math.Round(newboxSize.Length, 0);
            boxSize.Weigth = Math.Round(newboxSize.Weigth, 0);
            boxSize.Height = Math.Round(newboxSize.Height, 0);

            string proText = string.Join("x", boxSize.Length, boxSize.Weigth, boxSize.Height);

            return(proText);
        }
Beispiel #11
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();
        }
        public void GetBoundingBox(out BoxSize boxSize)
        {
            BoxSize newboxSize = new BoxSize();

            ModelDoc2 swModel = default(ModelDoc2);

            double L = 0;
            double W = 0;
            double H = 0;

            double[] BoxFeatureDblArray = new double[7];

            SketchManager swSketchMgr = default(SketchManager);

            SketchPoint[]   swSketchPt  = new SketchPoint[9];
            SketchSegment[] swSketchSeg = new SketchSegment[13];

            swModel = (ModelDoc2)iswApp.IActiveDoc2;

            PartDoc swPart = (PartDoc)swModel;

            double[] BoxFaceDblArray = new double[7];
            BoxFeatureDblArray = (double[])swPart.GetPartBox(true);

            Debug.Print("  Pt1 = " + "(" + BoxFeatureDblArray[0] * 1000.0 + ", " + BoxFeatureDblArray[1] * 1000.0 + ", " + BoxFeatureDblArray[2] * 1000.0 + ") mm");
            Debug.Print("  Pt2 = " + "(" + BoxFeatureDblArray[3] * 1000.0 + ", " + BoxFeatureDblArray[4] * 1000.0 + ", " + BoxFeatureDblArray[5] * 1000.0 + ") mm");
            L = (BoxFeatureDblArray[3] - BoxFeatureDblArray[0]) * 1000;
            W = (BoxFeatureDblArray[4] - BoxFeatureDblArray[1]) * 1000;
            H = (BoxFeatureDblArray[5] - BoxFeatureDblArray[2]) * 1000;

            List <double> myList = new List <double> {
                L, W, H
            };

            myList.Sort();

            newboxSize.Length = myList[2];
            newboxSize.Weigth = myList[1];
            newboxSize.Height = myList[0];

            swModel.Insert3DSketch2(true);
            swModel.SetAddToDB(true);
            swModel.SetDisplayWhenAdded(false);

            swSketchMgr = (SketchManager)swModel.SketchManager;
            // Draw points at each corner of bounding box
            swSketchPt[0] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[1], BoxFeatureDblArray[5]);
            swSketchPt[1] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[1], BoxFeatureDblArray[5]);
            swSketchPt[2] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[1], BoxFeatureDblArray[2]);
            swSketchPt[3] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[1], BoxFeatureDblArray[2]);
            swSketchPt[4] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[4], BoxFeatureDblArray[5]);
            swSketchPt[5] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[4], BoxFeatureDblArray[5]);
            swSketchPt[6] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[4], BoxFeatureDblArray[2]);
            swSketchPt[7] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[4], BoxFeatureDblArray[2]);
            // Now draw bounding box
            swSketchSeg[0]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[0].X, swSketchPt[0].Y, swSketchPt[0].Z, swSketchPt[1].X, swSketchPt[1].Y, swSketchPt[1].Z);
            swSketchSeg[1]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[1].X, swSketchPt[1].Y, swSketchPt[1].Z, swSketchPt[2].X, swSketchPt[2].Y, swSketchPt[2].Z);
            swSketchSeg[2]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[2].X, swSketchPt[2].Y, swSketchPt[2].Z, swSketchPt[3].X, swSketchPt[3].Y, swSketchPt[3].Z);
            swSketchSeg[3]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[3].X, swSketchPt[3].Y, swSketchPt[3].Z, swSketchPt[0].X, swSketchPt[0].Y, swSketchPt[0].Z);
            swSketchSeg[4]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[0].X, swSketchPt[0].Y, swSketchPt[0].Z, swSketchPt[4].X, swSketchPt[4].Y, swSketchPt[4].Z);
            swSketchSeg[5]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[1].X, swSketchPt[1].Y, swSketchPt[1].Z, swSketchPt[5].X, swSketchPt[5].Y, swSketchPt[5].Z);
            swSketchSeg[6]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[2].X, swSketchPt[2].Y, swSketchPt[2].Z, swSketchPt[6].X, swSketchPt[6].Y, swSketchPt[6].Z);
            swSketchSeg[7]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[3].X, swSketchPt[3].Y, swSketchPt[3].Z, swSketchPt[7].X, swSketchPt[7].Y, swSketchPt[7].Z);
            swSketchSeg[8]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[4].X, swSketchPt[4].Y, swSketchPt[4].Z, swSketchPt[5].X, swSketchPt[5].Y, swSketchPt[5].Z);
            swSketchSeg[9]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[5].X, swSketchPt[5].Y, swSketchPt[5].Z, swSketchPt[6].X, swSketchPt[6].Y, swSketchPt[6].Z);
            swSketchSeg[10] = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[6].X, swSketchPt[6].Y, swSketchPt[6].Z, swSketchPt[7].X, swSketchPt[7].Y, swSketchPt[7].Z);
            swSketchSeg[11] = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[7].X, swSketchPt[7].Y, swSketchPt[7].Z, swSketchPt[4].X, swSketchPt[4].Y, swSketchPt[4].Z);

            swModel.SetDisplayWhenAdded(true);
            swModel.SetAddToDB(false);

            //string actionSketchname = swModel.SketchManager.ActiveSketch.Name;

            swModel.Insert3DSketch2(true);

            swModel.SelectedFeatureProperties(0, 0, 0, 0, 0, 0, 0, true, false, "Size");

            swModel.ClearSelection2(true);

            boxSize.Length = newboxSize.Length;
            boxSize.Weigth = newboxSize.Weigth;
            boxSize.Height = newboxSize.Height;
            //  swModel.Extension.CustomPropertyManager[""].Delete("尺寸");

            swModel.Extension.CustomPropertyManager[""].Add3("尺寸", 30, "aaaa", 1);

            // swModel.AddCustomInfo("尺寸","Text", boxSize.Length.ToString());

            swModel.Save();
        }
Beispiel #13
0
        public void MakeBolid(AssemblyParameters parameters)
        {
            #region parameters
            lengthOfMainPart = 800 / 100.0;
            heightOfMainPart = 80 / 100.0;
            widthOfMainPart  = 150 / 100.0;
            #endregion
            createPart();
            var            Part = swDoc;
            SketchSegment  segment;
            SketchManager  sketchManager  = Part.SketchManager;
            FeatureManager featureManager = Part.FeatureManager;
            bool           boolstatus;
            boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            Part.SketchManager.InsertSketch(true);
            segment = sketchManager.CreateLine(0, 0, 0, -lengthOfMainPart, 0, 0);
            segment = sketchManager.CreateLine(-lengthOfMainPart, 0, 0, -lengthOfMainPart, heightOfMainPart, 0);
            segment = sketchManager.CreateLine(-lengthOfMainPart, heightOfMainPart, 0, 0, heightOfMainPart, 0);
            segment = sketchManager.CreateLine(0, heightOfMainPart, 0, 0, 0, 0);
            Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 0, 0, 0, false, 0, null, 0);
            var extrusion = featureManager.FeatureExtrusion2(true, false, false, 6, 0, widthOfMainPart, 0.01, false, false, false, false, 1.74532925199433E-02, 1.74532925199433E-02, false, false, false, false, true, true, true, 0, 0, false);
            sketchManager.InsertSketch(true);

            Part.ClearSelection();

            var firstVal  = -widthOfMainPart / 2.0;
            var secondVal = widthOfMainPart / 2.0;
            sketchManager.InsertSketch(false);
            Part.Extension.SelectByID2("", "EDGE", 0, 0.04, firstVal, true, 1, null, 1);
            Part.Extension.SelectByID2("", "EDGE", 0, 0.04, secondVal, true, 1, null, 1);
            Part.FeatureManager.InsertFeatureChamfer(4, 2, 2.5, 0, 0.6, 0, 0, 0);

            Part.ClearSelection2(true);
            Part.Extension.SelectByID2("", "EDGE", -1.60359675146537E-03, 0.468692650695658, -0.161665083159619, false, 1, null, 0);
            Part.Extension.SelectByID2("", "EDGE", 1.24126468108443E-05, 0.432705387515739, 0.150090293621304, true, 1, null, 0);
            Part.FeatureManager.FeatureFillet3(195, 0.2, 0.02, 0, 0, 0, 0, (0), (0), (0), (0), (0), (0), (0));


            Part.ClearSelection2(true);
            //sketchManager.InsertSketch(false);
            Part.Extension.SelectByID2("", "EDGE", -2.50145207253843, 0.409842119252346, 0.759927555199994, true, 1, null, 0);
            Part.Extension.SelectByID2("", "EDGE", -2.50145207253843, 0.409842119252346, 0.759927555199994, false, 1, null, 0);

            Part.FeatureManager.FeatureFillet3(195, 3, 3, 0, 0, 0, 0, 0, null, null, null, null, null, null);

            Part.ClearSelection2(true);
            //sketchManager.InsertSketch(false);
            Part.Extension.SelectByID2("", "EDGE", -9.92190741726517E-04, 0.423385979796308, 0.156783427202669, false, 1, null, 0);
            Part.Extension.SelectByID2("", "EDGE", -3.0946920736028E-03, 0.461205360135011, -0.128842154520996, true, 1, null, 0);
            Part.FeatureManager.FeatureFillet3(195, 0.2, 3, 0, 0, 0, 0, 0, null, null, null, null, null, null);

            //Start creating bottom part
            Part.Extension.SelectByID2("Top Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            sketchManager.InsertSketch(true);
            Part.ClearSelection2(true);
            double distanceBetweenMainPartAndWheel        = 125.0 / 100.0;
            double widthOFDetailThatLinksMainPartAndWheel = 60.0 / 100.0;
            Part.SketchManager.CreateLine(-lengthOfMainPart, -widthOfMainPart / 2, 0, -lengthOfMainPart, -widthOfMainPart / 2 - 125 / 100.0, 0);
            Part.SketchManager.CreateLine(-lengthOfMainPart, -widthOfMainPart / 2 - 125 / 100.0, 0, -lengthOfMainPart + widthOFDetailThatLinksMainPartAndWheel, -widthOfMainPart / 2 - distanceBetweenMainPartAndWheel, 0);
            Part.SketchManager.CreateLine(-lengthOfMainPart + 60 / 100.0, -widthOfMainPart / 2 - 125.0 / 100.0, 0, -lengthOfMainPart + widthOFDetailThatLinksMainPartAndWheel, (-widthOfMainPart / 2 - 125 / 100.0) + 42.57247318 / 100.0, 0);
            double x1ForArc1 = -lengthOfMainPart + 122.31294971 / 100.0;
            double y1ForArc1 = -widthOfMainPart / 2.0;
            double z1ForArc1 = 0.0;
            double x2ForArc1 = x1ForArc1 + 106.29290168 / 100.0;
            double y2ForArc1 = y1ForArc1 - 226.27818952 / 100.0;
            double z2ForArc1 = 0.0;
            double x3ForArc1 = -lengthOfMainPart + 60.0 / 100.0;
            double y3ForArc1 = -widthOfMainPart / 2.0 + (-125.0 + 42.57247318) / 100.0;
            double z3ForArc1 = 0.0;
            // Part.SketchManager.Create3PointArc(x1ForArc, y1ForArc, z1ForArc, x2ForArc, y2ForArc, z2ForArc, x3ForArc, y3ForArc, z3ForArc);
            Part.SketchManager.Create3PointArc(x1ForArc1, y1ForArc1, 0.0, -7.4, -1.574275, 0.0, -7.022504, -1.175317, 0.0);
            Part.SetPickMode();
            Part.ClearSelection2(true);
            Part.SketchManager.CreateLine(-6.776871, -widthOfMainPart / 2.0, 0, -7.4, -widthOfMainPart / 2.0, 0);
            Part.SketchManager.CreateLine(-7.4, -widthOfMainPart / 2.0, 0, -7.4, -1.273082, 0);
            Part.SketchManager.CreateLine(-7.4, -widthOfMainPart / 2.0, 0, -lengthOfMainPart, -widthOfMainPart / 2.0, 0);
            Part.SketchManager.Create3PointArc(-7.017346, -widthOfMainPart / 2.0, 0, -7.4, -1.273082, 0, -7.17822, -1.06516, 0);
            Part.SetPickMode();
            Part.ClearSelection2(true);

            //Wing
            Part.SketchManager.CreateLine(x1ForArc1, y1ForArc1, z1ForArc1, x1ForArc1 + 107.68705029 / 100.0, y1ForArc1, z1ForArc1);
            Part.SketchManager.CreateLine(x1ForArc1 + 107.68705029 / 100.0, y1ForArc1, z1ForArc1, x1ForArc1 + (107.68705029 + 70.0) / 100.0, y1ForArc1 - 40.0 / 100, z1ForArc1);
            Part.SketchManager.CreateLine(x1ForArc1 + (107.68705029 + 70.0) / 100.0, y1ForArc1 - 40.0 / 100, z1ForArc1, x1ForArc1 + (107.68705029 + 70.0) / 100.0, y1ForArc1 - 90.0 / 100, z1ForArc1);
            double x1ForArc3  = Math.Round((x1ForArc1 + (107.68705029 + 70.0 + 240.0) / 100.0), 1);
            double y1ForArc3  = Math.Round(y1ForArc1 - (90.0 - 23.32770382) / 100.00, 1);
            double z1FForArc3 = 0.0;
            //Part.SketchManager.CreateLine(x1ForArc1 + (107.68705029 + 70.0) / 100.0, y1ForArc1 - 90.0 / 100, z1ForArc1, x1ForArc3, y1ForArc3, z1FForArc3);
            Part.SketchManager.Create3PointArc(x1ForArc3, y1ForArc3, z1FForArc3, -5, -1.65, 0, -3.988716, -1.938586, 0);
            double x1ForArc4 = x1ForArc3 + 110.0 / 100;
            double y1ForArc4 = y1ForArc3 + 78.15763134 / 100.0;
            double z1ForArc4 = 0.0;
            //Part.SketchManager.CreateLine(x1ForArc3, y1ForArc3, z1FForArc3, x1ForArc4, y1ForArc4, z1ForArc4);
            Part.SketchManager.Create3PointArc(x1ForArc4, y1ForArc4, z1ForArc4, x1ForArc3, y1ForArc3, z1FForArc3, -2.114926, -0.999068, 0);
            double x1ForArc5 = x1ForArc4 + 70.0 / 100.0;
            double y1ForArc5 = y1ForArc4 - 130.82992752 / 100.0;
            double z1ForArc5 = 0.0;
            //Part.SketchManager.CreateLine(x1ForArc4, y1ForArc4, z1ForArc4, x1ForArc5, y1ForArc5, z1ForArc5);
            Part.SketchManager.Create3PointArc(x1ForArc5, y1ForArc5, z1ForArc5, x1ForArc4, y1ForArc4, z1ForArc4, -1.047119, -1.215711, 0);
            double x2ForArc6 = x1ForArc4 + 13.58 / 100.0;
            double y2ForArc6 = y1ForArc4 + 7.03 / 100.0;
            double z2ForArc6 = 0.0;
            double x1ForArc6 = x1ForArc5;
            double y1ForArc6 = y1ForArc5 + 43.1674111 / 100.0;
            double z1ForArc6 = 0.0;
            //Part.SketchManager.CreateLine(x1ForArc6, y1ForArc6, z1ForArc6, x2ForArc6, y2ForArc6, z2ForArc6);
            Part.SketchManager.Create3PointArc(x1ForArc6, y1ForArc6, z1ForArc6, x2ForArc6, y2ForArc6, z2ForArc6, -1.004515, -0.966642, 0);
            double x2ForLine = x1ForArc6;
            double y2ForLine = y1ForArc6 + 110.0 / 100.0;
            double z2ForLine = 0.0;
            Part.SketchManager.CreateLine(x1ForArc6, y1ForArc6, z1ForArc6, x2ForLine, y2ForLine, z2ForLine);
            Part.SketchManager.Create3PointArc(x2ForArc6, y2ForArc6, z2ForArc6, x2ForLine, y2ForLine, z2ForLine, -1.097502, -0.462248, 0);
            double x2ForBackWing1 = 0;
            double y2ForBackWing1 = y1ForArc5;
            double z2ForBackWing1 = 0;
            Part.SketchManager.CreateLine(x1ForArc5, y1ForArc5, z1ForArc5, x2ForBackWing1, y2ForBackWing1, z2ForBackWing1);
            double halfOFLengthOFBackWing = 192.904 / 100.0;
            double x2ForBackWing2         = 0;
            double y2ForBackWIng2         = y2ForBackWing1 + halfOFLengthOFBackWing;
            double z2ForBackWing2         = 0;
            Part.SketchManager.CreateLine(x2ForBackWing1, y2ForBackWing1, z2ForBackWing1, x2ForBackWing2, y2ForBackWIng2, z2ForBackWing2);
            double x2ForBackWing3 = 0;
            double y2ForBackWing3 = y2ForBackWIng2 + halfOFLengthOFBackWing;
            double z2ForBackWIng3 = 0;
            Part.SketchManager.CreateLine(x2ForBackWing2, y2ForBackWIng2, z2ForBackWing2, x2ForBackWing3, y2ForBackWing3, z2ForBackWIng3);
            double x2ForBackWing4 = x1ForArc5;
            double y2ForBackWing4 = y2ForBackWing3;
            double z2ForBackWing4 = 0;
            Part.SketchManager.CreateLine(x2ForBackWing3, y2ForBackWing3, z2ForBackWIng3, x2ForBackWing4, y2ForBackWing4, z2ForBackWing4);
            //The same but another side of bolide
            double x2ForCorpseToWheelLine1 = -lengthOfMainPart;
            double y2ForCorpseToWheelLine1 = widthOfMainPart / 2 + distanceBetweenMainPartAndWheel;
            double z2ForCorpseToWheelLine1 = 0.0;
            Part.SketchManager.CreateLine(-lengthOfMainPart, widthOfMainPart / 2, 0, x2ForCorpseToWheelLine1, y2ForCorpseToWheelLine1, z2ForCorpseToWheelLine1);
            double x2ForCorpseToWheelLine2 = x2ForCorpseToWheelLine1 + widthOFDetailThatLinksMainPartAndWheel;
            double y2ForCoprseToWheelLine2 = y2ForCorpseToWheelLine1;
            double z2ForCoprseToWheelLine2 = z2ForCorpseToWheelLine1;
            Part.SketchManager.CreateLine(x2ForCorpseToWheelLine1, y2ForCorpseToWheelLine1, z2ForCorpseToWheelLine1, x2ForCorpseToWheelLine2, y2ForCoprseToWheelLine2, z2ForCoprseToWheelLine2);
            double x2ForCorpseToWheelLine3 = x2ForCorpseToWheelLine2;
            double y2ForCoprseToWheelLine3 = y2ForCorpseToWheelLine1 - 42.57247318 / 100.0;
            double z2ForCoprseToWheelLine3 = z2ForCoprseToWheelLine2;
            Part.SketchManager.CreateLine(x2ForCorpseToWheelLine2, y2ForCoprseToWheelLine2, z2ForCoprseToWheelLine2, x2ForCorpseToWheelLine3, y2ForCoprseToWheelLine3, z2ForCoprseToWheelLine3);
            double x1ForCorpseToWheelArc1 = x1ForArc1;
            double y1ForCorpseToWheelArc1 = -y1ForArc1;
            double z1ForCorpseToWheelArc1 = 0;
            Part.SketchManager.Create3PointArc(x2ForCorpseToWheelLine3, y2ForCoprseToWheelLine3, z2ForCoprseToWheelLine3, x1ForCorpseToWheelArc1, y1ForCorpseToWheelArc1, z1ForCorpseToWheelArc1, -7.02437, 1.177213, 0);
            double x2ForCorpseToWheelLine4 = -lengthOfMainPart + 60.0 / 100.0;
            double y2ForCorpseToWheelLine4 = widthOfMainPart / 2.0;
            double z2ForCorpseToWheelLine4 = 0;
            Part.SketchManager.CreateLine(x1ForCorpseToWheelArc1, y1ForCorpseToWheelArc1, z1ForCorpseToWheelArc1, x2ForCorpseToWheelLine4, y2ForCorpseToWheelLine4, z2ForCorpseToWheelLine4);
            double x2ForCoprseToWheelLine5 = x2ForCorpseToWheelLine4;
            double y2ForCorpseToWheelLine5 = widthOfMainPart / 2 + 52.3082 / 100.0;
            double z2ForCorpseToWheelLine5 = 0;
            Part.SketchManager.CreateLine(x2ForCorpseToWheelLine4, y2ForCorpseToWheelLine4, z2ForCorpseToWheelLine4, x2ForCoprseToWheelLine5, y2ForCorpseToWheelLine5, z2ForCorpseToWheelLine5);
            double x1ForCorpseToWheelArc2 = -lengthOfMainPart + 98.2654 / 100.0;
            double y1ForCorpseToWheelArc2 = y1ForCorpseToWheelArc1;
            double z1ForCorpseToWheelArc2 = z1ForCorpseToWheelArc1;
            Part.SketchManager.CreateLine(x2ForCorpseToWheelLine4, y2ForCorpseToWheelLine4, z2ForCorpseToWheelLine4, -lengthOfMainPart, widthOfMainPart / 2.0, z2ForCoprseToWheelLine2);
            Part.SketchManager.Create3PointArc(x2ForCoprseToWheelLine5, y2ForCorpseToWheelLine5, z2ForCorpseToWheelLine5, x1ForCorpseToWheelArc2, y1ForCorpseToWheelArc2, z1ForCorpseToWheelArc2, -7.169033, 0.997835, 0);
            double x2ForCorpseLine1 = x1ForArc1 + 107.68705029 / 100.0;
            double y2ForCorpseLine1 = widthOfMainPart / 2.0;
            double z2ForCorpseLine1 = 0;
            Part.SketchManager.CreateLine(x1ForCorpseToWheelArc2, y1ForCorpseToWheelArc2, z1ForCorpseToWheelArc2, x2ForCorpseLine1, y2ForCorpseLine1, z2ForCorpseLine1);
            double x2ForCorpseLine2 = x2ForCorpseLine1 + 70.0 / 100.0;
            double y2ForCorpseLine2 = y2ForCorpseLine1 + 40.0 / 100.0;
            double z2ForCorpseLine2 = 0.0;
            Part.SketchManager.CreateLine(x2ForCorpseLine1, y2ForCorpseLine1, z2ForCorpseLine1, x2ForCorpseLine2, y2ForCorpseLine2, z2ForCorpseLine2);
            double x2ForCorpseLine3 = x2ForCorpseLine2;
            double y2ForCorpseLine3 = y2ForCorpseLine2 + 50.0 / 100.0;
            double z2ForCorpseLIne3 = 0.0;
            Part.SketchManager.CreateLine(x2ForCorpseLine2, y2ForCorpseLine2, z2ForCorpseLine2, x2ForCorpseLine3, y2ForCorpseLine3, z2ForCorpseLIne3);
            double x2ForCorpseArc1 = x1ForArc3;
            double y2ForCorpseArc1 = -y1ForArc3;
            double z2ForCorpseArc1 = z1FForArc3;
            Part.SketchManager.Create3PointArc(x2ForCorpseLine3, y2ForCorpseLine3, z2ForCorpseLIne3, x2ForCorpseArc1, y2ForCorpseArc1, z2ForCorpseArc1, -3.563352, 1.899428, 0);
            double x2ForCorpseArc2 = x1ForArc4;
            double y2ForCorpseArc2 = -y1ForArc4;
            double z2ForCorpseArc2 = z1ForArc4;
            Part.SketchManager.Create3PointArc(x2ForCorpseArc1, y2ForCorpseArc1, z2ForCorpseArc1, x2ForCorpseArc2, y2ForCorpseArc2, z2ForCorpseArc2, -2.025267, 0.941125, 0);
            double x2ForCorpseArc3 = x2ForBackWing4;
            double y2ForCorpseArc3 = y2ForBackWing4;
            double z2ForCorpseArc3 = z2ForBackWing4;
            Part.SketchManager.Create3PointArc(x2ForCorpseArc2, y2ForCorpseArc2, z2ForCorpseArc2, x2ForCorpseArc3, y2ForCorpseArc3, z2ForCorpseArc3, -1.158409, 1.11352, 0);
            double x2ForCorpseArc4 = x2ForArc6;
            double y2ForCorpseArc4 = -y2ForArc6;
            double z2ForCorpseArc4 = z2ForArc6;
            double x1ForCorpseArc4 = x1ForArc6;
            double y1ForCorpseArc4 = -y1ForArc6;
            double z1ForCorpseArc4 = z1ForArc6;
            Part.SketchManager.Create3PointArc(x1ForCorpseArc4, y1ForCorpseArc4, z1ForCorpseArc4, x2ForCorpseArc4, y2ForCorpseArc4, z2ForCorpseArc4, -1.058286, 0.989618, 0);
            double x2ForCorpseLine4 = x2ForLine;
            double y2ForCorpseLine4 = -y2ForLine;
            double z2ForCorpseLine4 = z2ForLine;
            Part.SketchManager.CreateLine(x2ForCorpseArc4, y2ForCorpseArc4, z2ForCorpseArc4, x2ForCorpseLine4, y2ForCorpseLine4, z2ForCorpseLine4);
            Part.SketchManager.CreateLine(x1ForCorpseArc4, y1ForCorpseArc4, z1ForCorpseArc4, x2ForCorpseLine4, y2ForCorpseLine4, z2ForCorpseLine4);
            //close needed counturs
            Part.SketchManager.CreateLine(-8, 0.75, 0, -2.5, 0.75, 0);
            Part.SketchManager.CreateLine(-2.5, 0.75, 0, 0, 0.15, 0);
            Part.SketchManager.CreateLine(0, 0.15, 0, 0, 0.007679, 0);
            Part.SketchManager.CreateLine(-0.042941, -0.116145, 0, -0.153325, -0.186798, 0);
            Part.SketchManager.CreateLine(-0.153325, -0.186798, 0, -2.502459, -0.729218, 0);
            Part.SketchManager.CreateLine(-2.502459, -0.729218, 0, -2.85496, -0.75, 0);
            Part.SketchManager.CreateLine(-2.85496, -0.75, 0, -5.7, -0.75, 0);
            Part.SketchManager.CreateLine(-8, -0.75, 0, -8, 0.75, 0);

            Thread.Sleep(100);
            Part.SetPickMode();
            Part.SelectionManager.EnableContourSelection = true;
            Part.Extension.SelectByID2("Sketch2", "SKETCHREGION", -3.9841093791155, 1.92165359018481E-02, -1.11273181579067, true, 4, null, 0);

            Part.Extension.SelectByID2("Sketch2", "SKETCHREGION", -6.90010975425287, 1.05342333640838, 1.97602960993305, true, 0, null, 0);
            Part.Extension.SelectByID2("Sketch2", "SKETCHREGION", -6.21591444832203, 2.1019999157831, -0.191076915736342, true, 0, null, 0);
            Part.Extension.SelectByID2("Sketch2", "SKETCHREGION", -4.3896245678695, -0.268919542014907, 1.3356196563234, true, 0, null, 0);
            Part.FeatureManager.FeatureExtrusion2(true, false, true, 0, 0, 0.4, 0.4, false, false, false, false, 1.74532925199433E-02, 1.74532925199433E-02, false, false, false, false, true, true, true, 0, 0, false);
            Part.SelectionManager.EnableContourSelection = false;
            frontLoft();
            driverSit();
            backWing(parameters);
            frontWing(parameters);
            partEnhancing();
            bool saved = swDoc.SaveAs("C:\\Users\\jungl\\Documents\\bilide2\\mainPart.sldprt");
            if (!saved)
            {
                MessageBox.Show("Solidworks не зміг зберегти корпус боліда. Потрібно перезапустити Solidworks");
            }
        }
Beispiel #14
0
 public void MakeTriangles()
 {
     swSketchManager = modDoc.SketchManager;
     var i = 0;
     foreach (var verts in stlSurfaceVertices)
     {
         swSketchManager.Insert3DSketch(true);
         var p1 = verts[0];
         var p2 = verts[1];
         var p3 = verts[2];
         stlSurfaces[i].l1 = swSketchManager.CreateLine((double)p1.x, (double)p1.y, (double)p1.z, (double)p2.x, (double)p2.y, (double)p2.z) as SketchLine;
         stlSurfaces[i].l2 = swSketchManager.CreateLine((double)p2.x, (double)p2.y, (double)p2.z, (double)p3.x, (double)p3.y, (double)p3.z) as SketchLine;
         stlSurfaces[i].l3 = swSketchManager.CreateLine((double)p3.x, (double)p3.y, (double)p3.z, (double)p1.x, (double)p1.y, (double)p1.z) as SketchLine;
         var plane = modDoc.InsertPlanarRefSurface();
         var name = "Surface-Plane" + (i + 1).ToString();
         modDoc.Extension.SelectByID(name, "SURFACEBODY", 0, 0, 0, false, 0, null);
         Body2 body = modDoc.ISelectionManager.GetSelectedObject(1);
         body.SetMaterialProperty("Default", "solidworks materials.sldmat", "Pure Gold");
         stlSurfaces[i].b = body;
         i++;
     }
     modDoc.ViewZoomtofit2();
     //swSketchManager.InsertSketch(true);
     Finish();
 }
Beispiel #15
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();
        }