When you are defining layers, linetypes provide another way to convey visual information. A linetype is a repeating pattern of dashes, dots, and blank spaces you can use to distinguish the purpose of one line from another.
当你定义图层后,线型提供了另外的一种方法来表达视觉信息。线型是一个由虚线、点和空格重复组成的图案,可以用来区分线条的用途。
The linetype name and definition describe the particular dash-dot sequence, the relative lengths of dashes and blank spaces, and the characteristics of any included text or shapes.
线型名及其定义描述了特定的点划序列、虚线和空格的相对长度,以及任何包含的文字或形的特性。
Use the Linetype property to assign a linetype to a layer. This property takes the name of the linetype as input.
要指定图层线型,请使用 Linetype 特性。此特性需要输入线型的名称。
NoteBefore a linetype can be assigned to a layer it must be defined in the drawing first. For information on working with linetypes, see Work with Linetypes.
注意线型在被指定给图层之前必须首先在图形中被定义好。关于使用线型的更多的详细信息,请参见 使用线型.
The following example creates a new layer named "ABC" and assigns it the "Center" linetype.
下面的示例创建一个名字为“ABC”的新图层然后给它指定线型“Center”。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
<CommandMethod("SetLayerLinetype")> _
Public Sub SetLayerLinetype()
'' 获得当前文档和数据库 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 = "ABC"
Dim acLyrTblRec As LayerTableRecord
If acLyrTbl.Has(sLayerName) = False Then
acLyrTblRec = New LayerTableRecord()
''指定图层的名字 Assign the layer a name
acLyrTblRec.Name = sLayerName
'' 升级图层表为可写 Upgrade the Layer table for write
acLyrTbl.UpgradeOpen()
'' 追加新图层到层表和事务中 Append the new layer to the Layer table and the transaction
acLyrTbl.Add(acLyrTblRec)
acTrans.AddNewlyCreatedDBObject(acLyrTblRec, True)
Else
acLyrTblRec = acTrans.GetObject(acLyrTbl(sLayerName), _
OpenMode.ForRead)
End If
'' 以只读方式打开图层表 Open the Layer table for read
Dim acLinTbl As LinetypeTable
acLinTbl = acTrans.GetObject(acCurDb.LinetypeTableId, _
OpenMode.ForRead)
If acLinTbl.Has("Center") = True Then
'' 升级层表记录为可写 Upgrade the Layer Table Record for write
acLyrTblRec.UpgradeOpen()
''设置图层的线型 Set the linetype for the layer
acLyrTblRec.LinetypeObjectId = acLinTbl("Center")
End If
''保存更改并销毁事务 Save the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
[CommandMethod("SetLayerLinetype")]
public static void SetLayerLinetype()
{
// 获得当前文档和数据库 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 = "ABC";
LayerTableRecord acLyrTblRec;
if (acLyrTbl.Has(sLayerName) == false)
{
acLyrTblRec = new LayerTableRecord();
// Assign the layer a name
acLyrTblRec.Name = sLayerName;
// Upgrade the Layer table for write
acLyrTbl.UpgradeOpen();
// Append the new layer to the Layer table and the transaction
acLyrTbl.Add(acLyrTblRec);
acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);
}
else
{
acLyrTblRec = acTrans.GetObject(acLyrTbl[sLayerName],
OpenMode.ForRead) as LayerTableRecord;
}
// 以只读方式打开图层表 Open the Layer table for read
LinetypeTable acLinTbl;
acLinTbl = acTrans.GetObject(acCurDb.LinetypeTableId,
OpenMode.ForRead) as LinetypeTable;
if (acLinTbl.Has("Center") == true)
{
// Upgrade the Layer Table Record for write
acLyrTblRec.UpgradeOpen();
// Set the linetype for the layer
acLyrTblRec.LinetypeObjectId = acLinTbl["Center"];
}
// Save the changes and dispose of the transaction
acTrans.Commit();
}
}