您可以命名和保存要重用的视图。当您不再需要该视图时,可以将其删除。 命名视图存储在视图表中,该表是工程图数据库中的命名符号表之一。使用向 View 表添加新视图的方法创建命名视图。将新的命名视图添加到“视图”(View) 表时,将创建缺省模型空间视图。Add 您可以在创建视图时为其命名。视图的名称长度最多为 255 个字符,包含字母、数字和特殊字符美元符号 ($)、连字符 (-) 和下划线 (_)。 只需使用要删除的对象的方法,即可从 View 表中删除命名视图。EraseViewTableRecord 添加命名视图并将其设置为当前视图以下示例将命名视图添加到图形中,并将其设置为当前视图。 VB.NETImports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime <CommandMethod("CreateNamedView")> _ Public Sub CreateNamedView() '' Get the current database Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database '' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() '' Open the View table for read Dim acViewTbl As ViewTable acViewTbl = acTrans.GetObject(acCurDb.ViewTableId, OpenMode.ForRead) '' Check to see if the named view 'View1' exists If (acViewTbl.Has("View1") = False) Then '' Open the View Table for write acTrans.GetObject(acCurDb.ViewTableId, OpenMode.ForWrite) '' Create a new View table record and name the view "View1" Using acViewTblRec As ViewTableRecord = New ViewTableRecord() acViewTblRec.Name = "View1" '' Add the new View table record to the View table and the transaction acViewTbl.Add(acViewTblRec) acTrans.AddNewlyCreatedDBObject(acViewTblRec, True) '' Set 'View1' current acDoc.Editor.SetCurrentView(acViewTblRec) End Using '' Commit the changes acTrans.Commit() End If '' Dispose of the transaction End Using End Sub C#using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Runtime; [CommandMethod("CreateNamedView")] public static void CreateNamedView() { // Get the current database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the View table for read ViewTable acViewTbl; acViewTbl = acTrans.GetObject(acCurDb.ViewTableId, OpenMode.ForRead) as ViewTable; // Check to see if the named view 'View1' exists if (acViewTbl.Has("View1") == false) { // Open the View table for write acTrans.GetObject(acCurDb.ViewTableId, OpenMode.ForWrite); // Create a new View table record and name the view 'View1' using (ViewTableRecord acViewTblRec = new ViewTableRecord()) { acViewTblRec.Name = "View1"; // Add the new View table record to the View table and the transaction acViewTbl.Add(acViewTblRec); acTrans.AddNewlyCreatedDBObject(acViewTblRec, true); // Set 'View1' current acDoc.Editor.SetCurrentView(acViewTblRec); } // Commit the changes acTrans.Commit(); } // Dispose of the transaction } } VBA/ActiveX 代码参考Sub CreateNamedView() ' Add a named view to the views collection Dim viewObj As AcadView Set viewObj = ThisDrawing.Views.Add("View1") ThisDrawing.ActiveViewport.SetView viewObj End Sub 擦除命名视图以下示例从图形中删除命名视图。 VB.NETImports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime <CommandMethod("EraseNamedView")> _ Public Sub EraseNamedView() '' Get the current database Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database '' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() '' Open the View table for read Dim acViewTbl As ViewTable acViewTbl = acTrans.GetObject(acCurDb.ViewTableId, OpenMode.ForRead) '' Check to see if the named view 'View1' exists If (acViewTbl.Has("View1") = True) Then '' Open the View table for write acTrans.GetObject(acCurDb.ViewTableId, OpenMode.ForWrite) '' Get the named view Dim acViewTblRec As ViewTableRecord acViewTblRec = acTrans.GetObject(acViewTbl("View1"), OpenMode.ForWrite) '' Remove the named view from the View table acViewTblRec.Erase() '' Commit the changes acTrans.Commit() End If '' Dispose of the transaction End Using End Sub C#using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Runtime; [CommandMethod("EraseNamedView")] public static void EraseNamedView() { // Get the current database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the View table for read ViewTable acViewTbl; acViewTbl = acTrans.GetObject(acCurDb.ViewTableId, OpenMode.ForRead) as ViewTable; // Check to see if the named view 'View1' exists if (acViewTbl.Has("View1") == true) { // Open the View table for write acTrans.GetObject(acCurDb.ViewTableId, OpenMode.ForWrite); // Get the named view ViewTableRecord acViewTblRec; acViewTblRec = acTrans.GetObject(acViewTbl["View1"], OpenMode.ForWrite) as ViewTableRecord; // Remove the named view from the View table acViewTblRec.Erase(); // Commit the changes acTrans.Commit(); } // Dispose of the transaction } } VBA/ActiveX 代码参考Sub EraseNamedView() On Error Resume Next Dim viewObj As AcadView Set viewObj = ThisDrawing.Views("View1") If Err = 0 Then ' Delete the view viewObj.Delete End If End Sub 相关概念父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-7 19:50
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.