通过数据库将线型设置为当前的
 
 

This example sets a linetype current through the Database object with the Celtype property.

下列通过 Database 对象的 Celtype 属性将一个线型设置成当前线型。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
 
<CommandMethod("SetLinetypeCurrent")> _
Public Sub SetLinetypeCurrent()
  '' 获得当前文档和数据库   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) = True Then
          ''设置Center 线型为当前线型  Set the linetype Center current
          acCurDb.Celtype = acLineTypTbl(sLineTypName)
 
          ''保存修改   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("SetLinetypeCurrent")]
public static void SetLinetypeCurrent()
{
  // 获得当前文档和数据库   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) == true)
      {
          // Set the linetype Center current
          acCurDb.Celtype = acLineTypTbl[sLineTypName];
 
          // Save the changes
          acTrans.Commit();
      }
 
      // Dispose of the transaction
  }
}
VBA/ActiveX 代码参考