- 积分
- 7540
- 明经币
- 个
- 注册时间
- 2006-4-6
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
用lisp可以轻松实现。
(defun C:TEST (/ DATA GRR GRRPT KEY LOOP OBJECTS PT SS)
;; by carrot1983 2020.09.29
(setq SS (ssget))
(setq PT (getpoint "\n指定点:"))
(setq OBJECTS (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))))
(setq LOOP t)
(while LOOP
(setq GRR (grread t 15 2))
(setq KEY (car GRR))
(setq DATA (cadr GRR))
(cond ((= KEY 5)
(setq GRRPT DATA)
(foreach O OBJECTS
(vla-move O (vlax-3d-point PT) (vlax-3d-point GRRPT))
)
) ;_移动
((or (= KEY 3) (= DATA 13))
(setq LOOP NIL)
) ;_3左击 13回车 表示确认
((member KEY '(12 25))
(redraw)
(setq LOOP NIL)
) ;_右键退出
)
(setq PT GRRPT) ;_新基点
)
(redraw)
)
如果用drawjig 怎么修改以下代码。实现不显示原对象?
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();
}
}
}
|
|