03-05 创建和编辑AutoCAD实体(五) 使用图层、颜色和线型(1)使用图层(1-3)

来源:互联网 发布:数据库关系表 编辑:程序博客网 时间:2024/05/16 18:04
 

1.3、Make a Layer Current将图层设为当前图层

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。详见下面的示例代码:

Make a layer current through the database 通过数据库将图层设为当前图层

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

          '' 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 Code Reference

ThisDrawing.ActiveLayer = ThisDrawing.Layers("Center")

 

Make a layer current with the CLAYER system variable 使用系统变量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 Code Reference

ThisDrawing.SetVariable "CLAYER", "Center"

 

 

原创粉丝点击