線種とは、ダッシュ、ドット、スペースの繰り返しパターンです。複雑な線種とは、記号パターンを繰り返したものです。線種を使用するには、最初にその線種を図面にロードしなければなりません。線種を図面にロードするには、線種定義が LIN ライブラリ ファイルに存在しなければなりません。線種を図面にロードするには、Database オブジェクトの LoadLineTypeFile メンバー メソッドを使用します。
次の例は、acad.lin ファイルから線種「CENTER」をロードします。この線種が既に存在していたり、このファイルが存在しない場合は、メッセージが表示されます。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
<CommandMethod("LoadLinetype")> _
Public Sub LoadLinetype()
'' 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 Linetype table for read
Dim acLineTypTbl As LinetypeTable
acLineTypTbl = acTrans.GetObject(acCurDb.LinetypeTableId, _
OpenMode.ForRead)
Dim sLineTypName As String = "Center"
If acLineTypTbl.Has(sLineTypName) = False Then
'' Load the Center Linetype
acCurDb.LoadLineTypeFile(sLineTypName, "acad.lin")
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("LoadLinetype")]
public static void LoadLinetype()
{
// 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 Linetype table for read
LinetypeTable acLineTypTbl;
acLineTypTbl = acTrans.GetObject(acCurDb.LinetypeTableId,
OpenMode.ForRead) as LinetypeTable;
string sLineTypName = "Center";
if (acLineTypTbl.Has(sLineTypName) == false)
{
// Load the Center Linetype
acCurDb.LoadLineTypeFile(sLineTypName, "acad.lin");
}
// Save the changes and dispose of the transaction
acTrans.Commit();
}
}
Sub LoadLinetype()
On Error GoTo ERRORHANDLER
Dim linetypeName As String
linetypeName = "CENTER"
' Load "CENTER" line type from acad.lin file
ThisDrawing.Linetypes.Load linetypeName, "acad.lin"
Exit Sub
ERRORHANDLER:
MsgBox Err.Description
End Sub