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

来源:互联网 发布:ubuntu vscode调试php 编辑:程序博客网 时间:2024/05/16 23:42

3、Workwith Linetypes使用线型

A linetype is a repeating pattern ofdashes, dots, and blank spaces. A complex linetype is a repeating pattern ofsymbols. To use a linetype you must first load it into your drawing. A linetypedefinition must exist in a LIN library file before a linetype can be loadedinto a drawing. To load a linetype into your drawing, use the member method LoadLineTypeFile of a Database object.

线型是点、划和空格的重复图案。复杂的线型是各种符号的重复图案。要使用线型,需先将该线型加载到图形里。加载前,线型库文件(.LIN文件)里必须有该线型的定义。向图形加载线型使用Database对象的LoadLineTypeFile成员方法。

For more information about working withlinetypes, see “Overview of Linetypes” in theAutoCAD User's Guide.

关于使用线型的更多内容,见AutoCAD用户指南中的“线型概览”。

Note The linetypes used internally by AutoCAD should not beconfused with the hardware linetypes provided by some plotters. The two typesof dashed lines produce similar results. Donot use both types at the same time, however,because the results can be unpredictable.

注意:不要将 AutoCAD 内部使用的线型与某些绘图仪提供的硬件线型相混淆。这两种类型的虚线产生的效果相似。不要同时使用这两种类型,否则将产生不可预知的结果。

Load a linetype into AutoCAD 加载线型到AutoCAD

This example attempts to load the linetype“CENTER” from the acad.lin file. If the linetype already exists, or thefile does not exist, then a message is displayed.

本例视图从线型文件acad.lin加载线型“CENTER”,如果该线型已存在,或线型文件不存在,则显示消息。

VB.NET

ImportsAutodesk.AutoCAD.Runtime

ImportsAutodesk.AutoCAD.ApplicationServices

ImportsAutodesk.AutoCAD.DatabaseServices

 

<CommandMethod("LoadLinetype")>_

Public SubLoadLinetype()

  '' 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) = FalseThen

          '' Load the Center Linetype

         acCurDb.LoadLineTypeFile(sLineTypName, "acad.lin")

      End If

 

      '' Save the changes and dispose of thetransaction

      acTrans.Commit()

  End Using

End Sub

C#

usingAutodesk.AutoCAD.Runtime;

usingAutodesk.AutoCAD.ApplicationServices;

usingAutodesk.AutoCAD.DatabaseServices;

 

[CommandMethod("LoadLinetype")]

public static voidLoadLinetype()

{

  // 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加载线型Center

         acCurDb.LoadLineTypeFile(sLineTypName, "acad.lin");

      }

 

      // Save the changes and dispose of thetransaction

      acTrans.Commit();

  }

}

VBA/ActiveX Code Reference

Sub LoadLinetype()

    On Error GoTo ERRORHANDLER

 

    Dim linetypeName As String

    linetypeName = "CENTER"

 

    ' Load "CENTER" line type fromacad.lin file

    ThisDrawing.Linetypes.Load linetypeName,"acad.lin"

    Exit Sub

 

ERRORHANDLER:

    MsgBox Err.Description

End Sub



Topics in this section本节内容:

·        Make a Linetype Active 设置当前线型

·        Rename Linetypes 重命名线型

·        Delete Linetypes 删除线型

·        Change Linetype Descriptions 修改线型说明

·        Specify Linetype Scale 指定线型比例

 

3.1、Makea Linetype Active设置线型为活动

To use a linetype, you must make itactive. All newly created objects are drawn using the active linetype. Thereare two different methods for applying a linetype to an object: direct orinherited. You can directly assign a linetype to an object which overrides thelinetype assigned to the layer the object is on. Otherwise, an object inheritsthe linetype of the layer it is on by having its Linetype or LinetypeId property set to represent the ByLayerlinetype.

要使用线型,必须将其置为活动。所有新对象均使用活动线型绘制。对象的线型可由两种不同方法获得:直接指定或继承。可以直接给对象指定一个线型覆盖掉对象所在图层的线型。另外,对象可以继承其所在图层的线型,方法是将对象的Linetype属性或LinetypeId属性设置成代表ByLayer线型。

Note  Xref-dependent linetypes cannot be madeactive.

注意:不能将依赖外部参照的线型设置为活动线型。

There are three linetypes that exist ineach drawing: BYBLOCK, BYLAYER and CONTINUOUS. Each of these linetypes can beaccessed from the Linetype table object or using methods from theSymbolUtilityServices object. The following methods allow you to obtain theobject id for these default linetypes:

有三个线型存在于每个图形,他们是:BYBLOCK、 BYLAYER 和CONTINUOUS。这三个线型的每一个都可以从线型表对象访问,或使用SymbolUtilityServices对象的方法访问。下列方法允许我们获取这些默认线型的对象ID:

·        GetLinetypeByBlockId - Returns the object id for the BYBLOCKlinetype.返回BYBLOCK线型的对象ID;

·        GetLinetypeByLayerId - Returns the object id for the BYLAYERlinetype. 返回BYLAYER线型的对象ID;

·        GetLinetypeContinuousId - Returns the object id for the CONTINUOUSlinetype.返回CONTINUOUS线型的对象ID;

For more information about activating alinetype, see “Set the Current Linetype” in theAutoCAD User's Guide.

关于激活线型的更多内容,见AutoCAD用户指南中的“设置当前线型”。

Topics in this section本小节内容:

·        Assign a linetype to an object 为对象指定线型

·        Make a linetype current through the database 通过数据库设置当前线型

·        Make a linetype current with the CELTYPE system variable通过系统变量CELTYPE设置当前线型

 

3.1.1、Assigna linetype to an object 为对象指定线型

The following example creates a circle andassigns the “Center” linetype to it.

下面的例子创建一个圆并指定线型为“Center”。

VB.NET

ImportsAutodesk.AutoCAD.Runtime

ImportsAutodesk.AutoCAD.ApplicationServices

ImportsAutodesk.AutoCAD.DatabaseServices

ImportsAutodesk.AutoCAD.Geometry

 

<CommandMethod("SetObjectLinetype")>_

Public SubSetObjectLinetype()

  '' 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"

 

      IfacLineTypTbl.Has(sLineTypName) = False Then

         acCurDb.LoadLineTypeFile(sLineTypName, "acad.lin")

      End If

 

      '' Open the Block table for read

      Dim acBlkTbl As BlockTable

      acBlkTbl =acTrans.GetObject(acCurDb.BlockTableId, _

                                  OpenMode.ForRead)

 

      '' Open the Block table record Modelspace for write

      Dim acBlkTblRec As BlockTableRecord

      acBlkTblRec =acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _

                                      OpenMode.ForWrite)

 

      '' Create a circle object

      Dim acCirc As Circle = New Circle()

      acCirc.Center = New Point3d(2, 2, 0)

      acCirc.Radius = 1

      acCirc.Linetype = sLineTypName

 

      acBlkTblRec.AppendEntity(acCirc)

      acTrans.AddNewlyCreatedDBObject(acCirc,True)

 

      '' Save the changes and dispose of thetransaction

      acTrans.Commit()

  End Using

End Sub

C#

usingAutodesk.AutoCAD.Runtime;

usingAutodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

usingAutodesk.AutoCAD.Geometry;

 

[CommandMethod("SetObjectLinetype")]

public static voidSetObjectLinetype()

{

  // 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)

      {

         acCurDb.LoadLineTypeFile(sLineTypName, "acad.lin");

      }

 

      // Open the Block table for read

      BlockTable acBlkTbl;

      acBlkTbl =acTrans.GetObject(acCurDb.BlockTableId,

                                  OpenMode.ForRead) as BlockTable;

 

      // Open the Block table record Modelspace for write

      BlockTableRecord acBlkTblRec;

      acBlkTblRec =acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],

                                     OpenMode.ForWrite) as BlockTableRecord;

 

      // Create a circle object

      Circle acCirc = new Circle();

      acCirc.Center = new Point3d(2, 2, 0);

      acCirc.Radius = 1;

      acCirc.Linetype = sLineTypName;

 

      acBlkTblRec.AppendEntity(acCirc);

      acTrans.AddNewlyCreatedDBObject(acCirc,true);

 

      // Save the changes and dispose of thetransaction

      acTrans.Commit();

  }

}

VBA/ActiveX Code Reference

SubSetObjectLinetype()

    ' Load the Center linetype

    Dim linetypeName As String

    linetypeName = "Center"

 

    On Error Resume Next

    ThisDrawing.Linetypes.Load linetypeName,"acad.lin"

 

    ' Define the center point of the circle

    Dim centerPt(0 To 2) As Double

    centerPt(0) = 0: centerPt(1) = 3:centerPt(2) = 0

 

    ' Create a new circle and assign it the ACIvalue of 4

    Dim circleObj As AcadCircle

    Set circleObj =ThisDrawing.ModelSpace.AddCircle(centerPt, 1)

    circleObj.Linetype = linetypeName

 

    circleObj.Update

End Sub

 

3.1.2、Makea linetype current through the database通过数据库设置当前线型

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

本例通过Database对象的Celtype属性将线型设置为当前线型。

VB.NET

ImportsAutodesk.AutoCAD.Runtime

ImportsAutodesk.AutoCAD.ApplicationServices

ImportsAutodesk.AutoCAD.DatabaseServices

 

<CommandMethod("SetLinetypeCurrent")>_

Public SubSetLinetypeCurrent()

  '' 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) = TrueThen

          '' 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#

usingAutodesk.AutoCAD.Runtime;

usingAutodesk.AutoCAD.ApplicationServices;

usingAutodesk.AutoCAD.DatabaseServices;

 

[CommandMethod("SetLinetypeCurrent")]

public static voidSetLinetypeCurrent()

{

  // 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将Center线型设置为当前线型

          acCurDb.Celtype =acLineTypTbl[sLineTypName];

 

          // Save the changes保存修改

          acTrans.Commit();

      }

 

      // Dispose of the transaction关闭事务

  }

}

VBA/ActiveX Code Reference

ThisDrawing.ActiveLinetype= ThisDrawing.Linetypes.Item("Center")

 

3.1.3、Makea linetype current with the CELTYPE system variable 通过系统变量CELTYPE设置当前线型

This example sets a linetype current withthe CELTYPE system variable.

本例通过系统变量CELTYPE将线型设置为当前线型。

VB.NET

Application.SetSystemVariable("CELTYPE","Center")

C#

Application.SetSystemVariable("CELTYPE","Center");

VBA/ActiveX Code Reference

ThisDrawing.SetVariable"CELTYPE", "Center"

 

3.2、RenameLinetypes 重命名线型

To rename a linetype, use the Name property. When you rename a linetype, youare renaming only the linetype definition in your drawing. The name in the LINlibrary file is not updated to reflect the new name.

重命名线型使用Name属性。重命名一个线型时,我们只是重新命名了图形中的线型定义。线型库文件(.LIN文件)中的线型名称没有更新。

3.3、DeleteLinetypes删除线型

To delete a linetype, use the Erase method. You can delete a linetype at anytime during a drawing session; however, linetypes that cannot be deletedinclude BYLAYER, BYBLOCK, CONTINUOUS, the current linetype, a linetype in use,and xref-dependent linetypes. Also, linetypes referenced by block definitionscannot be deleted, even if they are not used by any objects.

删除一个线型使用Erase方法。可以在绘图过程的任何时候删除一个线型,不过,不能删除线型BYLAYER、BYBLOCK、CONTINUOUS及当前线型、依赖外部参考的线型。还有,块定义所引用的线型也不能删除,不管有没有对象使用。

For more information about deletinglinetypes, see “Set the Current Linetype” in theAutoCAD User's Guide.

更多关于删除线型的内容,见AutoCAD用户指南中的“设置当前线型”。

3.4、ChangeLinetype Descriptions修改线型说明

Linetypes can have a description associatedwith them. The description provides an ASCII representation of the linetype.You can assign or change a linetype description by using the AsciiDescription property.

线型可以有与之关联的说明文字。该说明文字提供了改线型的ASCII描述。我们可以使用AsciiDescription属性来设置或修改线型说明。

A linetype description can have up to 47characters. The description can be a comment or a series of underscores, dots,dashes, and spaces to show a simple representation of the linetype pattern.

线型说明最多47个字符。说明可以是一个注释,也可以使用一系列下划线、点、虚线和空格来简单地表示出线型图案。

Change the description of a linetype 修改线型说明

The following example changes thedescription of the current linetype.

下例演示如何修改当前线型的说明。

VB.NET

ImportsAutodesk.AutoCAD.Runtime

ImportsAutodesk.AutoCAD.ApplicationServices

ImportsAutodesk.AutoCAD.DatabaseServices

 

<CommandMethod("ChangeLinetypeDescription")>_

Public SubChangeLinetypeDescription()

  '' 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 record of thecurrent linetype for write

      Dim acLineTypTblRec AsLinetypeTableRecord

      acLineTypTblRec =acTrans.GetObject(acCurDb.Celtype, _

                                         OpenMode.ForWrite)

 

      '' Change the description of the currentlinetype

      acLineTypTblRec.AsciiDescription ="Exterior Wall"

 

      '' Save the changes and dispose of thetransaction

      acTrans.Commit()

  End Using

End Sub

C#

usingAutodesk.AutoCAD.Runtime;

usingAutodesk.AutoCAD.ApplicationServices;

usingAutodesk.AutoCAD.DatabaseServices;

 

[CommandMethod("ChangeLinetypeDescription")]

public static voidChangeLinetypeDescription()

{

  // 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 record of thecurrent linetype for write

      //以写打开当前线型的线型表记录

      LinetypeTableRecord acLineTypTblRec;

      acLineTypTblRec = acTrans.GetObject(acCurDb.Celtype,

                                         OpenMode.ForWrite) as LinetypeTableRecord;

 

      // Change the description of the currentlinetype修改当前线型的说明

      acLineTypTblRec.AsciiDescription ="Exterior Wall";

 

      // Save the changes and dispose of thetransaction保存修改关闭事务

      acTrans.Commit();

  }

}

VBA/ActiveX Code Reference

 

ThisDrawing.ActiveLinetype.Description= "Exterior Wall"

 

 

 

3.5、SpecifyLinetype Scale指定线型比例

You can specify the linetype scale forobjects you create. The smaller the scale, the more repetitions of the patternare generated per drawing unit. By default, AutoCAD uses a global linetypescale of 1.0, which is equal to one drawing unit. You can change the linetypescale for all drawing objects and attribute references.

我们可以指定所创建对象的线型比例。比例越小,每图形单位内生成的线型图案越多。默认情况下,AutoCAD使用全局线形比例1.0,等于一个图形单位。我们可以修改所有图形对象和属性参考的线型比例。

The CELTSCALE system variable sets thelinetype scale for newly created objects. LTSCALE system variable changes theglobal linetype scale of existing objects as well as new objects. The LinetypeScale property on an object is used to changethe linetype scale for an object. The linetype scale at which an object isdisplayed at is based on the an individual object’s linetype scale multipliedby the global linetype scale.

系统变量CELTSCALE用来给新创建的对象设置线型比例。系统变量LTSCALE用来修改已存在对象及新对象的全局线型比例。对象的LinetypeScale属性用来修改该对象的线型比例。对象显示的线型比例基于对象自己的线形比例乘以全局线形比例的结果。

For more information about linetypescales, see “Control Linetype Scale” in theAutoCAD User's Guide.

更多关于线型比例的内容,见AutoCAD用户指南中的“控制线型比例”。

Change the linetype scale for an object 修改对象的线型比例

VB.NET

ImportsAutodesk.AutoCAD.Runtime

ImportsAutodesk.AutoCAD.ApplicationServices

ImportsAutodesk.AutoCAD.DatabaseServices

ImportsAutodesk.AutoCAD.Geometry

 

<CommandMethod("SetObjectLinetypeScale")>_

Public SubSetObjectLinetypeScale()

  '' 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()

 

      '' Save the current linetype

      Dim acObjId As ObjectId = acCurDb.Celtype

 

      '' Set the global linetype scale

      acCurDb.Ltscale = 3

 

      '' Open the Linetype table for read

      Dim acLineTypTbl As LinetypeTable

      acLineTypTbl =acTrans.GetObject(acCurDb.LinetypeTableId, _

                                      OpenMode.ForRead)

 

      Dim sLineTypName As String ="Border"

 

      If acLineTypTbl.Has(sLineTypName) = FalseThen

          acCurDb.LoadLineTypeFile(sLineTypName,"acad.lin")

      End If

 

      '' Set the Border linetype current

      acCurDb.Celtype =acLineTypTbl(sLineTypName)

 

      '' Open the Block table for read

      Dim acBlkTbl As BlockTable

      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,_

                                  OpenMode.ForRead)

 

      '' Open the Block table record Modelspace for write

      Dim acBlkTblRec As BlockTableRecord

      acBlkTblRec =acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _

                                     OpenMode.ForWrite)

 

      '' Create a circle object and set itslinetype

      '' scale to half of full size

      Dim acCirc1 As Circle = New Circle()

      acCirc1.Center = New Point3d(2, 2, 0)

      acCirc1.Radius = 4

      acCirc1.LinetypeScale = 0.5

 

      acBlkTblRec.AppendEntity(acCirc1)

      acTrans.AddNewlyCreatedDBObject(acCirc1,True)

 

      '' Create a second circle object

      Dim acCirc2 As Circle = New Circle()

      acCirc2.Center = New Point3d(12, 2, 0)

      acCirc2.Radius = 4

 

      acBlkTblRec.AppendEntity(acCirc2)

      acTrans.AddNewlyCreatedDBObject(acCirc2,True)

 

      '' Restore the original active linetype

      acCurDb.Celtype = acObjId

 

      '' Save the changes and dispose of thetransaction

      acTrans.Commit()

  End Using

End Sub

C#

usingAutodesk.AutoCAD.Runtime;

usingAutodesk.AutoCAD.ApplicationServices;

usingAutodesk.AutoCAD.DatabaseServices;

usingAutodesk.AutoCAD.Geometry;

 

[CommandMethod("SetObjectLinetypeScale")]

public static voidSetObjectLinetypeScale()

{

  // Get the current document and database获取当前文档和数据库

  Document acDoc =Application.DocumentManager.MdiActiveDocument;

  Database acCurDb = acDoc.Database;

 

  // Start a transaction启动事务

  using (Transaction acTrans =acCurDb.TransactionManager.StartTransaction())

  {

      // Save the current linetype保存当前线型

      ObjectId acObjId = acCurDb.Celtype;

 

      // Set the global linetype scale设置全局线型比例

      acCurDb.Ltscale = 3;

 

      // Open the Linetype table for read以读打开线型表

      LinetypeTable acLineTypTbl;

      acLineTypTbl =acTrans.GetObject(acCurDb.LinetypeTableId,

                                      OpenMode.ForRead) as LinetypeTable;

 

      string sLineTypName = "Border";

 

      if (acLineTypTbl.Has(sLineTypName) ==false)

      {

         acCurDb.LoadLineTypeFile(sLineTypName, "acad.lin");

      }

 

      // Set the Border linetype current将当前线型设置为Border;

      acCurDb.Celtype =acLineTypTbl[sLineTypName];

 

      // Open the Block table for read以读打开块表

      BlockTable acBlkTbl;

      acBlkTbl =acTrans.GetObject(acCurDb.BlockTableId,

                                  OpenMode.ForRead) as BlockTable;

 

      // Open the Block table record Modelspace for write

      //以写打开块表记录模型空间

      BlockTableRecord acBlkTblRec;

      acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],

                                     OpenMode.ForWrite) as BlockTableRecord;

 

      // Create a circle object and set itslinetype

      // scale to half of full size

      //创建一个圆并将其线型比例设置为0.5

      Circle acCirc1 = new Circle();

      acCirc1.Center = new Point3d(2, 2, 0);

      acCirc1.Radius = 4;

      acCirc1.LinetypeScale = 0.5;

 

      acBlkTblRec.AppendEntity(acCirc1);

      acTrans.AddNewlyCreatedDBObject(acCirc1,true);

 

      // Create a second circle object再创建一个圆

      Circle acCirc2 = new Circle();

      acCirc2.Center = new Point3d(12, 2, 0);

      acCirc2.Radius = 4;

 

      acBlkTblRec.AppendEntity(acCirc2);

      acTrans.AddNewlyCreatedDBObject(acCirc2,true);

 

      // Restore the original active linetype回复原来的线型

      acCurDb.Celtype = acObjId;

 

      // Save the changes and dispose of thetransaction保存修改关闭事务

      acTrans.Commit();

  }

}

VBA/ActiveX Code Reference

SubSetObjectLinetypeScale()

    ' Save the current linetype

    Dim currLineType As AcadLineType

    Set currLineType = ThisDrawing.ActiveLinetype

 

    ' Set global linetype scale

    ThisDrawing.SetVariable"LTSCALE", 3

 

    ' Load the Border linetype

    On Error Resume Next

    If NotIsObject(ThisDrawing.Linetypes.Item("Border")) Then

      ThisDrawing.Linetypes.Load"Border", "acad.lin"

    End If

 

    ThisDrawing.ActiveLinetype =ThisDrawing.Linetypes.Item("BORDER")

 

    ' Create a circle object in model space

    Dim center(0 To 2) As Double

    center(0) = 2: center(1) = 2: center(2) = 0

 

    Dim circleObj1 As AcadCircle

    Set circleObj1 =ThisDrawing.ModelSpace.AddCircle(center, 4)

 

    ' Set the linetype scale of the circle tohalf of full size

    circleObj1.LinetypeScale = 0.5

    circleObj1.Update

 

    Dim circleObj2 As AcadCircle

    center(0) = center(0) + 10

    Set circleObj2 =ThisDrawing.ModelSpace.AddCircle(center, 4)

    circleObj2.Update

 

    ' Restore original active linetype

    ThisDrawing.ActiveLinetype = currLineType

End Sub