//Microsoft.Office.Interop.MSProject //string[] args static void CreateSketch() { SldWorks swApp = new SldWorks(); //Feature myFeature; ModelDoc2 swModel = default(ModelDoc2); //RefPlane myRefPlane; SketchManager swSkMgr = default(SketchManager); FeatureManager swFeMgr = default(FeatureManager); //Feature swFeat; //Sketch swSketch; int longstatus = 0; bool boolstatus = false; swApp.ResetUntitledCount(0, 0, 0); swModel = (ModelDoc2)swApp.NewDocument("C:\\Users\\nemati\\Documents\\Visual Studio 2015\\Projects\\SWBlankApp\\SWBlankApp\\PartTemplate.SLDPRT", 0, 0, 0); swApp.ActivateDoc2("Part1", false, ref longstatus); swModel = (ModelDoc2)swApp.ActiveDoc; swSkMgr = swModel.SketchManager; swFeMgr = swModel.FeatureManager; swSkMgr.InsertSketch(true); //swFeMgr.FeatureExtruRefSurface() boolstatus = swModel.Extension.SelectByID2("Top Plane", "PLANE", -0.0553489443349025, 0.00330468607538553, 0.0269617286188933, false, 0, null, 0); swModel.ClearSelection2(true); if (swModel == null) { swApp.SendMsgToUser2("Ridi.", (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk); return; } int modelType = 0; modelType = swModel.GetType(); if (modelType != (int)swDocumentTypes_e.swDocPART) { swApp.SendMsgToUser2("A part document must be active.", (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk); return; } // Creating sample point SketchPoint skPoint = default(SketchPoint); skPoint = swSkMgr.CreatePoint(-100, 100, 0); // Creating sample arc SketchSegment skArc = default(SketchSegment); skArc = swSkMgr.Create3PointArc(0, 0, 0, 10, 10, 0, -10, 10, 0); // Creating sample circle SketchSegment skCircle = default(SketchSegment); skCircle = swSkMgr.CreateCircleByRadius(-20, 20, 0, 7.5); swSkMgr.InsertSketch(true); //swModel.SketchCircle(); Console.WriteLine(swApp.Visible.ToString()); Console.WriteLine(swApp.FrameWidth.ToString()); //swApp.CreateNewWindow(); swModel.SaveAs("C:\\Users\\nemati\\Documents\\Visual Studio 2015\\Projects\\SWBlankApp\\SWBlankApp\\SketchArc.SLDPRT"); //swApp. swApp.ExitApp(); //swApp = null; //swApp }
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(); }