随着图形变得越来越复杂,可以重命名对象以保持名称有意义或避免与插入或附着的其他图形中的名称发生冲突。属性用于获取当前名称或更改命名对象的名称。 可以重命名除 AutoCAD 保留的对象之外的任何命名对象,例如图层 0 或“连续”线型。 名称最多可包含 255 个字符。除了字母和数字之外,名称还可以包含空格(尽管AutoCAD会删除直接出现在名称前后的空格)以及Microsoft®Windows®或AutoCAD未用于其他目的的任何特殊字符。不能使用的特殊字符包括小于号和大于号 (< >)、正斜杠和反斜杠 (/ \)、引号 (“)、冒号 (:)、分号 (;)、问号 (?)、逗号 (,)、星号 (*)、竖线 (|)、等号 (=) 和单引号 (')。也不能使用通过 Unicode 字体创建的特殊字符。 重命名图层本示例创建图层“0”的副本,并将新图层重命名为“MyLayer”。 VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices <CommandMethod("RenameLayer")> _ Public Sub RenameLayer() '' Get the current document and database Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database '' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() '' Returns the layer table for the current database Dim acLyrTbl As LayerTable acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, _ OpenMode.ForWrite) '' Clone layer 0 (copy it and its properties) as a new layer Dim acLyrTblRec As LayerTableRecord acLyrTblRec = acTrans.GetObject(acLyrTbl("0"), _ OpenMode.ForRead).Clone() '' Change the name of the cloned layer acLyrTblRec.Name = "MyLayer" '' Add the cloned layer to the Layer table and transaction acLyrTbl.Add(acLyrTblRec) acTrans.AddNewlyCreatedDBObject(acLyrTblRec, True) '' Save changes and dispose of the transaction acTrans.Commit() End Using End Sub C#using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; [CommandMethod("RenameLayer")] public static void RenameLayer() { // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Returns the layer table for the current database LayerTable acLyrTbl; acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite) as LayerTable; // Clone layer 0 (copy it and its properties) as a new layer LayerTableRecord acLyrTblRec; acLyrTblRec = acTrans.GetObject(acLyrTbl["0"], OpenMode.ForRead).Clone() as LayerTableRecord; // Change the name of the cloned layer acLyrTblRec.Name = "MyLayer"; // Add the cloned layer to the Layer table and transaction acLyrTbl.Add(acLyrTblRec); acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true); // Save changes and dispose of the transaction acTrans.Commit(); } } |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )
GMT+8, 2024-5-19 15:01
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.