- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
namespace ZoomObjectSample
{
public class Zoom
{
[CommandMethod("ZO")]
public void ZO()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionResult psr = ed.GetSelection();
if (psr.Status != PromptStatus.OK)
return;
ObjectIdCollection idCol = new ObjectIdCollection(psr.Value.GetObjectIds());
ZoomObjects(idCol);
}
private 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);
Extents3d ext = ent.GeometricExtents;
for (int i = 1; i < idCol.Count; i++)
{
ent = (Entity)tr.GetObject(idCol[i], OpenMode.ForRead);
Extents3d tmp = ent.GeometricExtents;
ext.AddExtents(tmp);
}
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();
}
}
}
} |
|