The dimension value that is displayed can be replaced using the DimensionText property. Using this property you can completely replace the displayed value of the dimension, or you can append text to the value. To represent the measured value in the override dimension text, use the character string “<>” in the text.
可以使用 DimensionText 属性来替换所显示的标注值。使用此属性可以完全替换所显示的标注值,也可以向该值附加文字。若要在替代标注文字中表示测量值,请在文字中使用字符“<>”。
This example appends some text to the value so that both the string and the dimension value are displayed.
本例向标注值附加了文字,所以既显示字符串,又显示标注值。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("OverrideDimensionText")> _
Public Sub OverrideDimensionText()
'' 获得当前数据库 Get the current 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 the aligned dimension
Dim acAliDim As AlignedDimension = New AlignedDimension()
acAliDim.SetDatabaseDefaults()
acAliDim.XLine1Point = New Point3d(5, 3, 0)
acAliDim.XLine2Point = New Point3d(10, 3, 0)
acAliDim.DimLinePoint = New Point3d(7.5, 5, 0)
acAliDim.DimensionStyle = acCurDb.Dimstyle
''替换标注文字 Override the dimension text
acAliDim.DimensionText = "The value is <>"
'' 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acAliDim)
acTrans.AddNewlyCreatedDBObject(acAliDim, True)
'' 提交修改并销毁事务 Commit 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("OverrideDimensionText")]
public static void OverrideDimensionText()
{
// 获得当前数据库 Get the current 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 the aligned dimension
AlignedDimension acAliDim = new AlignedDimension();
acAliDim.SetDatabaseDefaults();
acAliDim.XLine1Point = new Point3d(5, 3, 0);
acAliDim.XLine2Point = new Point3d(10, 3, 0);
acAliDim.DimLinePoint = new Point3d(7.5, 5, 0);
acAliDim.DimensionStyle = acCurDb.Dimstyle;
// Override the dimension text
acAliDim.DimensionText = "The value is <>";
// 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acAliDim);
acTrans.AddNewlyCreatedDBObject(acAliDim, true);
// 提交修改并销毁事务 Commit the changes and dispose of the transaction
acTrans.Commit();
}
}