Пример #1
0
        public void didBuildModel()
        {
            SwApp.NewPart();
            _swModel = SwApp.IActiveDoc2;
            _swPart  = (PartDoc)(_swModel);

            _swModel.Extension.SelectByID2("Top", "PLANE", 0, 0, 0, false, 0, null, 0);
            _swModel.SketchManager.InsertSketch(true);
            _swModel.ClearSelection2(true);

            _swModel.SketchManager.CreateCornerRectangle(0, 0, 0, Length, Width, 0);
            _swModel.ClearSelection2(true);

            _swModel.SketchManager.InsertSketch(true);

            _swModel.FeatureManager.FeatureExtrusion2(true, false, false, 0, 0, Height, 0.01, false, false, false, false, 1.74532925199433E-02, 1.74532925199433E-02, false, false, false, false, true, true, true, 0, 0, false);

            _swModel.Extension.SelectByID2("", "FACE", Length / 2, Height, -Width / 2, false, 0, null, 0);
            _swModel.ShowNamedView2("*Top", 5);

            _swModel.ViewZoomTo2(-1.40224455089843E-02, 7.79877043000974E-02, 0, 0.090572328390715, -1.30337019942975E-02, 0);

            _swModel.SketchManager.CreateCircle(0.004, Width - 0.004, 0, 0.004, Width - 0.004 + 0.00135, 0);
            _swModel.ClearSelection2(true);

            _swModel.SketchManager.CreateCircle(0.004, 0.004, 0, 0.004, 0.00535, 0);
            _swModel.ClearSelection2(true);

            _swModel.SketchManager.CreateCircle(Length - 0.004, Width - 0.004, 0, Length - 0.004, Width - 0.004 + 0.00135, 0);
            _swModel.ClearSelection2(true);

            _swModel.SketchManager.CreateCircle(Length - 0.004, 0.004, 0, Length - 0.004, 0.00535, 0);
            _swModel.ClearSelection2(true);

            _swModel.ShowNamedView2("*Isometry", 7);

            _swModel.Extension.SelectByID2("Arc1@", "EXTSKETCHSEGMENT", 5.96034675525732E-03, 6.63356185593879E-02, 0, false, 0, null, 0);
            _swModel.FeatureManager.FeatureCut3(true, false, false, 1, 0, 0.005, 0.005, false, false, false, false, 1.74532925199433E-02, 1.74532925199433E-02, false, false, false, false, false, true, true, true, true, false, 0, 0, false);

            _swModel.ViewZoomTo2(-1.30039690871637E-02, 3.75387366394858E-02, 1.58777579102132E-02, 0.142076690355558, -0.052121832944159, 1.58777579102138E-02);
            _swModel.ShowNamedView2("*Left", 3);
            _swModel.ViewZoomTo2(-0.083498837770881115, 0.014433467968860341, -0.060000000000000081, 0.0096740082936823124, -0.016165167848730275, -0.059999999999999866);
            _swModel.Extension.SelectByID2("", "EDGE", 0, Height / 2, 0, true, 0, null, 0);
            _swModel.Extension.SelectByID2("", "EDGE", 0, Height / 2, -Width, true, 0, null, 0);
            _swModel.ShowNamedView2("*Righr", 4);
            _swModel.ViewZoomTo2(-0.013345844591793166, 0.018717276983323025, 0.059999999999999894, 0.080438974189122076, -0.017083126923257995, 0.060000000000000143);
            _swModel.Extension.SelectByID2("", "EDGE", Length, Height / 2, 0, true, 0, null, 0);
            _swModel.Extension.SelectByID2("", "EDGE", Length, Height / 2, -Width, true, 0, null, 0);
            _swModel.ShowNamedView2("*Isometry", 7);
            _swModel.FeatureManager.InsertFeatureChamfer(4, 1, 0.0027, 0.78539816339745, 0, 0, 0, 0);


            _swModel.Extension.SelectByID2("Body-Feature1", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            _swModel.Extension.SelectByID2("Unknown", "BROWSERITEM", 0, 0, 0, false, 0, null, 0);
            _swModel.ClearSelection2(true);
            _swPart.SetMaterialPropertyName2("По умолчанию", @"C:/ProgramData/SolidWorks/SolidWorks 2012/Sustainability/Sustainability Extras.sldmat", "Плата системы питания");
            _swModel.ClearSelection2(true);

            _swModel.SaveAs3(@"C:\Certificate\plata.SLDPRT", 0, 2);
        }
Пример #2
0
        public void ShouldBeAbleToApplySampleMacroFeature()
        {
            ((IModelDoc2)SwApp.NewPart()).Using(SwApp, modelDoc =>
            {
                Assert.True(modelDoc.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0));
                var plane1 = (RefPlane)modelDoc.FeatureManager.InsertRefPlane(8, 0.01, 0, 0, 0, 0);
                Assert.True(modelDoc.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0));
                var plane2 = (RefPlane)modelDoc.FeatureManager.InsertRefPlane(8, 0.02, 0, 0, 0, 0);

                Assert.True(modelDoc.Extension.SelectByID2("Plane2", "PLANE", 0, 0, 0, false, 0, null, 0));
                var lines =
                    modelDoc.SketchManager.CreateCornerRectangle(-0.02, 0.01, 0, 0.02, -0.01, 0)
                    .CastArray <ISketchSegment>();
                // Sketch to extrude
                Assert.True(modelDoc.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 0, null, 0));
                // Start condition reference
                Assert.True(modelDoc.Extension.SelectByID2("Plane2", "PLANE", 0.00105020593408751, -0.00195369982668282,
                                                           0.0248175428318827, true, 32, null, 0));
                // End condition reference
                Assert.True(modelDoc.Extension.SelectByID2("Plane1", "PLANE", 0.0068370744701368, -0.004419862088339,
                                                           0.018892268568016, true, 1, null, 0));

                // Boss extrusion start condition reference is Plane2, and the extrusion end is offset 3 mm from the end condition reference, Plane1
                var feature = modelDoc.FeatureManager.FeatureExtrusion3(true, false, true,
                                                                        (int)swEndConditions_e.swEndCondOffsetFromSurface, 0, 0.003, 0.003, false, false, false,
                                                                        false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, true, true, true,
                                                                        (int)swStartConditions_e.swStartSurface, 0, false);

                var macroFeature = new DemoMacroFeatures.SampleMacroFeature.SampleMacroFeature();
                macroFeature.Edit(SwApp, modelDoc, null);
                Assert.True(modelDoc.Extension.SelectByID2(feature.Name, "SOLIDBODY", 0, 0, 0, false, 1, null, 0));

                // TODO this doesn't work. It raises a dialog that says it can't create
                // the feature
                macroFeature.Commit();
            });
        }