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

来源:互联网 发布:mysql 昨天0点到24点 编辑:程序博客网 时间:2024/05/01 07:49
 

Use Layers, Colors, and Linetypes使用图层、颜色和线型

Layers are like transparent overlays on which you organize and group different kinds of drawing information. The objects you create have properties including layers, colors, and linetypes. Color helps you distinguish similar elements in your drawings, and linetypes help you differentiate easily between different drafting elements, such as centerlines or hidden lines. Organizing layers and objects on layers makes it easier to manage the information in your drawings.

图层就像透明覆层,在上面我们可以组织各种不同的图形信息。我们创建的对象均拥有图层、颜色和线型等属性。颜色用于区分图形中的相似元素;线型,像中心线或隐藏线,用于区分不同的绘图元素。组织好图层及图层上的对象能使管理图形信息更容易。

For more information about this topic, see “Control the Properties of Objects” in theAutoCAD User's Guide.

本主题的更多内容,见AutoCAD用户指南中的“控制对象属性”。

 

Topics in this section本节内容:

·         Work with Layers使用图层

·         Work with Colors使用颜色

·         Work with Linetypes使用线型

 

1、Work with Layers 使用图层

You are always drawing on a layer. It may be the default layer or a layer you create and name yourself. Each layer has an associated color and linetype among other properties. For example, you can create a layer on which you draw only centerlines and assign the color blue and the linetype CENTER to that layer. Then, whenever you want to draw centerlines you can switch to that layer and start drawing.

我们总是在图层上绘图,可能是在默认图层上,或者是在自己创建并命名的图层上。每个图层都有与之关联的颜色和线型,以及其他属性。 例如,我们可以创建一个图层并将其颜色设置为蓝色、将其线型设置为CENTER,这样我们就只能在该图层上画中心线。之后,每当要绘制中心线时,我们就可以切换到这个图层 并开始绘制。

All layers and linetypes are stored in separate symbol tables. Layers are kept within the Layers table, and linetypes are kept within the Linetypes table.

所有的图层和线型存储在单独的符号表里。图层保存在Layers表里,线型保存在Linetypes表里。

For more information about working with layers, see “Work with Layers” in theAutoCAD User's Guide.

关于使用图层的更多内容,见见AutoCAD用户指南中的“使用图层”。

Topics in this section本小节内容:

·         Sort Layers and Linetypes 检索图层和线型

·         Create and Name Layers 创建并命名图层

·         Make a Layer Current 将图层设置为当前

·         Turn Layers On and Off 打开和关闭图层

·         Freeze and Thaw Layers 冻结和解冻图层

·         Lock and Unlock Layers 锁定和解锁图层

·         Assign Color to a Layer 指定图层颜色

·         Assign a Linetype to a Layer 指定图层线型

·         Erase Layers 删除图层

 

1.1、Sort Layers and Linetypes 检索图层和线型

You can iterate through the Layers and Linetypes tables to find all the layers and linetypes in a drawing.

我们可以遍历Layers表和Linetypes表,来找到图形中的所有图层和线型。

Iterate through the Layers table 遍历Layers表

The following code iterates through the Layers table to gather the names of all the layers in the drawing. The names are then displayed in a message box.

下面的代码遍历Layers表来收集图形中所有图层的名称,然后将名称显示在信息框内。

VB.NET

Imports Autodesk.AutoCAD.Runtime

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.DatabaseServices

 

<CommandMethod("DisplayLayerNames")> _

Public Sub DisplayLayerNames()

  '' 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 sLayerNames As String = ""

 

      For Each acObjId As ObjectId In acLyrTbl

          Dim acLyrTblRec As LayerTableRecord

          acLyrTblRec = acTrans.GetObject(acObjId, _

                                          OpenMode.ForRead)

 

          sLayerNames = sLayerNames & vbLf & acLyrTblRec.Name

      Next

 

      Application.ShowAlertDialog("The layers in this drawing are: " & _

                                  sLayerNames)

 

      '' Dispose of the transaction

  End Using

End Sub

 

C#

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

 

[CommandMethod("DisplayLayerNames")]

public static void DisplayLayerNames()

{

  // 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 sLayerNames = "";

 

      foreach (ObjectId acObjId in acLyrTbl)

      {

          LayerTableRecord acLyrTblRec;

          acLyrTblRec = acTrans.GetObject(acObjId,

                                          OpenMode.ForRead) as LayerTableRecord;

 

          sLayerNames = sLayerNames + "\n" + acLyrTblRec.Name;

      }

 

      Application.ShowAlertDialog("The layers in this drawing are: " +

                                  sLayerNames);

 

      // Dispose of the transaction关闭事务

  }

}

 

VBA/ActiveX Code Reference

Sub DisplayLayerNames()

    Dim layerNames As String

    Dim entry As AcadLayer

    layerNames = ""

 

    For Each entry In ThisDrawing.Layers

        layerNames = layerNames + entry.Name + vbCrLf

    Next

 

    MsgBox "The layers in this drawing are: " + _

           vbCrLf + layerNames

End Sub

 

原创粉丝点击