For my next trick, I've been trying to get to grips with groups.
As part of the process of creating the new layouts, my method for creating what we call a "Keyplan" involved, (In VBA at least) creating a group and then zooming to that group. (The same way I would do it if I were doing so manually.)
I've been wondering this morning whether I need to bother doing that any more. given the following code (originally from
Kean): -
// (the usual "usings" are required in order to make this work: -
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
// This is a special one:
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
[CommandMethod ("ZE")]
public static void ZoomToEntity(ObjectId GroupId)
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
//Extract the extents of the "group"
Extents3d ext;
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
Entity ent = (Entity)tr.GetObject(GroupId, OpenMode.ForRead);
ext = ent.GeometricExtents;
tr.Commit();
}
ext.TransformBy(ed.CurrentUserCoordinateSystem.Inverse());
// Call our helper function
private static void ZoomWin(Editor ed, Point3d min, Point3d max)
{
Point2d min2d = new Point2d(min.X, min.Y);
Point2d max2d = new Point2d(max.X, max.Y);
ViewTableRecord view = new ViewTableRecord();
view.CenterPoint = min2d + ((max2d - min2d) / 2.0);
view.Height = max2d.Y - min2d.Y;
view.Width = max2d.X - min2d.X;
ed.SetCurrentView(view);
}
I guess I would just need to create an object (in my case a user-defined rectangle) and then store the ObjectId of said Object for when it's time to create the viewports.