Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            double r1 = Convert.ToDouble(textBox1.Text) / 1e3;
            double r2 = Convert.ToDouble(textBox2.Text) / 1e3;
            double h  = Convert.ToDouble(textBox3.Text) / 1e3;

            SldWorks sw = new SldWorks();

            sw.Visible = true;
            PartDoc   Part  = sw.NewPart();
            ModelDoc2 Model = sw.ActiveDoc;

            Model.InsertSketch2(true);

            Model.SelectByID("Спереди", "PLANE", 0, 0, 0); // Выделяем плоскость на которой будем рисовать

            Model.InsertSketch2(true);                     // Добавляем эскиз
            Model.CreateCircleByRadius2(0, 0, 0, r1);      // рисуем окружность 1
            Model.CreateCircleByRadius2(0, 0, 0, r2);      // рисуем окружность 2
            Model.FeatureBoss2(true, false, false,
                               0, 0, h, 0, true, false, true, false,
                               0, 0, false, false, false, false);  // Бобышка - вытянуть

            /*Model.CreateEllipse2(0, 0, 0, 1, 0, 0, 0, 2, 0);
             * Model.FeatureBoss2(true, false, false, 0, 0, 1, 0, true, false, true, false, 0.5, 0, false, false, false, false);*/
        }
Exemple #2
0
        public override void CreatePart()
        {
            swApp = SolidWorksSingleton.GetApplication();
            DocumentManager.CreateNewPartDoc();
            swModel = (ModelDoc2)swApp.ActiveDoc;

            swFeature      = swModel.FeatureByPositionReverse(3);
            swFeature.Name = "Front";

            swModel.Extension.SelectByID2("Front", "PLANE", 0, 0, 0, false, 0, null, 0);

            swModel.InsertSketch2(true);

            swModel.CreateCircleByRadius2(0, 0, 0, InsideDiameter / 2);
            swModel.CreateCircleByRadius2(0, 0, 0, OutsideDiameter / 2);

            swModel.InsertSketch2(true);

            swFeature = swModel.FeatureManager.FeatureExtrusion3(true, false, false, 0, 0, Lenght, 0, false, false, false, false, 0, 0, false, false, false, false, false, false, false, 0, 0, false);

            BasicOpertations.ChangeEntityName("FACE", MateOutsideFace, OutsideDiameter / 2, 0, Lenght / 2);

            double dim = (OutsideDiameter - InsideDiameter) / 4;

            BasicOpertations.ChangeEntityName("FACE", MateBase, (InsideDiameter / 2) + dim, 0, 0);

            DocumentManager.Save(TargetFolder, FileName, DocumentManager.sw_DocType.part);
        }
Exemple #3
0
        private void b_cut_Click(object sender, EventArgs e)
        {
            if (double.TryParse(tb_radius.Text, out radius) == false)
            {
                MessageBox.Show("Fehlerhafte Eingabe!");
                return;
            }
            ModelDoc2 swModel = swApp.ActiveDoc;

            swModel.Extension.SelectByID2("", "FACE", 0.5 * breite, hoehe, -0.5 * laenge, false, 1, null, 0);

            swModel.InsertSketch2(true);

            Sketch swSketch = (Sketch)swModel.GetActiveSketch2();

            swModel.CreateCircleByRadius2(0.5 * breite, 0.5 * laenge, 0, radius);
            swModel.FeatureManager.FeatureCut3(true, false, false, 1, 1, 0.0, 0.0, false, false, false, false, 0, 0, false,
                                               false, false, false, false, true, true, false, false, false, 0, 0.0, false);

            swModel.SaveAsSilent("C:\\temp\\Quader_L_" + tb_laenge.Text + "_B_" +
                                 tb_breite.Text + "_H_" + tb_hoehe.Text + "_cut_R_" + tb_radius.Text + ".SLDPRT", true);
        }
        //
        private void b_create_Click(object sender, EventArgs e)
        {
            // Deklarieren der benötigten Variablen
            double a0x, a0y, lh, rg, PMax, PsiMax;

            // Auslesen der eingegebenen Werte im Formular
            if (double.TryParse(label_1.Text, out a0x) == false ||
                double.TryParse(label_2.Text, out a0y) == false ||
                double.TryParse(label_3.Text, out lh) == false ||
                double.TryParse(label_4.Text, out rg) == false ||
                double.TryParse(tb_pmax.Text, out PMax) == false ||
                double.TryParse(label_6.Text, out PsiMax) == false)
            {
                MessageBox.Show("Fehlerhafte Eingabe!");
                return;
            }

            // Erzeugen eines neuen Bauteils
            ModelDoc2 swModel = (ModelDoc2)swApp.NewPart();

            // Herstellen zwischen MatCAD und aktives Arbeitsblatt auslesen
            Matcad.Application mcApp = (Mathcad.Application)Marshal.GetActiveObject("Mathcad.Applicaiton");
            Mathcad.Worksheet  mcWks = mcApp.ActiveWorksheet;

            // neuer Sketch in SolidWorks
            swModel.Extension.SelectByID2("Ebene vorne", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.InsertSketch2(true);

            // Setzen der Parameter im MathCAD Arbeitsblatt
            mcWks.SetValue("a0x", a0x);
            mcWks.SetValue("a0y", a0y);
            mcWks.SetValue("lh", lh);
            mcWks.SetValue("rg", rg);
            mcWks.SetValue("pmax", PMax);
            mcWks.SetValue("psimax", PsiMax);

            double xa = 0.0, ya = 0.0;
            double xk, yk;

            Mathcad.NumericValue mcVal;

            // Schleife zur Berechnung der Stützpunkte
            for (int i = 0; i < PMax; i++)
            {
                // Setzten des Parameters für aktuellen Stützpunkt
                mcWks.SetValue("pact", i);

                // Auslesen der berechneten Koordinaten aus MathCAD
                mcVal = (Mathcad.NumericValue)mcWks.GetValue("X");
                xk    = mcVal.Real;

                mcVal = (Mathcad.NumericValue)mcWks.GetValue("Y");
                yk    = mcVal.Real;

                if (i > 0)
                {
                    swModel.CreateLine2(xa / 1000.0, ya / 1000.0, 0, xk /
                                        1000.0, yk / 1000.0, 0);
                }
                xa = xk;
                ya = yk;
            }

            // Kreis zeichnen und extrudieren
            swModel.CreateCircleByRadius2(a0x / 1000.0, a0y / 1000.0, 0.0, 3.0 / 1000.0);

            swModel.FeatureManager.FeatureExtrusion2(true, false, false, 0, 0,
                                                     0.01, 0, false, false, false, false, 0, 0, false, false, false,
                                                     false, false, false, false, 0, 0, false);
        }
        //
        private void b_createWithSpline_Click(object sender, EventArgs e)
        {
            double a0x, a0y, lh, rg, PMax, PsiMax;

            // Auslesen der eingegebenen Werte im Formular
            if (double.TryParse(tb_a0x.Text, out a0x) == false ||
                double.TryParse(tb_a0y.Text, out a0y) == false ||
                double.TryParse(tb_lh.Text, out lh) == false ||
                double.TryParse(tb_rg.Text, out rg) == false ||
                double.TryParse(tb_pmax.Text, out PMax) == false ||
                double.TryParse(tb_psimax.Text, out PsiMax) == false)
            {
                MessageBox.Show("Fehlerhafte Eingabe!");
                return;
            }

            // Erzeugen eines neuen Bauteils
            ModelDoc2 swModel = (ModelDoc2)swApp.NewPart();

            // Herstellen zwischen MatCAD und aktives Arbeitsblatt auslesen
            Matcad.Application mcApp = (Mathcad.Application)Marshal.GetActiveObject("Mathcad.Applicaiton");
            Mathcad.Worksheet  mcWks = mcApp.ActiveWorksheet;

            // neuer Sketch in SolidWorks
            swModel.Extension.SelectByID2("Ebene vorne", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.InsertSketch2(true);

            // Setzen der Parameter im MathCAD Arbeitsblatt
            mcWks.SetValue("a0x", a0x);
            mcWks.SetValue("a0y", a0y);
            mcWks.SetValue("lh", lh);
            mcWks.SetValue("rg", rg);
            mcWks.SetValue("psimax", PsiMax);
            mcWks.SetValue("pcnt", PMax);

            double[] PointData = new double[(int)(PMax * 3 + 3)];
            int      pIndex = 0;
            double   xk, yk;

            Mathcad.NumericValue mcVal;


            // Schleife zur Berechnung der Stützpunkte
            for (int i = 0; i < PMax; i++)
            {
                // Setzten des Parameters für aktuellen Stützpunkt
                mcWks.SetValue("pact", i);

                // Auslesen der berechneten Koordinaten aus MathCAD
                mcVal = (Mathcad.NumericValue)mcWks.GetValue("X");
                xk    = mcVal.Real;

                mcVal = (Mathcad.NumericValue)mcWks.GetValue("Y");
                yk    = mcVal.Real;

                PointData[pIndex]     = xk / 1000.0;
                PointData[pIndex + 1] = yk / 1000.0;
                PointData[pIndex + 2] = 0;
                pIndex = pIndex + 3;
            }

            swModel.CreateSpline(PointData);
            swModel.CreateCircleByRadius2(a0x / 1000.0, a0y / 1000.0, 0.0, 3.0 / 1000.0);

            swModel.FeatureManager.FeatureExtrusion2(true, false, false, 0, 0,
                                                     0.01, 0, false, false, false, false, 0, 0, false, false, false,
                                                     false, false, false, false, 0, 0, false);
        }
        public override void CreatePart()
        {
            swApp = SolidWorksSingleton.GetApplication();
            DocumentManager.CreateNewPartDoc();

            swModel = (ModelDoc2)swApp.ActiveDoc;

            swFeature      = swModel.FeatureByPositionReverse(3);
            swFeature.Name = "Front";

            swModel.Extension.SelectByID2("Front", "PLANE", 0, 0, 0, false, 0, null, 0);

            swModel.InsertSketch2(true);

            swModel.CreateLine2(0, 0, 0, XLenght, 0, 0);
            //swModel.AddDimension2(0,0,0);

            swModel.CreateLine2(0, 0, 0, 0, YLenght, 0);
            //swModel.AddDimension2(0, 0, 0);

            //int markHorizontal = 2;
            //int markVertical = 4;

            //swModel.Extension.SelectByID2("Point1@Origin", "EXTSKETCHSEGMENT",0,0,0,false, markHorizontal|markVertical,null,0);

            object datumDisp = "Point1@Origin";

            swModel.SketchManager.FullyDefineSketch(true, true, (int)swSketchFullyDefineRelationType_e.swSketchFullyDefineRelationType_Vertical | (int)swSketchFullyDefineRelationType_e.swSketchFullyDefineRelationType_Horizontal, true, (int)swAutodimScheme_e.swAutodimSchemeBaseline, datumDisp, (int)swAutodimScheme_e.swAutodimSchemeBaseline, datumDisp, (int)swAutodimHorizontalPlacement_e.swAutodimHorizontalPlacementBelow, (int)swAutodimVerticalPlacement_e.swAutodimVerticalPlacementLeft);

            swModel.InsertSketch2(true);

            swFeature      = swModel.FeatureByPositionReverse(0);
            swFeature.Name = "Sketch1";

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

            swModel.FeatureManager.InsertSheetMetalBaseFlange2(Thickness, false, Thickness, Width, 0, true, 0, 0, 0, null, false, 0, 0, 0, 0, false, false, false, false);

            BasicOpertations.ChangeEntityName("FACE", MateRef1, Thickness, YLenght / 2, -Width / 2);

            swModel.Extension.SelectByID2("", "FACE", XLenght / 2, Thickness, -Width / 2, false, 0, null, 0);

            swModel.InsertSketch2(true);

            swModel.CreateCircleByRadius2(XLenght - X1, X2, 0, BoltHoles);
            swModel.CreateCircleByRadius2(XLenght - X1, Width - X2, 0, BoltHoles);

            swModel.InsertSketch2(true);

            swFeature      = swModel.FeatureByPositionReverse(0);
            swFeature.Name = "BoltHoles";

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

            BasicOpertations.SimpleCut();


            swPart = (PartDoc)swApp.ActiveDoc;

            swEntity = swPart.GetEntityByName(MateRef1, (int)swSelectType_e.swSelFACES);
            swEntity.Select4(false, null);

            swModel.InsertSketch2(true);

            swModel.CreateCircleByRadius2(Width / 2, YLenght - (PipeHole * 2), 0, PipeHole);
            swModel.AddDiameterDimension(0, 0, 0);

            swModel.InsertSketch2(true);

            BasicOpertations.SimpleCut();

            BasicOpertations.ChangeEntityName("FACE", MateRefHole, Thickness / 2, YLenght - PipeHole, -Width / 2);

            swModel = (ModelDoc2)swApp.ActiveDoc;

            swModel.Extension.SelectByID2("", "EDGE", XLenght, Thickness / 2, 0, false, 0, null, 0);
            swModel.Extension.SelectByID2("", "EDGE", XLenght, Thickness / 2, -Width, true, 0, null, 0);

            BasicOpertations.SimpleFillet(Rad2);

            swModel.Extension.SelectByID2("", "EDGE", Thickness / 2, YLenght, 0, false, 0, null, 0);
            swModel.Extension.SelectByID2("", "EDGE", Thickness / 2, YLenght, -Width, true, 0, null, 0);

            BasicOpertations.SimpleFillet(Rad1);

            swModel.ClearSelection2(true);
            swModel.ViewZoomtofit2();

            DocumentManager.Save(TargetFolder, FileName, DocumentManager.sw_DocType.part);
        }