您始终在活动图层上绘图。激活图层时,将在该图层上创建新对象。如果将其他图层设置为活动状态,则会为您创建的任何新对象分配该新活动图层并使用其颜色和线型。如果图层处于冻结状态,则无法将其设置为活动状态。 要使图层处于活动状态,请使用对象的属性或 CLAYER 系统变量。例如:ClayerDatabase 使图层在数据库中成为当前本示例使用属性设置通过对象的图层电流。DatabaseClayer VB.NETImports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
<CommandMethod("SetLayerCurrent")> _
Public Sub SetLayerCurrent()
'' 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()
'' Open the Layer table for read
Dim acLyrTbl As LayerTable
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, _
OpenMode.ForRead)
Dim sLayerName As String = "Center"
If acLyrTbl.Has(sLayerName) = True Then
'' Set the layer Center current
acCurDb.Clayer = acLyrTbl(sLayerName)
'' Save the changes
acTrans.Commit()
End If
'' Dispose of the transaction
End Using
End Sub
C#using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
[CommandMethod("SetLayerCurrent")]
public static void SetLayerCurrent()
{
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Layer table for read
LayerTable acLyrTbl;
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
OpenMode.ForRead) as LayerTable;
string sLayerName = "Center";
if (acLyrTbl.Has(sLayerName) == true)
{
// Set the layer Center current
acCurDb.Clayer = acLyrTbl[sLayerName];
// Save the changes
acTrans.Commit();
}
// Dispose of the transaction
}
}
VBA/ActiveX 代码参考ThisDrawing.ActiveLayer = ThisDrawing.Layers("Center")
使用 CLAYER 系统变量使图层保持当前状态本示例使用 CLAYER 系统变量设置层电流。 VB.NETApplication.SetSystemVariable("CLAYER", "Center")
C#Application.SetSystemVariable("CLAYER", "Center");
VBA/ActiveX 代码参考ThisDrawing.SetVariable "CLAYER", "Center" 相关概念父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 09:47
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.