- 积分
- 7540
- 明经币
- 个
- 注册时间
- 2006-4-6
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2020-9-29 15:53:10
|
显示全部楼层
应该不是代码的问题。以下这段代码是gile 大神写的。
public class MoveJig : DrawJig
{
protected Point3d basePt;
protected Entity[] entities;
public MoveJig(Entity[] entities, Point3d basePt)
{
this.entities = entities;
this.basePt = basePt;
}
public Matrix3d Displacement { get; private set; }
protected override SamplerStatus Sampler(JigPrompts prompts)
{
var options = new JigPromptPointOptions("\nSecond point: ");
options.UserInputControls = UserInputControls.Accept3dCoordinates;
options.BasePoint = basePt;
options.UseBasePoint = true;
options.Cursor = CursorType.RubberBand;
var result = prompts.AcquirePoint(options);
if (basePt.DistanceTo(result.Value) < Tolerance.Global.EqualPoint)
return SamplerStatus.NoChange;
Displacement = Matrix3d.Displacement(result.Value - basePt);
return SamplerStatus.OK;
}
protected override bool WorldDraw(WorldDraw draw)
{
var geo = draw.Geometry;
if (geo != null)
{
geo.PushModelTransform(Displacement);
foreach (var ent in entities) geo.Draw(ent);
geo.PopModelTransform();
}
return true;
}
}
[CommandMethod("TEST", CommandFlags.UsePickSet)]
public void Test()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var selection = ed.GetSelection();
if (selection.Status != PromptStatus.OK) return;
var ptResult = ed.GetPoint("\nBase point: ");
if (ptResult.Status != PromptStatus.OK) return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Entity[] entities = new Entity[selection.Value.Count];
for (int i = 0; i < selection.Value.Count; i++)
{
entities[i] = (Entity)tr.GetObject(selection.Value[i].ObjectId, OpenMode.ForRead);
}
var jig = new MoveJig(entities, ptResult.Value.TransformBy(ed.CurrentUserCoordinateSystem));
var result = ed.Drag(jig);
if (result.Status == PromptStatus.OK)
{
foreach (var ent in entities)
{
ent.UpgradeOpen();
ent.TransformBy(jig.Displacement);
}
}
tr.Commit();
}
}
} |
|