02-02 控制AutoCAD环境(二) 控制图形窗口(3)使用命名视图
来源:互联网 发布:sketch mac 最新版本 编辑:程序博客网 时间:2024/05/02 07:46
3、Use Named Views使用命名视图
You can name and save a view you want to reuse. When you no longer need the view, you can remove it.
我们可以对想要重复使用的视图进行命名并保存,当不再需要这个视图时,可以将其删除。
Named views are stored in the View table, one of the named symbol tables in a drawing database. A named view is created with the Add method to add a new view to the View table. When you add the new named view to the View table, a default model space view is created.
命名视图存储在View表里,View表是图形数据库里的一个命名符号表。命名视图通过用Add方法将新视图添加到View表来创建。当我们往View表添加新的命名视图时,会生成一个默认的模型空间视图。
You name the view when you create it. The name of the view can be up to 255 characters long and contain letters, digits, and the special characters dollar sign ($), hyphen (-), and underscore (_).
在创建视图时对其命名。视图的名称可以至多含255个字符,包括字母、数字及特殊字符中的美元符号($)、连字符(-)、下划线(_)。
A named view can be removed from the View table by simply use the Erase method of the ViewTableRecord object you want to remove.
通过调用想要删除的ViewTableRecord对象的Erase方法,可以将命名视图从View表中删除。
Add a named view and set it current 添加命名视图并将其设置为当前视图
The following example adds a named view to the drawing and sets it current.
下面的例子为图形添加一个命名视图并将其设置为当前视图。
VB.NET
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"
Dim 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)
' 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打开View表,读
ViewTable acViewTbl;
acViewTbl = acTrans.GetObject(acCurDb.ViewTableId,
OpenMode.ForRead) as ViewTable;
// Check to see if the named view 'View1' exists
//检查命名视图View1是否存在
if (acViewTbl.Has("View1") == false)
{
// Open the View table for write打开View表,写
acViewTbl.UpgradeOpen();
// Create a new View table record and name the view 'View1'
// 新建一个View表记录并命名为View1
ViewTableRecord acViewTblRec = new ViewTableRecord();
acViewTblRec.Name = "View1";
// Add the new View table record to the View table and the transaction
//添加到View表及事务
acViewTbl.Add(acViewTblRec);
acTrans.AddNewlyCreatedDBObject(acViewTblRec, true);
// Set 'View1' current置View1为当前视图
acDoc.Editor.SetCurrentView(acViewTblRec);
// Commit the changes提交事务
acTrans.Commit();
}
// Dispose of the transaction处置事务,回收内存
}
}
VBA/ActiveX Code Reference 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
Erase a named view 删除命名视图
The following example erases a named view from the drawing.
下面的例子从图形中删除一个命名视图。
VB.NET
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
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
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从View表删除命名视图
acViewTblRec.Erase();
// Commit the changes提交修改
acTrans.Commit();
}
// Dispose of the transaction
}
}
VBA/ActiveX Code Reference 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
- 02-02 控制AutoCAD环境(二) 控制图形窗口(3)使用命名视图
- 02-02 控制AutoCAD环境(二) 控制图形窗口(4)使用平铺视口
- 02-02 控制AutoCAD环境(二) 控制图形窗口(2)缩放和平移当前视图
- 02-02 控制AutoCAD环境(二) 控制图形窗口(1)设置文档窗口的位置和大小
- 02-02 控制AutoCAD环境(二) 控制图形窗口(5)更新文档窗口的几何信息
- 02-01 控制AutoCAD环境(一) 控制应用程序窗口
- 02-05 控制AutoCAD环境(五) 设置AutoCAD选项
- 02-09 控制AutoCAD环境(九) 访问AutoCAD命令行
- 02-03 控制AutoCAD环境(三) 创建、打开、保存和关闭图形
- 02-07 控制AutoCAD环境(七) 精确制图
- 02-08 控制AutoCAD环境(八) 提示用户输入
- 02-04 控制AutoCAD环境(四) 锁定和解锁文档
- 02-06 控制AutoCAD环境(六) 设置和返回系统变量
- 控制Dialog的窗口大小(自定义Dialog视图)
- Linux下使用SSH和VNC实现图形化远程控制(Ubuntu 9.04环境)
- Processing 高效控制管理图形方法(二)
- 控制台窗口界面的编程控制(二)
- C++命名控制(static和namespace的使用)
- java笔试中常见的一些基础题
- Android学习之Android广播机制
- 学习另一门语言
- linux中.o,.a,.o,.so文件的意义和编程实现
- Spring2.5 + Struts1 的整合
- 02-02 控制AutoCAD环境(二) 控制图形窗口(3)使用命名视图
- 一个LINUX狂人的语录[转]
- HP DV3000系列 XP驱动下载!
- uboot移植文档(一) - xgc94418297的日志 - 网易博客
- C语言宏定义使用技巧
- 一个关于Media Player 跨iPhone版本的问题
- [小说连载]张小庆,在路上(9)- 上地,第二个项目
- socket编程的最简单实例 - linux系统编程及驱动开发 - 小超嵌入式工作室 嵌入式开发学习交流论坛 XC-STC XC2440技术支持 - Powered by Discuz!
- fread读文件读取不全解决方法