可实现效果如下(对象捕捉F3需打开,否则效果不好):
public class CircleJig : EntityJig
{
public static void DraCJig()
{
PromptPointResult ppr = Z.ed.GetPoint("a");
if (ppr.Value == null) return;
Point3d pt = ppr.Value;
CircleJig circle = new CircleJig(pt);
Polyjig poly = new Polyjig(pt);
for (; ; )
{
PromptResult resJig = Z.ed.Drag(circle);//拖动圆
if (resJig.Status == PromptStatus.Cancel)
{
return;
}
if (resJig.Status == PromptStatus.OK) //确定, 则将圆添加到数据库
// if (resJigpl.Status == PromptStatus.OK)
{
Z.db.AddEntityToModeSpace(circle.GetEntity());//画圆
break;
}
return;
}
for (; ; )//画完圆继续jig线,不需要可注释
{
PromptResult resJigpl = Z.ed.Drag(poly);//拖动线
if (resJigpl.Status == PromptStatus.Cancel)// 放弃, 则退出.
{
return;
}
if (resJigpl.Status == PromptStatus.OK) //确定, 则将线添加到数据库
{
Z.db.AddEntityToModeSpace(poly.Updata());//画多段线
break;
}
return;
}
}
// private Point3d jCenter; // 圆心
private double jRadius; // 半径
public CircleJig(Point3d center)
: base(new Circle()) // 继承父类Circle的属性
{
((Circle)Entity).Center = center; // Entity 转化为Cirecle 对象 复制center
}
// 用于更新图像对象 这里更新属性时无需使用事务处理
protected override bool Update()
{
if (jRadius > 0)
{
((Circle)Entity).Radius = jRadius;
}
return true;
}
// 这个函数的作用是当鼠标在屏幕上移动时 就会被调用 实现这个函数时 一般是用它改变图形的属性 我们在这个类定义的属性
protected override SamplerStatus Sampler(JigPrompts prompts)
{
// 声明拖拽类jig提示信息
JigPromptPointOptions jppo = new JigPromptPointOptions("\n 请指定圆上的一个点");
char space = (char)32;
jppo.Keywords.Add("U");
jppo.Keywords.Add(space.ToString());
jppo.UserInputControls = UserInputControls.Accept3dCoordinates;
jppo.Cursor = CursorType.RubberBand;
jppo.BasePoint = ((Circle)Entity).Center;
jppo.UseBasePoint = true;
// 获取拖拽时鼠标的位置状态
PromptPointResult ppr = prompts.AcquirePoint(jppo);
jRadius = ppr.Value.GetDistanceBetweenTwoPoint(((Circle)Entity).Center);
return SamplerStatus.NoChange; // 继续移动 循环检测
}
public Entity GetEntity()
{
return Entity;
}
}
public class Polyjig : Autodesk.AutoCAD.EditorInput.DrawJig
{
public Point3d location;
public Point3d basePoint;
public Polyline polyine = new Polyline();
public Plane plane = new Plane();
public int index;
public static void DrawPLJig()
{
PromptPointResult ppr = Z.ed.GetPoint("a");
if (ppr.Value == null) return;
Point3d pt = ppr.Value;
Polyjig poly = new Polyjig(pt);
for (; ; )
{
PromptResult resJigpl = Z.ed.Drag(poly);//拖动线
if (resJigpl.Status == PromptStatus.Cancel) // 放弃, 则退出.
{
return;
}
if (resJigpl.Status == PromptStatus.OK) //确定, 则将线添加到数据库
{
Z.db.AddEntityToModeSpace(poly.Updata());//画多段线
break;
}
return;
}
}
public Polyjig(Point3d basept)
{
location = basept;
basePoint = basept;
polyine.AddVertexAt(0, basePoint.Convert2d(plane), 0, 0, 0);
polyine.AddVertexAt(1, location.Convert2d(plane), 0, 0, 0);
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
var opts = new JigPromptPointOptions("\n 输入下一个点");
opts.UserInputControls = (UserInputControls.Accept3dCoordinates |
UserInputControls.NoZeroResponseAccepted
| UserInputControls.NoNegativeResponseAccepted);
var res = prompts.AcquirePoint(opts);
if (res.Value != location)
{
location = res.Value;
}
else
{
return SamplerStatus.NoChange;
}
if (res.Status == PromptStatus.Cancel)
{
return SamplerStatus.Cancel;
}
else
{
return SamplerStatus.OK;
}
}
protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
{
Updata();
draw.Geometry.Draw(polyine);
return true;
}
public Polyline Updata()
{
index = polyine.NumberOfVertices - 1;