将图层设置为当前的
 
 

You are always drawing on the active layer. When you make a layer active, you create new objects on that layer. If you make a different layer active, any new objects you create is assigned that new active layer and uses its color and linetype. You cannot make a layer active if it is frozen.

用户总是在活动的图层上绘制图形。图层置为活动时,用户可以在该图层上创建新对象。如果将其他图层置为活动图层,所有新对象都将在新的活动图层上创建并且使用该图层的颜色和线型。如果图层被冻结,则不能将其置为活动。

To make a layer active, use the Clayer property of the Database object or the CLAYER system variable. For example:

若要使一个图层成为活动的,请使用 Database 对象的 Clayer 属性或 CLAYER 系统变量。例如:

通过数据库将一个图层设置为当前图层

This example sets a layer current through the Database object with the Clayer property.

本示例通过 Database 对象的 Clayer 属性将一个图层设置为当前图层。

VB.NET

Imports 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
          '' 设置 Center 层为当前图层   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 代码参考

使用 CLAYER 系统变量设置一个图层为当前图层

This example sets a layer current with the CLAYER system variable.

本例使用 CLAYER 系统变量设置一个图层为当前图层。

VB.NET

Application.SetSystemVariable("CLAYER", "Center")

C#

Application.SetSystemVariable("CLAYER", "Center");
VBA/ActiveX 代码参考