\n works whereas a space doesn't because you need to enter rather than spacebar the actual cad command.
I have been pretty confused about these multiple vports. Didn't matter I did I couldn't get a consistant result.
Here are a coulple of findings
1) Each viewport maintains it's own dcs,
the position of the viewport on the screen has no relationship to the dcs and it vport center.
2) Height and width are taken from bottom left corner and if their ratios are incorrect the cenerpoint will be wrong.
Below is getting close but I cannot get the width height relationship for an isoview.
In a new drawing- draw a circle with a diameter of 1.
On zooming extents the properties window reads height 1.0089 width=1.3637
Now switch to sw isoview and height=1.0522 width=8.533, the latter doesn't make much sense
[CommandMethod ( "4V")]
public void Create4VPorts()
{
String sName = "4Left";
Database db=HostApplicationServices.WorkingDatabase;
Document doc=acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
acadApp.SetSystemVariable("Tilemode", 1);
ViewportTableRecord vp;
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
ViewportTable vt =tr.GetObject(
db.ViewportTableId, OpenMode.ForRead, false) as ViewportTable;
if (vt.Has(sName)) goto skip;
Vector3d viewdir = new Vector3d(-1, -1, 1);
vp = tr.GetObject(vt["*Active"],
OpenMode.ForRead) as ViewportTableRecord;
//dcs
Matrix3d ucs = ed.CurrentUserCoordinateSystem;
Point3d viewctr = ((Point3d)acadApp.GetSystemVariable("VIEWCTR")).TransformBy(ucs);
ViewTableRecord vtr = ed.GetCurrentView();
Vector3d vd = vtr.ViewDirection.GetNormal();
Plane pn = new Plane(vtr.Target, vd);
Matrix3d dcs = Matrix3d.WorldToPlane(pn);
if (vtr.ViewTwist != 0)
dcs = dcs * Matrix3d.Rotation(-vtr.ViewTwist, vtr.ViewDirection, vtr.Target);
dcs = dcs.Inverse();
Point3d cenDcs=viewctr.TransformBy(dcs);
Point2d cen = new Point2d(cenDcs.X, cenDcs.Y);
double vpHeight = ((double)acadApp.GetSystemVariable("VIEWSIZE"));
Point2d screensize = (Point2d)acadApp.GetSystemVariable("Screensize");
double ratio = screensize.X / screensize.Y, widthoverht = 0.0;
double vpWidth = vpHeight*ratio,Wd=0;
vt.UpgradeOpen();
for (int i = 0; i <= 3; i++)
{
vp = new ViewportTableRecord();
vp.Name = sName;
//bottom 0, 0, -1 //Left -1, 0, 0 //back 0, 1, 0
//se 1, -1, 1 //nw 1, 1, 1 //ne -1, 1, 1
switch (i)
{
case 0: //Southwest
vp.LowerLeftCorner = new Point2d(0.333, 0);
vp.UpperRightCorner = new Point2d(1, 1);
vp.SetUcs(OrthographicView.TopView);
widthoverht = ((vpWidth * 2 / 3) / vpHeight);
vp.Height = vpWidth / widthoverht;
Wd = vpWidth * 2;
break;
case 1: //Topview
vp.LowerLeftCorner = new Point2d(0, 0.666);
vp.UpperRightCorner = new Point2d(0.333, 1);
vp.SetUcs(vp.ViewOrthographic);
widthoverht = ((vpWidth / 3) / (vpHeight/3));
vp.Height = vpWidth / widthoverht;
Wd = vpWidth;
viewdir = new Vector3d(0, 0, 1);
break;
case 2: //Rightview
vp.LowerLeftCorner = new Point2d(0, 0.333);
vp.UpperRightCorner = new Point2d(0.333, 0.666);
vp.SetUcs(OrthographicView.RightView);
widthoverht = ((vpWidth / 3) / (vpHeight / 3));
vp.Height = vpWidth / widthoverht;
Wd = vpWidth;
viewdir = new Vector3d(1, 0, 0);
cen = new Point2d(cenDcs.Y, 0);
break;
case 3: //frontview
vp.LowerLeftCorner = new Point2d(0, 0);
vp.UpperRightCorner = new Point2d(0.333, 0.333);
vp.SetUcs(OrthographicView.FrontView);
widthoverht = ((vpWidth / 3) / (vpHeight / 3));
vp.Height = vpWidth / widthoverht;
Wd = vpWidth;
viewdir = new Vector3d(0, -1, 0);
cen = new Point2d(cenDcs.X, 0);
break;
default:
break;
}
vp.CenterPoint = cen;
vp.ViewDirection = viewdir;
vp.Width = Wd;
vt.Add(vp);
db.TransactionManager.AddNewlyCreatedDBObject(vp, true);
}
tr.Commit();
}
skip:
doc.SendStringToExecute("-vports Restore 4left\n", false, true, true);
}