创建线性标注
 
 

Linear dimensions can be aligned or rotated. Aligned dimensions have the dimension line parallel to the line along which the extension line origins lie. Rotated dimensions have the dimension line placed at an angle to the extension line origins.

线性标注可以是对齐标注或转角标注。对齐标注的尺寸线与尺寸界线原点所在的线平行。而转角标注的尺寸线与尺寸界线原点形成一定的角度。

You create linear dimensions by creating instances of the AlignedDimension and RotatedDimension objects. After you create an instance of a linear dimensions, you can modify the text, the angle of the text, or the angle of the dimension line. The following illustrations show how the type of linear dimension and the placement of the extension line origins affect the angle of the dimension line and text.

要创建线性标注,请创建 AlignedDimension 和 RotatedDimension 的标注。创建线性标注的实例之后,可以修改文字、文字的角度或尺寸线的角度。在下面的图解中显示尺寸线性标注的类型和尺寸界线的原点如何影响尺寸线的角度和文字。

When you create an instance of an AlignedDimension object, you have the option to specify the extension line origins, the location of the dimension line, dimension text, and the dimension style to apply. If you do not pass any parameters into the AlignedDimension object constructor, the object is assigned a set of default property values.

当创建一个 AlignedDimension 的实例时,用户可以指定尺寸界线原点、尺寸线的位置、标注文字和应用的标注样式这些选项。如果你没有传递任何参数给AlignedDimension 对象的构造函数,对象将会被指定一些默认的属性值。

The RotatedDimension object constructor offers the same options as the AlignedDimension object constructor, with one exception. The RotatedDimension object constructor takes an additional paramter that specifies the angle at which the dimension line is rotated.

RotatedDimension 对象构造函数提供了与 AlignedDimension 对象构造函数相同的选项和一个例外的选项。RotatedDimension 对象构造函数带了一个另外的参数,它用来指定尺寸线的旋转角度。

For additional information about creating linear dimensions, see “Create Linear Dimensions” in the AutoCAD User's Guide.

更多关于创建线性标注的详细信息,请参见《AutoCAD 用户手册》中的“创建线性标注”。

折弯标注

Joglines on linear dimensions are not added through a set of properties, but extended data(Xdata). The application name responsible for dimension joglines is ACAD_DSTYLE_DIMJAG_POSITION. The following is an example of the Xdata structure that needs to be appended to a linear dimension.

线性标注不能通过设置属性来添加折弯,但是可以使用扩展数据。应用程序名字为 ACAD_DSTYLE_DIMJAG_POSITION 的扩展数据负责标注折弯。下例是一个需要追加一个线性标注的 Xdata 结构的例子。

VB.NET

'' Open the Registered Application table for read
Dim acRegAppTbl As RegAppTable
acRegAppTbl = <transaction>.GetObject(<current_database>.RegAppTableId, _
                                      OpenMode.ForRead)
 
'' Check to see if the app "ACAD_DSTYLE_DIMJAG_POSITION" is
'' registered and if not add it to the RegApp table
If acRegAppTbl.Has("ACAD_DSTYLE_DIMJAG_POSITION") = False Then
    Dim acRegAppTblRec As RegAppTableRecord = New RegAppTableRecord()
 
    acRegAppTblRec.Name = "ACAD_DSTYLE_DIMJAG_POSITION"
 
    acRegAppTbl.UpgradeOpen()
 
    acRegAppTbl.Add(acRegAppTblRec)
    <transaction>.AddNewlyCreatedDBObject(acRegAppTblRec, True)
End If
 
'' Create a result buffer to define the Xdata
Dim acResBuf As ResultBuffer = New ResultBuffer()
acResBuf.Add(New TypedValue(DxfCode.ExtendedDataRegAppName, _
                                    "ACAD_DSTYLE_DIMJAG_POSITION"))
acResBuf.Add(New TypedValue(DxfCode.ExtendedDataInteger16, 387))
acResBuf.Add(New TypedValue(DxfCode.ExtendedDataInteger16, 3))
acResBuf.Add(New TypedValue(DxfCode.ExtendedDataInteger16, 389))
acResBuf.Add(New TypedValue(DxfCode.ExtendedDataXCoordinate, _
                                    New Point3d(-1.26985, 3.91514, 0)))
 
'' Attach the Xdata to the dimension
<dimension_object>.XData = acResBuf

C#

// Open the Registered Application table for read
RegAppTable acRegAppTbl;
acRegAppTbl = <transaction>.GetObject(<current_database>.RegAppTableId,
                                      OpenMode.ForRead) as RegAppTable;
 
// Check to see if the app "ACAD_DSTYLE_DIMJAG_POSITION" is
// registered and if not add it to the RegApp table
if (acRegAppTbl.Has("ACAD_DSTYLE_DIMJAG_POSITION") == false)
{
    RegAppTableRecord acRegAppTblRec = new RegAppTableRecord();
 
    acRegAppTblRec.Name = "ACAD_DSTYLE_DIMJAG_POSITION";
 
    acRegAppTbl.UpgradeOpen();
 
    acRegAppTbl.Add(acRegAppTblRec);
    <transaction>.AddNewlyCreatedDBObject(acRegAppTblRec, true);
}
 
// Create a result buffer to define the Xdata
ResultBuffer acResBuf = new ResultBuffer();
acResBuf.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName,
                                         "ACAD_DSTYLE_DIMJAG_POSITION"));
acResBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 387));
acResBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 3));
acResBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 389));
acResBuf.Add(new TypedValue((int)DxfCode.ExtendedDataXCoordinate,
                                         new Point3d(-1.26985, 3.91514, 0)));
 
// Attach the Xdata to the dimension
<dimension_object>.XData = acResBuf;
VBA/ActiveX 代码参考

创建一个旋转的线性标注

This example creates a rotated dimension in Model space.

本例将在模型空间中创建一个转角标注。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("CreateRotatedDimension")> _
Public Sub CreateRotatedDimension()
  '' 获得当前数据库  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 rotated dimension
      Dim acRotDim As RotatedDimension = New RotatedDimension()
      acRotDim.SetDatabaseDefaults()
      acRotDim.XLine1Point = New Point3d(0, 0, 0)
      acRotDim.XLine2Point = New Point3d(6, 3, 0)
      acRotDim.Rotation = 0.707
      acRotDim.DimLinePoint = New Point3d(0, 5, 0)
      acRotDim.DimensionStyle = acCurDb.Dimstyle
 
      '' 添加新对象到模型空间和事务中   Add the new object to Model space and the transaction
      acBlkTblRec.AppendEntity(acRotDim)
      acTrans.AddNewlyCreatedDBObject(acRotDim, True)
 
      '' 提交修改并销毁事务  Commit 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("CreateRotatedDimension")]
public static void CreateRotatedDimension()
{
  // 获得当前数据库  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 rotated dimension
      RotatedDimension acRotDim = new RotatedDimension();
      acRotDim.SetDatabaseDefaults();
      acRotDim.XLine1Point = new Point3d(0, 0, 0);
      acRotDim.XLine2Point = new Point3d(6, 3, 0);
      acRotDim.Rotation = 0.707;
      acRotDim.DimLinePoint = new Point3d(0, 5, 0);
      acRotDim.DimensionStyle = acCurDb.Dimstyle;
 
      // 添加新对象到模型空间和事务中   Add the new object to Model space and the transaction
      acBlkTblRec.AppendEntity(acRotDim);
      acTrans.AddNewlyCreatedDBObject(acRotDim, true);
 
      // 提交修改并销毁事务  Commit the changes and dispose of the transaction
      acTrans.Commit();
  }
}
VBA/ActiveX 代码参考