Hi,
What about doing things in the reverse order.
Typically we define the page setup first so that we can get the paper size and the paper margins to create the viewport.
Here's a little snippet which shows how to create a viewport (as the 'Fit' option of the _MVIEW command).
private static Viewport CreateFitViewport(Transaction tr, Layout layout)
{
Point2d
minPt = layout.PlotPaperMargins.MinPoint,
maxPt = layout.PlotPaperMargins.MaxPoint,
pSize = layout.PlotPaperSize;
double width, height;
if ((int)layout.PlotRotation % 2 == 0)
{
width = pSize.X - maxPt.X - minPt.X;
height = pSize.Y - maxPt.Y - minPt.Y;
}
else
{
width = pSize.Y - maxPt.Y - minPt.Y;
height = pSize.X - maxPt.X - minPt.X;
}
var btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);
var viewport = new Viewport();
viewport.Width = width;
viewport.Height = height;
viewport.CenterPoint = new Point3d(width / 2.0, height / 2.0, 0.0);
btr.AppendEntity(viewport);
tr.AddNewlyCreatedDBObject(viewport, true);
return viewport;
}