工具类
class CircleJig : EntityJig
{
private Point3d m_CenterPt;
private double m_Radius = 100.0;
public CircleJig(Vector3d normal)
: base(new Circle())
{
((Circle)Entity).Center = m_CenterPt;
((Circle)Entity).Normal = normal;
((Circle)Entity).Radius = m_Radius;
}
protected override bool Update()
{
((Circle)Entity).Center = m_CenterPt;
((Circle)Entity).Radius = m_Radius;
return true;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions optJig = new JigPromptPointOptions("\n请指定圆的圆心或用右键修改半径");
optJig.Keywords.Add("100");
optJig.Keywords.Add("200");
optJig.Keywords.Add("300");
optJig.UserInputControls = UserInputControls.Accept3dCoordinates;
PromptPointResult resJig = prompts.AcquirePoint(optJig);
Point3d curPt = resJig.Value;
if (resJig.Status == PromptStatus.Cancel)
{
return SamplerStatus.Cancel;
}
if (resJig.Status == PromptStatus.Keyword)
{
switch (resJig.StringResult)
{
case "100":
m_Radius = 100;
return SamplerStatus.NoChange;
case "200":
m_Radius = 200;
return SamplerStatus.NoChange;
case "300":
m_Radius = 300;
return SamplerStatus.NoChange;
}
}
if (m_CenterPt != curPt)
{
m_CenterPt = curPt;
return SamplerStatus.OK;
}
else
{
return SamplerStatus.NoChange;
}
}
public Entity getEntity()
{
return Entity;
}
}
调用
[CommandMethod("shiyann")]
public void shiyann()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Matrix3d mt = ed.CurrentUserCoordinateSystem;
Vector3d normal = mt.CoordinateSystem3d.Zaxis;
CircleJig circleJig = new CircleJig(normal);
for (;;)
{
PromptResult resJig = ed.Drag(circleJig);
if (resJig.Status == PromptStatus.Cancel)
{
return;
}
if (resJig.Status == PromptStatus.OK)
{
Entity en = circleJig.getEntity();
addToModelSpace(db,en);
break;
}
}
}
其它工具
public ObjectId addToModelSpace(Database db, Entity ent)
{
ObjectId entId;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
entId = btr.AppendEntity(ent);
trans.AddNewlyCreatedDBObject(ent, true);
trans.Commit();
}
return entId;
}