马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
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;
- [Autodesk.AutoCAD.Runtime.CommandMethod("listViews")]
- 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());
- }
-
}
|