该方法在图形中将保存的图层状态从一个名称重命名为另一个名称。以下代码将 ColorLinetype 图层设置重命名为 OldColorLinetype。RenameLayerState VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices <CommandMethod("RenameLayerState")> _ Public Sub RenameLayerState() '' Get the current document Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acLyrStMan As LayerStateManager acLyrStMan = acDoc.Database.LayerStateManager Dim sLyrStName As String = "ColorLinetype" Dim sLyrStNewName As String = "OldColorLinetype" If acLyrStMan.HasLayerState(sLyrStName) = True And _ acLyrStMan.HasLayerState(sLyrStNewName) = False Then acLyrStMan.RenameLayerState(sLyrStName, sLyrStNewName) End If End Sub C#using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; [CommandMethod("RenameLayerState")] public static void RenameLayerState() { // Get the current document Document acDoc = Application.DocumentManager.MdiActiveDocument; LayerStateManager acLyrStMan; acLyrStMan = acDoc.Database.LayerStateManager; string sLyrStName = "ColorLinetype"; string sLyrStNewName = "OldColorLinetype"; if (acLyrStMan.HasLayerState(sLyrStName) == true && acLyrStMan.HasLayerState(sLyrStNewName) == false) { acLyrStMan.RenameLayerState(sLyrStName, sLyrStNewName); } } VBA/ActiveX 代码参考Sub RenameLayerState()
Dim oLSM As AcadLayerStateManager
Set oLSM = ThisDrawing.Application. _
GetInterfaceObject("AutoCAD.AcadLayerStateManager.24")
oLSM.SetDatabase ThisDrawing.Database
oLSM.Rename "ColorLinetype", "OldColorLinetype"
End Sub
|
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:07
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.