You can specify the linetype scale for objects you create. The smaller the scale, the more repetitions of the pattern are generated per drawing unit. By default, AutoCAD uses a global linetype scale of 1.0, which is equal to one drawing unit. You can change the linetype scale for all drawing objects and attribute references.
The CELTSCALE system variable sets the linetype scale for newly created objects. LTSCALE system variable changes the global linetype scale of existing objects as well as new objects. The LinetypeScale property on an object is used to change the linetype scale for an object. The linetype scale at which an object is displayed at is based on the an individual object’s linetype scale multiplied by the global linetype scale.
For more information about linetype scales, see “Control Linetype Scale” in the AutoCAD User's Guide.
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("SetObjectLinetypeScale")> _
Public Sub SetObjectLinetypeScale()
'' 获得当前文档和数据库 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) = False Then
acCurDb.LoadLineTypeFile(sLineTypName, "acad.lin")
End If
'' 设置 Border 线型为当前线型 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 Model space for write
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
OpenMode.ForWrite)
'' 创建一个圆对象,然后设置它的线型比例为全尺寸的一半 Create a circle object and set its linetype
'' scale to half of full size
Dim acCirc1 As Circle = New Circle()
acCirc1.SetDatabaseDefaults()
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.SetDatabaseDefaults()
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 the transaction
acTrans.Commit()
End Using
End Sub
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
[CommandMethod("SetObjectLinetypeScale")]
public static void SetObjectLinetypeScale()
{
// 获得当前文档和数据库 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");
}
// 设置 Border 线型为当前线型 Set the Border linetype current
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 Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
// 创建一个圆对象,然后设置它的线型比例为全尺寸的一半 Create a circle object and set its linetype
// scale to half of full size
Circle acCirc1 = new Circle();
acCirc1.SetDatabaseDefaults();
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.SetDatabaseDefaults();
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 the transaction
acTrans.Commit();
}
}