活动视口在“视口”(Viewports) 表格中由名为“*Active”的记录表示,该记录不是唯一的名称,因为当前显示在“模型”选项卡上的所有切片视口都命名为“*Active”。显示的每个平铺视口都分配了一个编号。活动视口的编号可通过以下方式获取:
拥有活动视口后,您可以控制其显示属性,启用视口的绘图辅助工具(如栅格和捕捉)以及视口本身的大小。平铺视口由两个角点定义:左下角和右上角点。and 属性表示视口在显示器上的图形位置。LowerLeftCornerUpperRightCorner 单个平铺视口配置的左下角为 (0,0),右上角为 (1,1)。绘图窗口的左下角始终由 (0,0) 点表示,右上角由 (1,1) 表示,无论“模型”选项卡上的平铺视口数如何。当显示多个平铺视口时,左下角和右上角会有所不同,但一个视口的左下角为 (0,0),另一个视口的右上角为 (1,1) 这些属性定义如下(以四向拆分为例): 在此示例中:
创建具有两个水平窗口的新平铺视口配置以下示例创建两个水平视口作为命名视口配置,并重新定义活动显示。 VB.NETImports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.Geometry <CommandMethod("CreateModelViewport")> _ Public Sub CreateModelViewport() '' 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 Viewport table for read Dim acVportTbl As ViewportTable acVportTbl = acTrans.GetObject(acCurDb.ViewportTableId, OpenMode.ForRead) '' Check to see if the named view 'TEST_VIEWPORT' exists If (acVportTbl.Has("TEST_VIEWPORT") = False) Then '' Open the View table for write acTrans.GetObject(acCurDb.ViewportTableId, OpenMode.ForWrite) '' Add the new viewport to the Viewport table and the transaction Using acVportTblRecLwr As ViewportTableRecord = New ViewportTableRecord() acVportTbl.Add(acVportTblRecLwr) acTrans.AddNewlyCreatedDBObject(acVportTblRecLwr, True) '' Name the new viewport 'TEST_VIEWPORT' and assign it to be '' the lower half of the drawing window acVportTblRecLwr.Name = "TEST_VIEWPORT" acVportTblRecLwr.LowerLeftCorner = New Point2d(0, 0) acVportTblRecLwr.UpperRightCorner = New Point2d(1, 0.5) '' Add the new viewport to the Viewport table and the transaction Using acVportTblRecUpr As ViewportTableRecord = New ViewportTableRecord() acVportTbl.Add(acVportTblRecUpr) acTrans.AddNewlyCreatedDBObject(acVportTblRecUpr, True) '' Name the new viewport 'TEST_VIEWPORT' and assign it to be '' the upper half of the drawing window acVportTblRecUpr.Name = "TEST_VIEWPORT" acVportTblRecUpr.LowerLeftCorner = New Point2d(0, 0.5) acVportTblRecUpr.UpperRightCorner = New Point2d(1, 1) '' To assign the new viewports as the active viewports, the '' viewports named '*Active' need to be removed and recreated '' based on 'TEST_VIEWPORT'. '' Step through each object in the symbol table For Each acObjId As ObjectId In acVportTbl '' Open the object for read Dim acVportTblRec As ViewportTableRecord acVportTblRec = acTrans.GetObject(acObjId, _ OpenMode.ForRead) '' See if it is one of the active viewports, and if so erase it If (acVportTblRec.Name = "*Active") Then acTrans.GetObject(acObjId, OpenMode.ForWrite) acVportTblRec.Erase() End If Next '' Clone the new viewports as the active viewports For Each acObjId As ObjectId In acVportTbl '' Open the object for read Dim acVportTblRec As ViewportTableRecord acVportTblRec = acTrans.GetObject(acObjId, _ OpenMode.ForRead) '' See if it is one of the active viewports, and if so erase it If (acVportTblRec.Name = "TEST_VIEWPORT") Then Dim acVportTblRecClone As ViewportTableRecord acVportTblRecClone = acVportTblRec.Clone() '' Add the new viewport to the Viewport table and the transaction acVportTbl.Add(acVportTblRecClone) acVportTblRecClone.Name = "*Active" acTrans.AddNewlyCreatedDBObject(acVportTblRecClone, True) End If Next '' Update the display with the new tiled viewports arrangement acDoc.Editor.UpdateTiledViewportsFromDatabase() End Using 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; using Autodesk.AutoCAD.Geometry; [CommandMethod("CreateModelViewport")] public static void CreateModelViewport() { // Get the current database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Viewport table for read ViewportTable acVportTbl; acVportTbl = acTrans.GetObject(acCurDb.ViewportTableId, OpenMode.ForRead) as ViewportTable; // Check to see if the named view 'TEST_VIEWPORT' exists if (acVportTbl.Has("TEST_VIEWPORT") == false) { // Open the View table for write acTrans.GetObject(acCurDb.ViewportTableId, OpenMode.ForWrite); // Add the new viewport to the Viewport table and the transaction using (ViewportTableRecord acVportTblRecLwr = new ViewportTableRecord()) { acVportTbl.Add(acVportTblRecLwr); acTrans.AddNewlyCreatedDBObject(acVportTblRecLwr, true); // Name the new viewport 'TEST_VIEWPORT' and assign it to be // the lower half of the drawing window acVportTblRecLwr.Name = "TEST_VIEWPORT"; acVportTblRecLwr.LowerLeftCorner = new Point2d(0, 0); acVportTblRecLwr.UpperRightCorner = new Point2d(1, 0.5); // Add the new viewport to the Viewport table and the transaction using (ViewportTableRecord acVportTblRecUpr = new ViewportTableRecord()) { acVportTbl.Add(acVportTblRecUpr); acTrans.AddNewlyCreatedDBObject(acVportTblRecUpr, true); // Name the new viewport 'TEST_VIEWPORT' and assign it to be // the upper half of the drawing window acVportTblRecUpr.Name = "TEST_VIEWPORT"; acVportTblRecUpr.LowerLeftCorner = new Point2d(0, 0.5); acVportTblRecUpr.UpperRightCorner = new Point2d(1, 1); // To assign the new viewports as the active viewports, the // viewports named '*Active' need to be removed and recreated // based on 'TEST_VIEWPORT'. // Step through each object in the symbol table foreach (ObjectId acObjId in acVportTbl) { // Open the object for read ViewportTableRecord acVportTblRec; acVportTblRec = acTrans.GetObject(acObjId, OpenMode.ForRead) as ViewportTableRecord; // See if it is one of the active viewports, and if so erase it if (acVportTblRec.Name == "*Active") { acTrans.GetObject(acObjId, OpenMode.ForWrite); acVportTblRec.Erase(); } } // Clone the new viewports as the active viewports foreach (ObjectId acObjId in acVportTbl) { // Open the object for read ViewportTableRecord acVportTblRec; acVportTblRec = acTrans.GetObject(acObjId, OpenMode.ForRead) as ViewportTableRecord; // See if it is one of the active viewports, and if so erase it if (acVportTblRec.Name == "TEST_VIEWPORT") { ViewportTableRecord acVportTblRecClone; acVportTblRecClone = acVportTblRec.Clone() as ViewportTableRecord; // Add the new viewport to the Viewport table and the transaction acVportTbl.Add(acVportTblRecClone); acVportTblRecClone.Name = "*Active"; acTrans.AddNewlyCreatedDBObject(acVportTblRecClone, true); } } // Update the display with the new tiled viewports arrangement acDoc.Editor.UpdateTiledViewportsFromDatabase(); } } // Commit the changes acTrans.Commit(); } // Dispose of the transaction } } VBA/ActiveX 代码参考Sub CreateModelViewport() ' Create a new viewport Dim vportObj As AcadViewport Set vportObj = ThisDrawing.Viewports.Add("TEST_VIEWPORT") ' Split vportObj into 2 horizontal windows vportObj.Split acViewport2Horizontal ' Now set vportObj to be the active viewport ThisDrawing.ActiveViewport = vportObj End Sub 相关概念父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-7 20:11
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.