Thanks cblais for the code. I needed to use it, but in order for this to work a myDB.UpdateExt(True) must be executed before retrieving the Extmax and Extmin values just as Tony Z stated on 9/20/07.
aks
I am trying change the code mentioned in here to use for paperspace.
I tried by changing the code as highlighted below and its not working.
Can anyone help me to show what I am doing wrong or any another way to zoom extent the paperspace of a document which is not active in the editor ?
/// <summary>
/// Sets a zoom extents of the Database model space
/// </summary>
/// <param name="db">The Database instance this method applies to.</param>
public static void ZoomExtents(this Database db)
{
db.TileMode = false;
Point2d scrSize = (Point2d)AcAp.GetSystemVariable("screensize");
double ratio = scrSize.X / scrSize.Y;
using (Transaction tr = db.TransactionManager.StartTransaction())
using (Line line = new Line(db.Pextmin, db.Pextmax))
{
ViewportTable vpt =
(ViewportTable)tr.GetObject(db.ViewportTableId, OpenMode.ForRead);
ViewportTableRecord vptr =
(ViewportTableRecord)tr.GetObject(vpt["*Active"], OpenMode.ForWrite);
Extents3d ext = line.GeometricExtents;
ext.TransformBy(vptr.WorldToEye());
Point2d pmin = new Point2d(ext.MinPoint.X, ext.MinPoint.Y);
Point2d pmax = new Point2d(ext.MaxPoint.X, ext.MaxPoint.Y);
double height = pmax.Y - pmin.Y;
double width = pmax.X - pmin.X;
if (width / height < ratio)
{
vptr.Height = height;
vptr.Width = height * ratio;
}
else
{
vptr.Width = width;
vptr.Height = width / ratio;
}
vptr.CenterPoint = pmin + (pmax - pmin) / 2.0;
tr.Commit();
}
}
I don't know if you can easily adapt the code you posted or not, because it is dependent on a number of things that require the document and the paperspace layout to be active (for example, the SCREENSIZE system variable, the *Active ViewportTableRecord, etc.). If the document is not active in the editor
I'm not suggesting it isn't possible to do, but given how the code is written, a great deal of it is dependent on the active document and layout.
Ajilal.Vijayan wrote:
I am trying change the code mentioned in here to use for paperspace.
I tried by changing the code as highlighted below and its not working.
Can anyone help me to show what I am doing wrong or any another way to zoom extent the paperspace of a document which is not active in the editor ?
/// <summary>
/// Sets a zoom extents of the Database model space
/// </summary>
/// <param name="db">The Database instance this method applies to.</param>
public static void ZoomExtents(this Database db)
{
db.TileMode = false;
Point2d scrSize = (Point2d)AcAp.GetSystemVariable("screensize");
double ratio = scrSize.X / scrSize.Y;
using (Transaction tr = db.TransactionManager.StartTransaction())
using (Line line = new Line(db.Pextmin, db.Pextmax))
{
ViewportTable vpt =
(ViewportTable)tr.GetObject(db.ViewportTableId, OpenMode.ForRead);
ViewportTableRecord vptr =
(ViewportTableRecord)tr.GetObject(vpt["*Active"], OpenMode.ForWrite);
Extents3d ext = line.GeometricExtents;
ext.TransformBy(vptr.WorldToEye());
Point2d pmin = new Point2d(ext.MinPoint.X, ext.MinPoint.Y);
Point2d pmax = new Point2d(ext.MaxPoint.X, ext.MaxPoint.Y);
double height = pmax.Y - pmin.Y;
double width = pmax.X - pmin.X;
if (width / height < ratio)
{
vptr.Height = height;
vptr.Width = height * ratio;
}
else
{
vptr.Width = width;
vptr.Height = width / ratio;
}
vptr.CenterPoint = pmin + (pmax - pmin) / 2.0;
tr.Commit();
}
}
Thanks for the reply @ActivistInvestor
In modelsapce this code works with the the documents which are not active in the editor.
So I tried with _db.GetViewports(true) and used the first objectid of that collection to get the Viewport.
This seems to be working.
ObjectIdCollection vpcol = _db.GetViewports(true); if (vpcol.Count > 0)//Check whether the layout is initialiazed { Viewport vport = (Viewport)_tr.GetObject(vpcol[0], OpenMode.ForWrite); vport.ViewHeight = (width / height) < ratio ? height : width / ratio; vport.ViewCenter = pmin + (pmax - pmin) / 2.0; }
Can't find what you're looking for? Ask the community or share your knowledge.