/// <summary> /// Creates a layer to accumulate all upcoming spriteBatch calls. /// This method should be called before <see cref="End()"/>. /// </summary> public static void Begin() { PreventFumble(); if (disableRelay) { preventFumbledRelay = true; } SketchManager.RegisterStage(StageType.Setup); SketchManager.RegisterStage(StageType.Begin); // Make sure that this method is always called before End(spriteBatch). if (!SketchManager.VerifyQueue(StageType.Setup, StageType.Begin)) { throw new RelatusException("Begin(spriteBatch) must be called before End(spriteBatch).", new MethodOrderException()); } // Initialize a RenderTarget2D to accumulate all spriteBatch draw calls. accumulation = new RenderTarget2D(spriteBatch.GraphicsDevice, WindowManager.WindowWidth, WindowManager.WindowHeight); // Setup the GraphicsDevice with the new accumulation RenderTarget2D. spriteBatch.GraphicsDevice.SetRenderTarget(accumulation); spriteBatch.GraphicsDevice.Clear(clearColor); clearColor = Color.Transparent; }
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 BodyDrawer(SLDManager app, BodyParam body) { application = app; // Получает ISketchManager объект, который позволяет получить доступ к процедурам эскиза swSketchManager = application.swModel.SketchManager; // Получает ISelectionMgr объект для данного документа, что делает выбранный объект доступным swSelMgr = (SelectionMgr)application.swModel.SelectionManager; this.body = body; }
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); }
public static SketchSegment[] CreateLinesRectangle(this SketchManager manager, double x1, double y1, double z1, double x2, double y2, double z2) { return(manager.CreateLinesByPoints( x1, y1, z1, // A x2, y1, z1, // B x2, y2, z2, // C x1, y2, z2, // D x1, y1, z1 // A )); }
public AbstractNAngleDrawer(SLDManager app, BodyParametrs body, BodyDrawer bodyDrawer, double angle) { application = app; this.body = body; this.bodyDrawer = bodyDrawer; deflection_Angle = angle * Math.PI / 180; // Получает ISketchManager объект, который позволяет получить доступ к процедурам эскиза swSketchManager = application.swModel.SketchManager; // Получает ISelectionMgr объект для данного документа, что делает выбранный объект доступным swSelMgr = (SelectionMgr)application.swModel.SelectionManager; }
public void StartSwLines() { swSketchManager = modDoc.SketchManager; swSketchManager.Insert3DSketch(true); foreach (var l in dmcLines) { DrawSwLine(l); } swSketchManager.ActiveSketch.SetAutomaticSolve(true); Finish(); }
/// <summary> /// This will disable the upcoming layer from being drawn. /// This is useful for any effects that require additional passes. /// Note that if this method is called, you must call <see cref="InterceptRelay"/> after <see cref="End()"/>. /// This method should be called before <see cref="Begin()"/>. /// </summary> public static void DisableRelay() { SketchManager.RegisterStage(StageType.Setup); // Make sure that this method is always called before Begin(spriteBatch). if (!SketchManager.VerifyQueue(StageType.Setup)) { throw new RelatusException("AttachEffect(effect) must be called before Begin(spriteBatch).", new MethodOrderException()); } disableRelay = true; }
public static void DrawSketch(ModelDoc2 SketchDoc) { SketchManager SwSketchMrg = SketchDoc.SketchManager;//获得SketchManager对象 SketchDoc.Extension.SelectByID2("前视基准面", "PLANE", 0, 0, 0, false, 0, null, 0); SwSketchMrg.InsertSketch(true);//进入编辑草图模式 object[] ObjRectangle = SwSketchMrg.CreateCenterRectangle(0, 0, 0, 0.075, 0.04, 0); SketchSegment SktCircle1 = SwSketchMrg.CreateCircle(-0.0425, 0, 0, -0.03, 0, 0); SketchSegment SktCircle2 = SwSketchMrg.CreateCircle(0.0425, 0, 0, 0.03, 0, 0); SketchSegment SktCentLine = SwSketchMrg.CreateCenterLine(0, 0.04, 0, 0, -0.04, 0); SwSketchMrg.InsertSketch(true);//退出编辑草图模式 }
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()); }
/// <summary> /// Sets the upcoming layer's background to a specified color. /// This method should be called before <see cref="Begin()"/>. /// </summary> /// <param name="color">The color used to fill the background of the upcoming layer.</param> public static void SetBackgroundColor(Color color) { PreventFumble(); SketchManager.RegisterStage(StageType.Setup); // Make sure that this method is always called before Begin(spriteBatch). if (!SketchManager.VerifyQueue(StageType.Setup)) { throw new RelatusException("SetBackgroundColor(color) must be called before Begin(spriteBatch).", new MethodOrderException()); } clearColor = color; }
/// <summary> /// Attaches an effect that will be applied to the entire upcoming layer. /// More than one effect can be attached to a Sketch at a time. /// Effects are applied in the same order as they are attached. /// This method should be called before <see cref="Begin()"/>. /// </summary> /// <param name="effect">The shader that will be applied to the entire upcoming layer.</param> public static void AttachEffect(Effect effect) { PreventFumble(); SketchManager.RegisterStage(StageType.Setup); // Make sure that this method is always called before Begin(spriteBatch). if (!SketchManager.VerifyQueue(StageType.Setup)) { throw new RelatusException("AttachEffect(effect) must be called before Begin(spriteBatch).", new MethodOrderException()); } shaders.Enqueue(effect); }
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); }
public override void Execute() { try { var DateTimeStart = DateTime.Now; DsApp.AbortRunningCommand(); CommandMessage CmdLine = DsApp.GetCommandMessage(); if (null == CmdLine) { return; } Document DsDoc = DsApp.GetActiveDocument(); Model Mdl = DsDoc.GetModel(); SketchManager SkMgr = Mdl.GetSketchManager(); SelectionManager SlMgr = DsDoc.GetSelectionManager(); object ObjType = null; object ObjEntites = null; Int32[] TabTypes = null; object[] TabEntites = null; string[] TabNomsCalques = null; EntityHelper dsEntityHelper = DsApp.GetEntityHelper(); ///============================================================================== CmdLine.PrintLine("Suppression des gravures"); TabNomsCalques = new string[] { "GRAVURE", "Gravure", "gravure" }; SkMgr.GetEntities(null, TabNomsCalques, out ObjType, out ObjEntites); TabTypes = (Int32[])ObjType; TabEntites = (object[])ObjEntites; foreach (var ent in TabEntites) { dsEntityHelper.SetErased(ent, true); } TimeSpan t = DateTime.Now - DateTimeStart; CmdLine.PrintLine(String.Format("Executé en {0}", GetSimplestTimeSpan(t))); } catch (Exception e) { Log.Write(e); } }
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(); }
/// <summary> /// Рисует тело, в котором будут отверстия /// </summary> /// <returns>Возвращает объект, на котором будут сделаны ячейки</returns> public void drawBody() { //получем ссылку на интерфейс, ответственный за рисование swSketchManager = application.swModel.SketchManager; application.swModel.Extension.SelectByID2("Сверху", "PLANE", 0, 0, 0, false, 0, null, 0); //выбрал плоскость swSketchManager.InsertSketch(false); sketch = application.swModel.GetActiveSketch2(); //создать основание var rect = swSketchManager.CreateCenterRectangle(0, 0, 0, body.GetWidth() / acc / 2.0, body.GetHeight() / acc / 2.0, 0); //очистить буфер выбранных элементов application.swModel.ClearSelection(); //вытянуть бобышку Feature feature = featureExtrusion(body.GetLenght() / acc); application.swModel.ClearSelection(); body3d = feature; }
/// <summary> /// Passes the entire layer to the user. The SketchManager is no longer managing the life cycle of the layer. /// Failure to properly manage the layer will result in a memory leak, among other problems. /// This method should be called after <see cref="End()"/>. /// </summary> /// <returns>Returns the entire layer that was just created.</returns> public static RenderTarget2D InterceptRelay() { SketchManager.RegisterStage(StageType.Post); // Make sure that this method is always called after End(spriteBatch). if (!SketchManager.VerifyQueue(StageType.Setup, StageType.Begin, StageType.End, StageType.Post)) { throw new RelatusException("InterceptRelay() must be called after End(spriteBatch).", new MethodOrderException()); } // Make sure that DisableRelay() was called. if (result == null) { throw new RelatusException("There is nothing to intercept. Make sure to call DisableRelay() before calling Begin(spriteBatch)", new MethodOrderException()); } SketchManager.GiveUpControl(); disableRelay = false; preventFumbledRelay = false; return(result); }
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 } } }
/// <summary> /// Creates a background layer that fills the entire screen with a specified color. /// </summary> /// <param name="spriteBatch">The default Game's SpriteBatch object.</param> /// <param name="color">The color used to fill the background layer.</param> public static void CreateBackgroundLayer(Color color) { PreventFumble(); if (!SketchManager.VerifyQueue()) { throw new RelatusException("CreateBackgroundLayer(spriteBatch, color) must be independent of any other Sketch calls.", new MethodOrderException()); } // Initialize a RenderTarget2D to accumulate all spriteBatch draw calls. accumulation = new RenderTarget2D(spriteBatch.GraphicsDevice, WindowManager.WindowWidth, WindowManager.WindowHeight); // Setup the GraphicsDevice with the new accumulation RenderTarget2D. spriteBatch.GraphicsDevice.SetRenderTarget(accumulation); spriteBatch.GraphicsDevice.Clear(color); // Reset the GraphicsDevice's RenderTarget. spriteBatch.GraphicsDevice.SetRenderTarget(null); spriteBatch.GraphicsDevice.Clear(Color.Transparent); // Relay the final RenderTarget2D to be drawn by the LayerManager. SketchManager.AddSketch(accumulation); }
public static void AddConstraintAndDim(ModelDoc2 SketchDoc) { SketchManager SwSketchMrg = SketchDoc.SketchManager;//获得SketchManager对象 SketchDoc.Extension.SelectByID2("前视基准面", "PLANE", 0, 0, 0, false, 0, null, 0); SwSketchMrg.InsertSketch(true);//进入编辑草图模式 object[] ObjRectangle = SwSketchMrg.CreateCenterRectangle(0, 0, 0, 0.075, 0.04, 0); SketchSegment SktCircle1 = SwSketchMrg.CreateCircle(-0.0425, 0, 0, -0.03, 0, 0); SketchSegment SktCircle2 = SwSketchMrg.CreateCircle(0.0425, 0, 0, 0.03, 0, 0); SketchSegment SktCentLine = SwSketchMrg.CreateCenterLine(0, 0.04, 0, 0, -0.04, 0); #region 两个圆心添加水平 SketchDoc.ClearSelection2(true); SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", -0.0425, 0, 0, true, 0, null, 0); SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", 0.0425, 0, 0, true, 0, null, 0); SketchDoc.SketchAddConstraints("sgHORIZONTALPOINTS2D"); #endregion #region 两个圆心添加对称 SketchDoc.ClearSelection2(true); SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", -0.0425, 0, 0, true, 0, null, 0); SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", 0.0425, 0, 0, true, 0, null, 0); SktCentLine.Select(true); SketchDoc.SketchAddConstraints("sgSYMMETRIC"); #endregion #region 圆心与坐标原点水平 SketchDoc.ClearSelection2(true); SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", -0.0425, 0, 0, true, 0, null, 0); SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", 0, 0, 0, true, 0, null, 0); SketchDoc.SketchAddConstraints("sgHORIZONTALPOINTS2D"); #endregion #region 添加孔间距尺寸 SketchDoc.ClearSelection2(true); SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", -0.0425, 0, 0, true, 0, null, 0); SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", 0.0425, 0, 0, true, 0, null, 0); SketchDoc.AddDimension2(0, 0.05, 0); #endregion #region 两个圆添加相同大小 SktCircle1.Select(false); SktCircle2.Select(true); SketchDoc.SketchAddConstraints("sgSAMELENGTH"); #endregion #region 添加圆尺寸 SktCircle1.Select(false); SketchDoc.AddDimension2(-0.02, 0.02, 0); #endregion #region 添加矩形长 SketchDoc.Extension.SelectByID2("", "SKETCHSEGMENT", -0.02, 0.04, 0, false, 0, null, 0); SketchDoc.AddDimension2(0, 0.07, 0); #endregion #region 添加矩形高 SketchDoc.Extension.SelectByID2("", "SKETCHSEGMENT", 0.075, 0, 0, false, 0, null, 0); SketchDoc.AddDimension2(0.09, 0, 0); #endregion SwSketchMrg.InsertSketch(true);//退出编辑草图模式 }
/// <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); }
public override void Execute() { try { Sm = DsApp.GetActiveDocument().GetModel().GetSketchManager(); DsApp.AbortRunningCommand(); CommandMessage CmdLine = DsApp.GetCommandMessage(); if (null == CmdLine) { return; } // Erreur avec le premier prompt, la commande est automatiquement annulée // Pour contourner le pb, on lance une commande à vide. { String sss = ""; CmdLine.PromptForString(true, "", "", out sss); } Document DsDoc = DsApp.GetActiveDocument(); Model Mdl = DsDoc.GetModel(); SketchManager SkMgr = Mdl.GetSketchManager(); SelectionManager SlMgr = DsDoc.GetSelectionManager(); SelectionFilter SlFilter; SlFilter = SlMgr.GetSelectionFilter(); object[] TabEntites = null; SlFilter.Clear(); SlFilter.AddEntityType(dsObjectType_e.dsSplineType); SlFilter.Active = true; if (CmdLine.PromptForSelection(true, "Selectionnez la spline", "Ce n'est pas une spline")) { dsObjectType_e entityType; var count = SlMgr.GetSelectedObjectCount(dsSelectionSetType_e.dsSelectionSetType_Previous); TabEntites = new object[1]; object selectedEntity = SlMgr.GetSelectedObject(dsSelectionSetType_e.dsSelectionSetType_Previous, 0, out entityType); if (dsObjectType_e.dsSplineType == entityType) { TabEntites[0] = selectedEntity; } } CmdLine.PrintLine(TabEntites.Length + " spline(s) selectionnée(s)"); TimeSpan t; DateTime DateTimeStart; DateTimeStart = DateTime.Now; if (TabEntites != null && TabEntites.Length > 0) { foreach (Spline Spline in TabEntites) { var slength = Spline.GetLength(); var Boucle = 100000; var Pas = slength / Boucle; DateTimeStart = DateTime.Now; for (double i = 0; i <= slength; i += Pas) { //CmdLine.PrintLine(i.ToString()); var ev = Spline.EvalDistance(i); //Action<iPoint, iVecteur, double> Tracer = delegate (iPoint origine, iVecteur derive, double echelle) //{ // var s = origine; // var e = origine.DeplacerC(derive.MultiplierC(echelle)); // SkMgr.InsertLine(s.X, s.Y, s.Z, e.X, e.Y, e.Z); //}; ////Tracer(ev.Point, ev.Derivee1, 100); ////Tracer(ev.Point, ev.Derivee2, 1000); } CmdLine.PrintLine(String.Format("1 Executé en {0}", GetSimplestTimeSpan(DateTime.Now - DateTimeStart))); double sP; double eP; Spline.GetEndParams(out sP, out eP); Pas = (eP - sP) / Boucle; DateTimeStart = DateTime.Now; for (double i = sP; i <= eP; i += Pas) { //CmdLine.PrintLine(i.ToString()); var ev = Spline.EvalParam(i); //Action<iPoint, iVecteur, double> Tracer = delegate (iPoint origine, iVecteur derive, double echelle) //{ // var s = origine; // var e = origine.DeplacerC(derive.MultiplierC(echelle)); // SkMgr.InsertLine(s.X, s.Y, s.Z, e.X, e.Y, e.Z); //}; ////Tracer(ev.Point, ev.Derivee1, 100); ////Tracer(ev.Point, ev.Derivee2, 1000); } CmdLine.PrintLine(String.Format("2 Executé en {0}", GetSimplestTimeSpan(DateTime.Now - DateTimeStart))); } } t = DateTime.Now - DateTimeStart; CmdLine.PrintLine(String.Format("Executé en {0}", GetSimplestTimeSpan(t))); } catch (Exception e) { Log.Write(e); } }
/// <summary> /// Applies any attached effects to the current layer, and passes the layer to the SketchManager to be drawn. /// This method should be called after <see cref="Begin()"/>. /// </summary> public static void End() { SketchManager.RegisterStage(StageType.End); // Make sure that this method is always called after Begin(spriteBatch). if (!SketchManager.VerifyQueue(StageType.Setup, StageType.Begin, StageType.End)) { throw new RelatusException("End(spriteBatch) must be called after Begin(spriteBatch).", new MethodOrderException()); } // Reset the GraphicsDevice's RenderTarget. spriteBatch.GraphicsDevice.SetRenderTarget(null); if (shaders.Count > 0) { // Create an array of RenderTarget2Ds to store the accumulation of each shader. RenderTarget2D[] renderTargets = new RenderTarget2D[shaders.Count]; for (int i = 0; i < renderTargets.Length; i++) { renderTargets[i] = new RenderTarget2D(spriteBatch.GraphicsDevice, WindowManager.WindowWidth, WindowManager.WindowHeight); } int totalShaders = shaders.Count; Effect shader; // Iterate through all the shaders in the queue. for (int i = 0; i < totalShaders; i++) { shader = shaders.Dequeue(); // Setup the GraphicsDevice with the current RenderTarget2D. spriteBatch.GraphicsDevice.SetRenderTarget(renderTargets[i]); spriteBatch.GraphicsDevice.Clear(Color.Transparent); // Apply the shader. spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, shader, null); { spriteBatch.Draw(i == 0 ? accumulation : renderTargets[i - 1], Vector2.Zero, Color.White); } spriteBatch.End(); // Dispose of the current shader. shader.Dispose(); } // Initialize a RenderTarget2D to capture the result of all the shaders. result = new RenderTarget2D(spriteBatch.GraphicsDevice, WindowManager.WindowWidth, WindowManager.WindowHeight); // Setup the GraphicsDevice with the result RenderTarget2D. spriteBatch.GraphicsDevice.SetRenderTarget(result); spriteBatch.GraphicsDevice.Clear(Color.Transparent); spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, null); { spriteBatch.Draw(renderTargets[renderTargets.Length - 1], Vector2.Zero, Color.White); } spriteBatch.End(); // Dispose of all the unnecessary RenderTarget2Ds. for (int i = 0; i < renderTargets.Length; i++) { renderTargets[i].Dispose(); } accumulation.Dispose(); // Reset the GraphicsDevice's RenderTarget. spriteBatch.GraphicsDevice.SetRenderTarget(null); // Relay the final RenderTarget2D to be drawn by the LayerManager. if (!disableRelay) { SketchManager.AddSketch(result); } } else { // Relay the accumulation RenderTarget2D to be drawn by the LayerManager. if (!disableRelay) { SketchManager.AddSketch(accumulation); } // Otherwise set the result as the current accumulation to be intercepted by the user. else { result = accumulation; } } }
public object[] draw(SketchManager sm) { sketch = sm.CreateParallelogram(p1.X, p1.Y, p1.Z, p2.X, p2.Y, p2.Z, p3.X, p3.Y, p3.Z); return(sketch); }
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(); }
public override void Execute() { try { var DateTimeStart = DateTime.Now; DsApp.AbortRunningCommand(); CommandMessage CmdLine = DsApp.GetCommandMessage(); if (null == CmdLine) { return; } //============================================================================== CmdLine.PrintLine("Calque '0' actif"); Document DsDoc = DsApp.GetActiveDocument(); LayerManager LyMgr = DsDoc.GetLayerManager(); Layer L0 = LyMgr.GetLayer("0"); L0.Activate(); // Creer les calques de pliage Color c; dsCreateObjectResult_e Erreur; //============================================================================== CmdLine.PrintLine("Création du claque 'LIGNES DE PLIAGE'"); Layer LigneDePliage; LyMgr.CreateLayer("LIGNES DE PLIAGE", out LigneDePliage, out Erreur); c = LigneDePliage.Color; c.SetColorByIndex(252); LigneDePliage.Color = c; //============================================================================== CmdLine.PrintLine("Création du claque 'NOTE DE PLIAGE'"); Layer NoteDePliage = null; LyMgr.CreateLayer("NOTE DE PLIAGE", out NoteDePliage, out Erreur); c = NoteDePliage.Color; c.SetColorByIndex(126); NoteDePliage.Color = c; Model Mdl = DsDoc.GetModel(); SketchManager SkMgr = Mdl.GetSketchManager(); SelectionManager SlMgr = DsDoc.GetSelectionManager(); SelectionFilter SlFilter; object ObjType = null; object ObjEntites = null; Int32[] TabTypes = null; object[] TabEntites = null; string[] TabNomsCalques = null; //============================================================================== CmdLine.PrintLine("Couleur des entité sur 'DuCalque'"); TabNomsCalques = GetTabNomsCalques(DsDoc); SkMgr.GetEntities(null, TabNomsCalques, out ObjType, out ObjEntites); TabEntites = (object[])ObjEntites; EntityHelper dsEntityHelper = DsApp.GetEntityHelper(); foreach (object entity in TabEntites) { Color ce = dsEntityHelper.GetColor(entity); ce.SetNamedColor(dsNamedColor_e.dsNamedColor_ByLayer); dsEntityHelper.SetColor(entity, ce); } //============================================================================== CmdLine.PrintLine("Transfert des lignes et notes de pliage sur les calques correspondants"); TabNomsCalques = new string[] { "0" }; SkMgr.GetEntities(null, TabNomsCalques, out ObjType, out ObjEntites); TabTypes = (Int32[])ObjType; TabEntites = (object[])ObjEntites; for (int i = 0; i < TabEntites.GetLength(0); i++) { dsObjectType_e tpe = (dsObjectType_e)TabTypes[i]; if (tpe == dsObjectType_e.dsLineType) { Line L = (Line)TabEntites[i]; if (L.LineStyle == "SLD-Center") { L.Layer = LigneDePliage.Name; } } else if (tpe == dsObjectType_e.dsNoteType) { Note N = (Note)TabEntites[i]; N.Layer = NoteDePliage.Name; } } //============================================================================== CmdLine.PrintLine("Conversion des textes à graver en lignes"); SlFilter = SlMgr.GetSelectionFilter(); SlFilter.Clear(); SlFilter.AddEntityType(dsObjectType_e.dsNoteType); SlFilter.Active = true; TabNomsCalques = new string[] { "GRAVURE" }; SkMgr.GetEntities(SlFilter, TabNomsCalques, out ObjType, out ObjEntites); TabTypes = (Int32[])ObjType; TabEntites = ObjEntites as object[]; if (TabEntites != null && TabEntites.Length > 0) { CmdLine.PrintLine(TabEntites.Length + " texte(s) convertis"); foreach (var Texte in TabEntites) { SlMgr.ClearSelections(dsSelectionSetType_e.dsSelectionSetType_Current); dsEntityHelper.Select(Texte, true); DsApp.RunCommand("ECLATERTEXTE\n", true); } } DsApp.RunCommand("_CSICON\nP\n", true); //============================================================================== CmdLine.PrintLine("Purger le dessin"); DsApp.RunCommand("_-CLEAN\n_All\n*\n_No\n", true); TimeSpan t = DateTime.Now - DateTimeStart; CmdLine.PrintLine(String.Format("Executé en {0}", GetSimplestTimeSpan(t))); } catch (Exception e) { Log.Write(e); } }
public override void Execute() { try { DsDoc = DsApp.GetActiveDocument(); DsMdl = DsDoc.GetModel(); LyM = DsDoc.GetLayerManager(); SkM = DsMdl.GetSketchManager(); SlM = DsDoc.GetSelectionManager(); DsApp.AbortRunningCommand(); CommandMessage CmdLine = DsApp.GetCommandMessage(); if (null == CmdLine) { return; } // Erreur avec le premier prompt, la commande est automatiquement annulée // Pour contourner le pb, on lance une commande à vide. { String sss = ""; CmdLine.PromptForString(true, "", "", out sss); } SelectionFilter SlFilter; SlFilter = SlM.GetSelectionFilter(); ReferenceImage Image = null; SlFilter.Clear(); SlFilter.AddEntityType(dsObjectType_e.dsReferenceImageType); SlFilter.Active = true; int NbPoint = 5000; Double Jeu = 5; Double DiamMin = 5; Double DiamMax = 45; // Double.PositiveInfinity; int SeuilNoirs = 8; int BlancPctDiam = 65; int TypeSampler = 2; int NbAffinage = 6; bool MaillageEtPoint = false; CmdLine.PromptForInteger("Nb de points maximum ", NbPoint, out NbPoint); CmdLine.PromptForDouble("Jeu entre les cercles ", Jeu, out Jeu); CmdLine.PromptForDouble("Supprimer les cercles de diam inf. à ", DiamMin, out DiamMin); CmdLine.PromptForDouble("Réduire les cercles de diam sup. à ", DiamMax, out DiamMax); CmdLine.PromptForInteger("Seuil mini pour les noirs (0 à 255) ", SeuilNoirs, out SeuilNoirs); CmdLine.PromptForInteger("Blanc, % du diam mini (0 à 100)", BlancPctDiam, out BlancPctDiam); CmdLine.PromptForInteger("Type de sampler : 1 -> Poisson / 2 -> Rejection ", TypeSampler, out TypeSampler); CmdLine.PromptForInteger("Nb d'iteration pour l'affinage ", NbAffinage, out NbAffinage); CmdLine.PromptForBool("Dessiner le maillage et les points d'origine ", "Oui", "Non", MaillageEtPoint, out MaillageEtPoint); if (CmdLine.PromptForSelection(true, "Selectionnez l'image", "Ce n'est pas une image")) { dsObjectType_e entityType; var count = SlM.GetSelectedObjectCount(dsSelectionSetType_e.dsSelectionSetType_Previous); object selectedEntity = SlM.GetSelectedObject(dsSelectionSetType_e.dsSelectionSetType_Previous, 0, out entityType); if (dsObjectType_e.dsReferenceImageType == entityType) { Image = (ReferenceImage)selectedEntity; } } //object ObjType = null; //object ObjEntites = null; //string[] TabNomsCalques = GetTabNomsCalques(DsDoc); //SkM.GetEntities(SlFilter, TabNomsCalques, out ObjType, out ObjEntites); //object[] TabEntites = ObjEntites as object[]; //Image = (ReferenceImage)TabEntites[0]; TimeSpan t; DateTime DateTimeStart; DateTimeStart = DateTime.Now; if (Image != null) { CmdLine.PrintLine(String.Format("Image : {0}", Image.GetPath())); Double ImgX, ImgY, ImgZ; Image.GetPosition(out ImgX, out ImgY, out ImgZ); CmdLine.PrintLine("Sampler"); Log.Message("Sampler"); List <PointF> listePoint; if (TypeSampler == 1) { Double fact1 = 2; Double fact2 = 0.7; CmdLine.PromptForDouble("Facteur multip. du rayon de rejection ", fact1, out fact1); CmdLine.PromptForDouble("Facteur multip. du rayon minimum à l'initialisation ", fact2, out fact2); listePoint = BitmapPoissonSampler.Run(Image, NbPoint, fact1, fact2); } else { listePoint = BitmapRejectionSampler.Run(Image, NbPoint); } dsCreateObjectResult_e res; var CalquePoint = LyM.GetLayer("Point"); if (CalquePoint == null) { LyM.CreateLayer("Point", out CalquePoint, out res); var c = CalquePoint.Color; c.SetColorByIndex(230); CalquePoint.Color = c; } if (MaillageEtPoint) { CalquePoint.Activate(); foreach (var pc in listePoint) { SkM.InsertCircleByDiameter(ImgX + pc.X, ImgY + Image.Height - pc.Y, 0, 2); } } CmdLine.PrintLine("Sampler terminé"); Log.Message("Sampler terminé"); Log.Message("Equilibrage des points"); VoronoiMap.VoronoiGraph graph; var listeSitePoincon = VoronoiEquilibreur.Start(Image, listePoint, NbAffinage, out graph); Log.Message("Equilibrage terminé"); var CalquePoincon = LyM.GetLayer("Poincon"); if (CalquePoincon == null) { LyM.CreateLayer("Poincon", out CalquePoincon, out res); var c = CalquePoincon.Color; c.SetColorByIndex(252); CalquePoincon.Color = c; } var CalqueMaillage = LyM.GetLayer("Maillage"); if (CalqueMaillage == null) { LyM.CreateLayer("Maillage", out CalqueMaillage, out res); var c = CalqueMaillage.Color; c.SetColorByIndex(126); CalqueMaillage.Color = c; } var CalqueHachures = LyM.GetLayer("Hachures"); if (CalqueHachures == null) { LyM.CreateLayer("Hachures", out CalqueHachures, out res); var c = CalqueHachures.Color; c.SetColorByIndex(100); CalqueMaillage.Color = c; } var ListeCercles = new List <Circle>(); CalquePoincon.Activate(); var facteurGris = (100 - BlancPctDiam) / (255 - SeuilNoirs); var DiamMiniDessin = Double.PositiveInfinity; var DiamMaxiDessin = 0.0; foreach (var pc in listeSitePoincon) { var diam = pc.CercleInscrit - (Jeu * 0.5); var reduce = (BlancPctDiam + (255 - pc.GrisCercleInscrit) * facteurGris) / 100; var diamReduce = Math.Min(DiamMax, diam * reduce); if (pc.GrisCercleInscrit > SeuilNoirs && diamReduce >= DiamMin) { //Log.Message("Ø : " + diam + " / f : " + reduce + " / Øred : " + diamReduce); DiamMiniDessin = Math.Min(DiamMiniDessin, diamReduce); DiamMaxiDessin = Math.Max(DiamMaxiDessin, diamReduce); var cercle = SkM.InsertCircleByDiameter(ImgX + pc.Site.X, ImgY + Image.Height - pc.Site.Y, 0, diamReduce); ListeCercles.Add(cercle); } } var format = String.Format("Nb de percages : {0} / DiamMaxi : {1:0.0} / DiamMini : {2:0.0}", ListeCercles.Count, DiamMaxiDessin, DiamMiniDessin); CmdLine.PrintLine(format); Log.Message(format); CalqueHachures.Activate(); foreach (var item in ListeCercles) { var ent = new DispatchWrapper[1] { new DispatchWrapper(item) }; SkM.InsertHatchByEntities(ent, "SOLID", 1, 0); } if (MaillageEtPoint) { CalqueMaillage.Activate(); foreach (var s in graph.Segments) { SkM.InsertLine(ImgX + s.P1.X, ImgY + Image.Height - s.P1.Y, 0, ImgX + s.P2.X, ImgY + Image.Height - s.P2.Y, 0); } } LyM.GetLayer("0").Activate(); CalqueMaillage.Shown = false; CalquePoint.Shown = false; CalquePoincon.Shown = false; } else { CmdLine.PrintLine("Pas d'image"); } t = DateTime.Now - DateTimeStart; CmdLine.PrintLine(String.Format("Executé en {0}", GetSimplestTimeSpan(t))); } catch (Exception e) { Log.Write(e); } }
public void StartSwLines() { swSketchManager = modDoc.SketchManager; swSketchManager.Insert3DSketch(true); foreach (var l in dmcLines) { DrawSwLine(l); } swSketchManager.ActiveSketch.SetAutomaticSolve(true); Finish(); }
//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); 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(); }
public object[] draw(SketchManager sm) { sketch = sm.CreatePolygon(center.X, center.Y, center.Z, vertex.X, vertex.Y, vertex.Z, COUNT, false); return(sketch); }
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(); }