VB。net:创建油炸圈饼
任何人都知道如何使用创建甜甜圈。net(非lisp)?试试这个
C#:
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。净值:
<CommandMethod("DON")> _
Shared PublicSub 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'~ 谢谢你,菲索,它工作得很好。 如果这有帮助的话,我很高兴
干杯
~'J'~
页:
[1]