Message 1 of 2
View Table

Not applicable
04-19-2011
05:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good Morning,
I have a simple program that when run checks if a given view is in the View Table for a drawing, if it is it will load it by default. The program works fine when it checks for the view. However the problem I am running into is that it does not change to the view afterwards. Any thoughts? Code below.
<code>
[CommandMethod("def")]
static public void DefViewLoad() // This method can have any name
{
//Set current application session
AcadApplication app;
app = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
// Get current DWG Database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acDB = acDoc.Database;
//Set Editor to save typing
Editor ed = acDoc.Editor;
//Start Transaction to play with DWG.
using (Transaction acTran = acDB.TransactionManager.StartTransaction())
{
//Open current drawing layer table listing and read.
ViewTable acVT;
acVT = acTran.GetObject(acDB.ViewTableId, OpenMode.ForRead) as ViewTable;
ViewTableRecord acVTRec = new ViewTableRecord();
if (acVT.Has("test")==true)
{
ed.WriteMessage("test works");
acVTRec.Name = "test";
ed.SetCurrentView(acVTRec);
}
acTran.Commit();
}
ed.Regen();
}
}
}
</code>
I have a simple program that when run checks if a given view is in the View Table for a drawing, if it is it will load it by default. The program works fine when it checks for the view. However the problem I am running into is that it does not change to the view afterwards. Any thoughts? Code below.
<code>
[CommandMethod("def")]
static public void DefViewLoad() // This method can have any name
{
//Set current application session
AcadApplication app;
app = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
// Get current DWG Database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acDB = acDoc.Database;
//Set Editor to save typing
Editor ed = acDoc.Editor;
//Start Transaction to play with DWG.
using (Transaction acTran = acDB.TransactionManager.StartTransaction())
{
//Open current drawing layer table listing and read.
ViewTable acVT;
acVT = acTran.GetObject(acDB.ViewTableId, OpenMode.ForRead) as ViewTable;
ViewTableRecord acVTRec = new ViewTableRecord();
if (acVT.Has("test")==true)
{
ed.WriteMessage("test works");
acVTRec.Name = "test";
ed.SetCurrentView(acVTRec);
}
acTran.Commit();
}
ed.Regen();
}
}
}
</code>