Jozi68 Posted October 13, 2009 Share Posted October 13, 2009 Anyone know how to create a donut using .net (not lisp)? Quote Link to comment Share on other sites More sharing options...
fixo Posted October 13, 2009 Share Posted October 13, 2009 Anyone know how to create a donut using .net (not lisp)? Try this one C#: [CommandMethod("DON")] static public void DrawDonut() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; try { PromptDoubleOptions pdo1 = new PromptDoubleOptions("\nSpecify inside diameter of donut: "); pdo1.AllowNegative = false; pdo1.AllowNone = false; pdo1.AllowZero = false; PromptDoubleResult dres1 = ed.GetDouble(pdo1); if (dres1.Status != PromptStatus.OK) { return; } PromptDoubleOptions pdo2 = new PromptDoubleOptions("\nSpecify outside diameter of donut: "); pdo2.AllowNegative = false; pdo2.AllowNone = false; pdo2.AllowZero = false; PromptDoubleResult dres2 = ed.GetDouble(pdo2); if (dres2.Status != PromptStatus.OK) { return; } PromptPointOptions pto = new PromptPointOptions("\nSpecify center point of donut: "); pto.AllowNone = false; PromptPointResult ptres = ed.GetPoint(pto); Point3d center = ptres.Value; if (ptres.Status != PromptStatus.OK) { return; } Double rad1 = dres1.Value / 2; Double rad2 = dres2.Value / 2; Double lwt = rad2 - rad1; Point2d pt1 = new Point2d(center.X - (rad1 + lwt / 2), center.Y); Point2d pt2 = new Point2d(center.X + (rad1 + lwt / 2), center.Y); Polyline pline = new Polyline(); pline.AddVertexAt(0, pt1, 1.0, lwt, lwt); pline.AddVertexAt(1, pt2, 1.0, lwt, lwt); pline.AddVertexAt(2, pt1, 0.0, lwt, lwt); pline.Closed = true; { Database db = HostApplicationServices.WorkingDatabase; AcDb.TransactionManager tm = db.TransactionManager; using (Transaction tr = tm.StartTransaction()) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); tr.Commit(); } } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { ed.WriteMessage(ex.StackTrace); } } VB.NET: <CommandMethod("DON")> _ Shared Public Sub DrawDonut() Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor Try Dim pdo1 As PromptDoubleOptions = New PromptDoubleOptions("\nSpecify inside diameter of donut: ") pdo1.AllowNegative = False pdo1.AllowNone = False pdo1.AllowZero = False Dim dres1 As PromptDoubleResult = ed.GetDouble(pdo1) If dres1.Status <> PromptStatus.OK Then Return End If Dim pdo2 As PromptDoubleOptions = New PromptDoubleOptions("\nSpecify outside diameter of donut: ") pdo2.AllowNegative = False pdo2.AllowNone = False pdo2.AllowZero = False Dim dres2 As PromptDoubleResult = ed.GetDouble(pdo2) If dres2.Status <> PromptStatus.OK Then Return End If Dim pto As PromptPointOptions = New PromptPointOptions("\nSpecify center point of donut: ") pto.AllowNone = False Dim ptres As PromptPointResult = ed.GetPoint(pto) Dim center As Point3d = ptres.Value If ptres.Status <> PromptStatus.OK Then Return End If Dim rad1 As Double = dres1.Value / 2 Dim rad2 As Double = dres2.Value / 2 Dim lwt As Double = rad2 - rad1 Dim pt1 As Point2d = New Point2d(center.X -(rad1 + lwt / 2),center.Y) Dim pt2 As Point2d = New Point2d(center.X +(rad1 + lwt / 2),center.Y) Dim pline As Polyline = New Polyline() pline.AddVertexAt(0, pt1, 1.0, lwt, lwt) pline.AddVertexAt(1, pt2, 1.0, lwt, lwt) pline.AddVertexAt(2, pt1, 0.0, lwt, lwt) pline.Closed = True { Dim db As Database = HostApplicationServices.WorkingDatabase Dim tm As AcDb.TransactionManager = db.TransactionManager Imports (Transaction tr = tm.StartTransaction()) { Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite), BlockTableRecord) btr.AppendEntity(pline) tr.AddNewlyCreatedDBObject(pline, True) tr.Commit() } } Catch ex As Autodesk.AutoCAD.Runtime.Exception ed.WriteMessage(ex.StackTrace) End Try End Sub ~'J'~ Quote Link to comment Share on other sites More sharing options...
Jozi68 Posted October 14, 2009 Author Share Posted October 14, 2009 Thank you Fixo, it works beautifully. Quote Link to comment Share on other sites More sharing options...
fixo Posted October 14, 2009 Share Posted October 14, 2009 Glad if that helps Cheers ~'J'~ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.