public class FixViewports
{
[CommandMethod("FixViewports")]
public static void FixViewportsCommand()
{
var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
try
{
if (!db.TileMode)
{
ed.WriteMessage("Must be in Model Space");
return;
}
using (var tr = db.TransactionManager.StartTransaction())
{
var vpTable = db.ViewportTableId.GetObject(OpenMode.ForWrite) as ViewportTable;
foreach (var vpObjId in vpTable)
{
var vpTblRec = vpObjId.GetObject(OpenMode.ForRead) as ViewportTableRecord;
ed.WriteMessage("ViewportName: " + vpTblRec.Name);
if (vpTblRec.Name.Equals("*Active", StringComparison.OrdinalIgnoreCase) ||
vpTblRec.Name.Equals("Civil 3D Section Editor Viewport Configuration Snapshot", StringComparison.OrdinalIgnoreCase))
{
ed.WriteMessage("Deleting Viewport: " + vpTblRec.Name);
vpTblRec.UpgradeOpen();
vpTblRec.Erase();
}
}
using (var vpRightTblRec = new ViewportTableRecord() { Name = "*Active", LowerLeftCorner = new Point2d(0, 0), UpperRightCorner = new Point2d(0.5, 1) })
{
vpTable.Add(vpRightTblRec);
tr.AddNewlyCreatedDBObject(vpRightTblRec, true);
}
using (var vpLeftTblRec = new ViewportTableRecord() { Name = "*Active", LowerLeftCorner = new Point2d(0.5, 0), UpperRightCorner = new Point2d(1, 1) })
{
vpTable.Add(vpLeftTblRec);
tr.AddNewlyCreatedDBObject(vpLeftTblRec, true);
}
vpTable.DowngradeOpen();
ed.UpdateTiledViewportsFromDatabase();
tr.Commit();
}
}
catch (System.Exception ex)
{
ed.WriteErrorMessage("Error: " + ex.Message);
}
}
}
A place to put reminders on how to do things or commands that I will use rarely, but are useful to know.
Ad
Thursday, August 08, 2019
Ghost Viewport
Sometimes a ghost viewport will show up after using the Corridor Section Command. I haven't found a way to remove the viewport via the User Interface. Here is some c#.NET Code that appears to get rid of the bad viewport.
Subscribe to:
Posts (Atom)