Each dimension has the capability of overriding the settings assigned to it by a dimension style. The following properties are available for most dimension objects:
Enter a user-defined suffix for an aligned dimension
This example creates an aligned dimension in model space and uses the Suffix property to allow the user to change the text suffix for the dimension.
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("AddDimensionTextSuffix")> _
Public Sub AddDimensionTextSuffix()
'' 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.XLine1Point = New Point3d(0, 5, 0)
acAliDim.XLine2Point = New Point3d(5, 5, 0)
acAliDim.DimLinePoint = New Point3d(5, 7, 0)
acAliDim.DimensionStyle = acCurDb.Dimstyle
'' Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acAliDim)
acTrans.AddNewlyCreatedDBObject(acAliDim, True)
'' Append a suffix to the dimension text
Dim pStrOpts As PromptStringOptions = New PromptStringOptions("")
pStrOpts.Message = vbLf & "Enter a new text suffix for the dimension: "
pStrOpts.AllowSpaces = True
Dim pStrRes As PromptResult = acDoc.Editor.GetString(pStrOpts)
If pStrRes.Status = PromptStatus.OK Then
acAliDim.Suffix = pStrRes.StringResult
End If
'' 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.EditorInput;
using Autodesk.AutoCAD.Geometry;
[CommandMethod("AddDimensionTextSuffix")]
public static void AddDimensionTextSuffix()
{
// 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.XLine1Point = new Point3d(0, 5, 0);
acAliDim.XLine2Point = new Point3d(5, 5, 0);
acAliDim.DimLinePoint = new Point3d(5, 7, 0);
acAliDim.DimensionStyle = acCurDb.Dimstyle;
// Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acAliDim);
acTrans.AddNewlyCreatedDBObject(acAliDim, true);
// Append a suffix to the dimension text
PromptStringOptions pStrOpts = new PromptStringOptions("");
pStrOpts.Message = "\nEnter a new text suffix for the dimension: ";
pStrOpts.AllowSpaces = true;
PromptResult pStrRes = acDoc.Editor.GetString(pStrOpts);
if (pStrRes.Status == PromptStatus.OK)
{
acAliDim.Suffix = pStrRes.StringResult;
}
// Commit the changes and dispose of the transaction
acTrans.Commit();
}
}