您可以为创建的对象指定线型比例。比例越小,每个绘图单元生成的图案重复次数就越多。默认情况下,AutoCAD 使用全局线型比例 1.0,它等于一个图形单位。可以更改所有图形对象和属性参照的线型比例。 CELTSCALE 系统变量为新创建的对象设置线型比例。LTSCALE 系统变量会更改现有对象和新对象的全局线型刻度。对象上的属性用于更改对象的线型刻度。显示对象的线型比例基于单个对象的线型比例乘以全局线型比例。LinetypeScale 更改对象的线型比例VB.NETImports 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
'' 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
Using 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
Using acCirc2 As Circle = New Circle()
acCirc2.Center = New Point3d(12, 2, 0)
acCirc2.Radius = 4
acBlkTblRec.AppendEntity(acCirc2)
acTrans.AddNewlyCreatedDBObject(acCirc2, True)
End Using
End Using
'' Restore the original active linetype
acCurDb.Celtype = acObjId
'' Save the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
C#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");
}
// 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
using (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
using (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 the transaction
acTrans.Commit();
}
}
VBA/ActiveX 代码参考Sub SetObjectLinetypeScale()
' 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 Not IsObject(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 to half 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
相关概念父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 07:08
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.