1
Display / Zoom in a new database
« on: August 30, 2012, 07:10:44 AM »
Hi,
A little piece of code in C#.Net in order to define the default view/zoom in a drawing which is not active in the editor. For example, it's useful for a newly created database than you create and save without activating it in the editor.
I share this code because i've spent some hours to find it. Most of the examples we found always concern an open and active document and use the editor.
The 2 main tricks are to use the viewporttablerecord whose name is "*Active" and the method database.UpdateExt() once the viewporttablerecord has been modified.
(Code adapted from this dicussion: http://forums.autodesk.com/t5/NET/Zoom-Extents-on-new-Database/td-p/2070825/highlight/true/page/2 )
A little piece of code in C#.Net in order to define the default view/zoom in a drawing which is not active in the editor. For example, it's useful for a newly created database than you create and save without activating it in the editor.
I share this code because i've spent some hours to find it. Most of the examples we found always concern an open and active document and use the editor.
The 2 main tricks are to use the viewporttablerecord whose name is "*Active" and the method database.UpdateExt() once the viewporttablerecord has been modified.
(Code adapted from this dicussion: http://forums.autodesk.com/t5/NET/Zoom-Extents-on-new-Database/td-p/2070825/highlight/true/page/2 )
Code: [Select]
try
{
if (sideDb.TileMode == true)// Then 'Model
{
ViewportTable vpt = sideTr.GetObject(sideDb.ViewportTableId, OpenMode.ForRead) as ViewportTable;
ViewportTableRecord vptr = sideTr.GetObject(vpt["*Active"], OpenMode.ForWrite) as ViewportTableRecord;
Point2d pmin = Point2d.Origin;
Point2d pmax = new Point2d(3000, 1500);
vptr.CenterPoint = (pmin + (pmax - pmin) / 2);
vptr.Height = (pmax.Y - pmin.Y);
vptr.Width = (pmax.X - pmin.X);
sideDb.UpdateExt(true);
}
}
catch { }