Here is a sample code to create a viewport with UCS Follow turned on. This should ensure that the viewport displays the plan based on the UCS whenever it changes.
[CommandMethod("CreateVP",
CommandFlags.NoTileMode)]
public void CreateVPMethod()
{
Document doc
= Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectId layoutId = LayoutManager.Current.GetLayoutId
(LayoutManager.Current.CurrentLayout);
using (Transaction Tx
= db.TransactionManager.StartTransaction())
{
Layout LayoutDest
= Tx.GetObject(layoutId, OpenMode.ForRead)
as Layout;
BlockTableRecord btrDest
= Tx.GetObject(LayoutDest.BlockTableRecordId,
OpenMode.ForWrite) as BlockTableRecord;
ViewportTable vt
= Tx.GetObject(db.ViewportTableId, OpenMode.ForRead)
as ViewportTable;
ViewportTableRecord vtr
= Tx.GetObject(vt["*Active"], OpenMode.ForRead)
as ViewportTableRecord;
UcsTable ucsTbl
= Tx.GetObject(db.UcsTableId, OpenMode.ForRead)
as UcsTable;
if (vtr != null)
{
Autodesk.AutoCAD.DatabaseServices.Viewport vpNew
= new Autodesk.AutoCAD.DatabaseServices.Viewport();
vpNew.SetDatabaseDefaults();
vpNew.Width = 6.0;
vpNew.Height = 5.0;
vpNew.CenterPoint = new Point3d(3.25, 3, 0);
if (ucsTbl.Has("myucs"))
{
ObjectId ucsId = ucsTbl["myucs"];
vpNew.SetUcs(ucsId);
}
vpNew.StandardScale
= StandardScaleType.Scale1To1;
vpNew.ViewCenter = vtr.CenterPoint;
vpNew.ViewHeight = vtr.Height;
vpNew.ViewDirection = vtr.ViewDirection;
vpNew.ViewTarget = vtr.Target;
vpNew.TwistAngle = vtr.ViewTwist;
vpNew.UcsPerViewport = true ;
vpNew.UcsFollowModeOn = true ;
vpNew.GridOn = true ;
vpNew.GridFollow = true ;
btrDest.AppendEntity(vpNew);
Tx.AddNewlyCreatedDBObject(vpNew, true );
vpNew.On = true ;
}
Tx.Commit();
}
}