Esempio n. 1
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();
        }
Esempio n. 2
0
        /// <summary>
        /// Создание резьбовой части
        /// </summary>
        ///

        public static void CreateCarving(double carvingLength, SldWorks swApp, ModelDoc2 swModel, List <string> detailNames, double pitchSize, double carvingRadius, double electrodeLength, string pathName)
        {
            var helixRevolution = 12;
            var sidesOfPolygon  = 3;

            string modelName = pathName + "Резьба.sldprt";

            swApp.NewPart();
            swModel = swApp.IActiveDoc2;

            swModel.Extension.SelectByID2("Спереди", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.SketchManager.CreateCircleByRadius(0, 0, 0, carvingRadius);
            swModel.Extension.SelectByID2("Arc1", "SKETCHSEGMENT", 0, 0, 0, false, 0, null, 0);
            swModel.FeatureManager.FeatureExtrusion2(true, false, false, 0, 0, carvingLength, 0, false, false, false, false, _draftAngle, _draftAngle, false, false, false, false, true, true, true, 0, 0, false);

            // Создание спирали
            swModel.Extension.SelectByID2("", "FACE", 0, 0, carvingLength, false, 0, null, 0);
            swModel.SketchManager.CreateCircleByRadius(0, 0, 0, carvingRadius);
            swModel.InsertHelix(true, true, false, false, 0, carvingLength, pitchSize, helixRevolution, 0, 0);

            // Создание треугольника для выреза резьбы
            swModel.Extension.SelectByID2("Сверху", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.SketchManager.CreatePolygon(carvingRadius, -carvingLength - 0.001, 0, carvingRadius - 0.0008, -carvingLength - 0.001, 0, sidesOfPolygon, false);
            swModel.ClearSelection2(true);

            // Выполнение операции "вырезать по направлению"
            swModel.Extension.SelectByID2("Эскиз3", "SKETCH", 0, 0, 0, true, 0, null, 0);
            swModel.Extension.SelectByID2("Спираль1", "REFERENCECURVES", 0, 0, 0, true, 0, null, 0);
            swModel.FeatureManager.InsertCutSwept4(false, true, 0, false, false, 0, 0, false, 0, 0, 0, 0, true, true, 0, true, true, true, false);
            swModel.ClearSelection2(true);

            swModel.Extension.SelectByID2("Спереди", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.FeatureManager.InsertRefPlane(_firstConstraint, carvingLength, 0, 0, 0, 0);
            swModel.ClearSelection2(true);

            swModel.Extension.SelectByID2("Плоскость4", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.SketchManager.CreateCircleByRadius(0, 0, 0, carvingRadius);
            swModel.FeatureManager.FeatureExtrusion2(true, false, false, 0, 0, _distanceExtrusion, 0, false, false, false, false, _draftAngle, _draftAngle, false, false, false, false, true, true, true, 0, 0, false);

            // Вырез под электрод
            swModel.Extension.SelectByID2("Спереди", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.SketchManager.CreateCircleByRadius(0, 0, 0, carvingRadius - _distanceExtrusion);
            swModel.FeatureManager.FeatureCut3(true, false, true, 0, 0, 0.06, 0.06, false, false, false, false, 0.02, 0.02, false, false, false, false, false, true, true, true, true, false, 0, 0, false);

            swModel.Extension.SelectByID2("Спереди", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.SketchManager.CreateCircleByRadius(0, 0, 0, 0.002);
            swModel.FeatureManager.FeatureExtrusion2(true, false, false, 0, 0, carvingLength + 0.003, 0, false, false, false, false, _draftAngle, _draftAngle, false, false, false, false, true, true, true, 0, 0, false);

            swModel.Extension.SelectByID2("", "FACE", 0, 0, carvingLength + 0.003, false, 0, null, 0);
            swModel.SketchManager.CreateCircleByRadius(0, 0, 0, 0.001);
            swModel.FeatureManager.FeatureExtrusion2(true, false, false, 0, 0, electrodeLength, 0, false, false, false, false, _draftAngle, _draftAngle, false, false, false, false, true, true, true, 0, 0, false);

            // Создание второго электрода
            swModel.Extension.SelectByID2("Справа", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.FeatureManager.InsertRefPlane(_firstConstraint, 0.001, 0, 0, 0, 0);

            swModel.Extension.SelectByID2("Сверху", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.FeatureManager.InsertRefPlane(_firstConstraint, 0, 0, 0, 0, 0);

            swModel.Extension.SelectByID2("Плоскость5", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.SketchManager.CreateCornerRectangle(-carvingLength - 0.008, 0.001, 0, -carvingLength - 0.007, -0.001, 0);
            swModel.SketchManager.InsertSketch(true);

            swModel.Extension.SelectByID2("Плоскость6", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.SketchManager.Create3PointArc(-0.0038, -carvingLength - _distanceExtrusion, 0, 0.001, -carvingLength - 0.007, 0, -0.004, -carvingLength - 0.003, 0);
            swModel.SketchManager.InsertSketch(true);

            swModel.Extension.SelectByID2("Эскиз8", "SKETCH", 0, 0, 0, true, 0, null, 0);
            swModel.Extension.SelectByID2("Эскиз9", "SKETCH", 0, 0, 0, true, 0, null, 0);

            swModel.FeatureManager.InsertProtrusionSwept3(false, false, 0, false, false, 0, 0, false, 0, 0, 0, 0, true, true, true, 0, false);

            swModel.SaveAs(modelName);
            detailNames.Add(modelName);
        }