c# example for accessing the view table
c# example for accessing the view table问题:
Is there a c# (sharp) example that shows how to access views from .NET?
解答:
Here is an example that outputs the names of the views to the command line.
// Namespaces in AutoCAD assemblies
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
public void listViews()
{
Database db;
Transaction tr;
ViewTable vt;
ViewTableRecord vtRec;
Autodesk.AutoCAD.EditorInput.Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
try
{
db = HostApplicationServices.WorkingDatabase;
using(tr = db.TransactionManager.StartTransaction())
{
using(vt = (ViewTable)tr.GetObject(db.ViewTableId, OpenMode.ForRead))
{
foreach(ObjectId id in vt)
{
vtRec = (ViewTableRecord)tr.GetObject(id, OpenMode.ForRead);
ed.WriteMessage("Name of View = " + vtRec.Name + "\n");
}
}
tr.Commit();
}
}
catch(System.Exception ex)
{
ed.WriteMessage(ex.ToString());
}
}
页:
[1]