设置倾斜角度 (.NET)
倾斜角度决定了文本的向前或向后倾斜。角度表示与其垂直轴(90 度)的偏移。若要设置倾斜角度,请使用该属性更改文本样式或文本对象的属性。倾斜角必须以弧度为单位提供。正角表示向右倾斜,负值将添加到其上以将其转换为正等价物。ObliquingAngleOblique2*PI 创建倾斜文本本示例创建一个单行文本对象,然后将其倾斜 45 度。 VB.NETImports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("ObliqueText")> _
Public Sub ObliqueText()
'' 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 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 single-line text object
Using acText As DBText = New DBText()
acText.Position = New Point3d(3, 3, 0)
acText.Height = 0.5
acText.TextString = "Hello, World."
'' Change the oblique angle of the text object to 45 degrees(0.707 in radians)
acText.Oblique = 0.707
acBlkTblRec.AppendEntity(acText)
acTrans.AddNewlyCreatedDBObject(acText, True)
End Using
'' 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("ObliqueText")]
public static void ObliqueText()
{
// 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 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 single-line text object
using (DBText acText = new DBText())
{
acText.Position = new Point3d(3, 3, 0);
acText.Height = 0.5;
acText.TextString = "Hello, World.";
// Change the oblique angle of the text object to 45 degrees(0.707 in radians)
acText.Oblique = 0.707;
acBlkTblRec.AppendEntity(acText);
acTrans.AddNewlyCreatedDBObject(acText, true);
}
// Save the changes and dispose of the transaction
acTrans.Commit();
}
}
VBA/ActiveX 代码参考Sub ObliqueText()
Dim textObj As AcadText
Dim textString As String
Dim insertionPoint(0 To 2) As Double
Dim height As Double
' Define the text object
textString = "Hello, World."
insertionPoint(0) = 3
insertionPoint(1) = 3
insertionPoint(2) = 0
height = 0.5
' Create the text object in model space
Set textObj = ThisDrawing.ModelSpace. _
AddText(textString, insertionPoint, height)
' Change the value of the ObliqueAngle
' to 45 degrees (.707 radians)
textObj.ObliqueAngle = 0.707
textObj.Update
End Sub
相关概念父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-11-1 16:59
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.