【发布时间】:2015-11-14 15:21:30
【问题描述】:
我似乎无法解释为什么下面的代码没有缩放到所选对象的中心。通常,对象位于屏幕中心附近但位于屏幕顶部。
我可以使用doc.SendStringToExecute("ZOOM " + "OBJECT " + objIdString + " ", true, false, false);,我可以得到我想要的东西,但不是在我想要的时候,因为调用来自无模式对话框上的按钮,然后是最后一个发生的事件。
我的目标是逐步浏览并缩放中心对象选择,并以是/否暂停以继续每个对象之间的对话。
我们将不胜感激。
public static void ZoomObjects(ObjectIdCollection idCol)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
using (ViewTableRecord view = ed.GetCurrentView())
{
Matrix3d WCS2DCS = Matrix3d.PlaneToWorld(view.ViewDirection);
WCS2DCS = Matrix3d.Displacement(view.Target - Point3d.Origin) * WCS2DCS;
WCS2DCS = Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) * WCS2DCS;
WCS2DCS = WCS2DCS.Inverse();
Entity ent = (Entity)tr.GetObject(idCol[0], OpenMode.ForRead);
Entity ent1 = (Entity)tr.GetObject(idCol[0], OpenMode.ForWrite);
Extents3d ext = ent.GeometricExtents;
for (int i = 1; i < Enerflex.SpoolTagFindForm1.idColCnt; i++)
{
ent = (Entity)tr.GetObject(idCol[i], OpenMode.ForRead);
ent1 = (Entity)tr.GetObject(idCol[i], OpenMode.ForWrite);
Extents3d tmp = ent.GeometricExtents;
ext.AddExtents(tmp);
ent1.Color = Color.FromColor(System.Drawing.Color.Red);
}
ext.TransformBy(WCS2DCS);
view.Width = ext.MaxPoint.X - ext.MinPoint.X;
view.Height = ext.MaxPoint.Y - ext.MinPoint.Y;
view.CenterPoint = new Point2d((ext.MaxPoint.X + ext.MinPoint.X) / 2.0, (ext.MaxPoint.Y + ext.MinPoint.Y) / 2.0);
ed.SetCurrentView(view);
tr.Commit();
}
}
【问题讨论】:
标签: zooming