後で再使用するビューには、名前を付けて保存できます。そのビューが必要なくなれば、削除できます。
名前の付いたビューは、図面データベース内の名前の付いたシンボル テーブルの 1 つである、ビュー テーブルに格納されます。名前の付いたビューは Add メソッドを使用して作成され、ビュー テーブルに新しいビューが追加されます。ビュー テーブルに新しい名前の付いたビューを追加すると、既定のモデル空間ビューが作成されます。
ビューを作成するときは名前を付ける必要があります。ビューの名前の長さは、文字、数字、特殊文字のドル記号($)、ハイフン(-)、アンダースコア(_) を含めて 255 文字までです。
名前の付いたビューをビュー テーブルから削除するには、削除する ViewTableRecord オブジェクトの Erase メソッドを使用します。
次の例では、名前の付いたビューを図面に追加して、現在のビューに設定します。
Imports 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 acViewTbl.UpgradeOpen() '' 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
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 acViewTbl.UpgradeOpen(); // 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 } }
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
次の例では、名前の付いたビューを図面から削除します。
Imports 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 acViewTbl.UpgradeOpen() '' 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
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 acViewTbl.UpgradeOpen(); // 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 } }
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