Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("CreateAngularDimension")> _
Public Sub CreateAngularDimension()
'' 获得当前数据库 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 an angular dimension
Dim acLinAngDim As LineAngularDimension2 = New LineAngularDimension2()
acLinAngDim.SetDatabaseDefaults()
acLinAngDim.XLine1Start = New Point3d(0, 5, 0)
acLinAngDim.XLine1End = New Point3d(1, 7, 0)
acLinAngDim.XLine2Start = New Point3d(0, 5, 0)
acLinAngDim.XLine2End = New Point3d(1, 3, 0)
acLinAngDim.ArcPoint = New Point3d(3, 5, 0)
acLinAngDim.DimensionStyle = acCurDb.Dimstyle
'' 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acLinAngDim)
acTrans.AddNewlyCreatedDBObject(acLinAngDim, True)
'' 提交修改并销毁事务 Commit the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
标注用于将测量值添加到图形中。而公差用于指定标注的变化范围。通过 .NET API,可以使用标注样式和标注替代来管理标注。
标注的概念
创建标注
编辑标注
使用标注样式
模型空间和图纸空间中的标注
创建引线和注释
使用形位公差
标注的概念
标注可以显示对象的形位测量值、对象之间的距离或角度,以及特征的 X 坐标和 Y 坐标。AutoCAD® 提供了三种基本类型的标注:线性标注、半径标注和角度标注。线性标注包括对齐标注、转角标注和坐标标注。
可以为直线、多线、圆弧、圆和多段线线段创建标注,也可以创建独立的标注。
AutoCAD 在当前图层上绘制标注。每个标注均与一个标注样式相关联,无论此标注是默认标注还是用户定义的标注。样式可以控制诸如颜色、文字样式、箭头和线型比例等标注特征。标注不支持厚度信息。样式族可以针对不同类型的标注,对基本样式进行细微的修改;而替代可以对特定的标注进行样式修改。
- 标注的组成部分
- 定义标注系统变量
- 设置标注文字样式
- 了解引线
- 了解关联标注
标注的组成部分
标注是由许多不同的对象组成的,像直线、文字、实体填充和块。虽然每个标注类型都有可能会出现些微的不同,但是他们都会有几个共同的部分。
- Dimension line.
- 尺寸线。指示标注的方向和范围的线。 对于角度标注,尺寸线是圆弧。
- Extension line.
- 尺寸界线. 尺寸界线从被标注的特征上延长至尺寸线。尺寸界线也称为投影线或证示线。
- Arrowhead.
- 箭头。 常常用于指示尺寸线终止的符号。箭头也称为终止符号或终止。
- Dimension text.
- 标注文字。 它通常指示距离的实际测量值的文本字符串,它也可能会包含前缀、后缀和公差。
- Leader.
- 引线。 引线是将注释连接到其参照的特征的实线。
定义标注系统变量
标注系统变量可以控制标注的外观。标注系统变量包括 DIMAUNIT、DIMUPT、DIMTOFL、DIMFIT、DIMTIH、DIMTOH、DIMJUST 和 DIMTAD。可以使用 Application 对象的 SetSystemVariable 方法访问并设置这些变量。例如,以下代码行将 DIMAUNIT 系统变量(角度标注的单位格式)设置为弧度 (3):
Application.SetSystemVariable("DIMAUNIT", 3)
设置标注文字样式
尺寸文本是指与尺寸相关的任何类型的文本,包括测量值、公差(横向和几何公差)、前缀、后缀和单行或段落形式的文本注释。您可以使用AutoCAD计算的默认测量值作为文本,提供自己的文本,或完全抑制文本。可以使用标注文字添加信息,例如特殊制造程序或装配说明。标注文字使用DIMTXSTY系统变量指定的文字样式。
了解引线
默认的引线是指向图形中某个特征的带箭头的直线。通常,引线的功能是连接注释和特征。这里的注释指段落文字、块或特征控制框。这种引线不同于 AutoCAD 为半径标注、直径标注和线性标注自动创建的简单引线,其文字不能在尺寸界线之间自动调整。
引线对象与注释关联,所以在编辑注释时引线也会随着更新。用户可以复制图形中其他位置使用的注释并将其附加到引线上,也可以创建新的注释。还可以创建未附着注释的引线。
了解关联标注
当与关联标注相关联的几何对象被修改时,关联标注会自动调整其位置、方向和测量值。DIMASSOC 系统变量用于控制关联标注。将 DIMASSOC 设置为 2 以打开关联标注。
创建标注
可以创建线性、半径、角度和坐标标注。
创建标注时,使用的是活动标注样式。创建之后,可以对尺寸界线原点、标注文字位置、标注文字内容以及与尺寸线的相对角度进行修改,也可以修改标注使用的标注样式。
- 创建线性标注
- 创建半径标注
- 创建角度标注
- 创建折弯半径标注
- 创建弧长标注
- 创建坐标标注
创建线性标注
线性标注可以是对齐标注或转角标注。对齐标注的尺寸线与尺寸界线原点所在的线平行。而转角标注的尺寸线与尺寸界线原点形成一定的角度。
要创建线性标注,请创建 AlignedDimension 和 RotatedDimension 的标注。创建线性标注的实例之后,可以修改文字、文字的角度或尺寸线的角度。在下面的图解中显示尺寸线性标注的类型和尺寸界线的原点如何影响尺寸线的角度和文字。
当创建一个 AlignedDimension 的实例时,用户可以指定尺寸界线原点、尺寸线的位置、标注文字和应用的标注样式这些选项。如果你没有传递任何参数给AlignedDimension 对象的构造函数,对象将会被指定一些默认的属性值。
RotatedDimension 对象构造函数提供了与 AlignedDimension 对象构造函数相同的选项和一个例外的选项。RotatedDimension 对象构造函数带了一个另外的参数,它用来指定尺寸线的旋转角度。
线性标注不能通过设置属性来添加折弯,但是可以使用扩展数据。应用程序名字为 ACAD_DSTYLE_DIMJAG_POSITION 的扩展数据负责标注折弯。下例是一个需要追加一个线性标注的 Xdata 结构的例子。
'' 打开已注册的应用程序表进行读取
Dim acRegAppTbl As RegAppTable
acRegAppTbl = <transaction>.GetObject(<current_database>.RegAppTableId, _
OpenMode.ForRead)
'' 检查应用程序“ACAD_DSTYLE_DIMJAG_POSITION”是否正确
'' 已注册,如果未注册,则将其添加到RegApp表中
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
'' 创建结果缓冲区以定义扩展数据
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)))
'' 将扩展数据附加到尺寸标注
<dimension_object>.XData = acResBuf
创建一个旋转的线性标注
本例将在模型空间中创建一个转角标注。
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
创建半径标注
半径标注用于测量圆弧和圆的半径与直径。半径或直径标注是通过创建 RadialDimension 和 DiametricDimension 对象的实例来创建的。
半径标注用于测量圆弧和圆的半径与直径。半径或直径标注是通过创建 RadialDimension 和 DiametricDimension 对象的实例来创建的。
根据圆或圆弧的大小、标注文本的位置以及 DIMUPT、DIMTOFL、DIMFIT、DIMTIH、DIMTOH、DIMJUST 和 DIMTAD 标注系统变量中的值,可以创建各种类型的半径标注。(系统变量可以使用 GetSystemVariable 和 SetSystemVariable 方法查询或设置。)
对于水平标注文字,如果尺寸线与水平线的角度大于 15 度,而且位于圆或圆弧的外面,则 AutoCAD 将绘制钩线,也称为引导线或弯钩。钩线为一个箭头的长度,放在标注文字的旁边。
当创建 RadialDimension 对象的实例后,用户可以指定圆心和引线附着点坐标、引线长度、标注文字和应用的标注样式这些选项。创建 DiametricDimension 对象与创建 RadialDimension 对象相似,除了使用指定引线附着点和远端引线附着点代替加以与引线附着点外。
LeaderLength 属性指定从 ChordPoint 到标注为注释文字的距离(如果不需要钩线则停止)。
创建半径标注
在模型空间中创建一个半径标注。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("CreateRadialDimension")> _
Public Sub CreateRadialDimension()
'' 获得当前数据库 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 radial dimension
Dim acRadDim As RadialDimension = New RadialDimension()
acRadDim.SetDatabaseDefaults()
acRadDim.Center = New Point3d(0, 0, 0)
acRadDim.ChordPoint = New Point3d(5, 5, 0)
acRadDim.LeaderLength = 5
acRadDim.DimensionStyle = acCurDb.Dimstyle
'' 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acRadDim)
acTrans.AddNewlyCreatedDBObject(acRadDim, True)
'' 提交修改并销毁事务 Commit the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
创建角度标注
角度标注用于测量两条线或三个点之间的角度。例如,用户可以使用它们来测量圆的两个半径之间的角度。角度标注是通过创建 LineAngularDimension2 或 Point3AngularDimension 对象的实例来创建的。
当用户创建 LineAngularDimension2 或 Point3AngularDimension 对象的实例后, 构造函数可以随意的接受一组参数。当创建一个新的LineAngularDimension2 对象时,可以提供下面的参数:
- 尺寸线1的起点 (XLine1Start 属性)
- 尺寸线1的终点 (XLine1End 属性)
- 尺寸线2的起点 (XLine2Start 属性)
- 尺寸线2的终点 (XLine2End 属性)
- 圆弧点 (ArcPoint 属性)
- 标注文字(DimensionText 属性)
- 标注样式(DimensionStyleName 或 DimensionStyle 属性)
当创建一个新的 Point3AngularDimension 对象时,可以提供下面的参数:
- 中心点 (CenterPoint 属性)
- 第一个尺寸线点 (XLine1Point 属性)
- 第二个尺寸线点 (XLine2Point 属性)
- 圆弧点 (ArcPoint 属性)
- 标注文字 (DimensionText 属性)
- 标注样式 (DimensionStyleName 或 DimensionStyle 属性)
创建角度标注
在模型空间中创建一个角度标注。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("CreateAngularDimension")> _
Public Sub CreateAngularDimension()
'' 获得当前数据库 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 an angular dimension
Dim acLinAngDim As LineAngularDimension2 = New LineAngularDimension2()
acLinAngDim.SetDatabaseDefaults()
acLinAngDim.XLine1Start = New Point3d(0, 5, 0)
acLinAngDim.XLine1End = New Point3d(1, 7, 0)
acLinAngDim.XLine2Start = New Point3d(0, 5, 0)
acLinAngDim.XLine2End = New Point3d(1, 3, 0)
acLinAngDim.ArcPoint = New Point3d(3, 5, 0)
acLinAngDim.DimensionStyle = acCurDb.Dimstyle
'' 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acLinAngDim)
acTrans.AddNewlyCreatedDBObject(acLinAngDim, True)
'' 提交修改并销毁事务 Commit the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
创建折弯半径标注
折弯半径标注用于测量一个对象的半径并显示一个半径符号显示在标注文字的前面。在下面的情况下,可以使用折弯标注代替半径标注对象:
- 对象的中心点位于布局的外面或者超出了模型的范围而不得不为半径标注提供足够的空间。
- 对象有一个很大的半径
可以通过创建 RadialDimensionLarge 对象的实例来创建折弯半径标注。在创建一个 RadialDimensionLarge 对象的实例时,它的构造函数可以随意的接受一组参数。当创建一个新的 RadialDimensionLarge 对象时,可以提供下面的参数:
- Center point (Center property)
- 中心点(Center 属性)
- Chord point (ChordPoint property)
- 弦点(ChordPoint 属性)
- Override center point (OverrideCenter property)
- 替换中心点(OverrideCenter 属性)
- Position of the jog lines (JogPoint property)
- 折弯线的位置(JogPoint 属性)
- Angle of the jog lines (JogAngle property)
- 折弯线的角度(JogAngle 属性)
- Dimension text (DimensionText property)
- 标注文字 (DimensionText 属性)
- Dimension style (DimensionStyleName or DimensionStyle properties)
- 标注样式 (DimensionStyleName 或 DimensionStyle 属性)
创建一个折弯半径标注
在模型空间中创建一个折弯半径标注。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("CreateJoggedDimension")> _
Public Sub CreateJoggedDimension()
'' 获得当前数据库 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 a large radius dimension
Dim acRadDimLrg As RadialDimensionLarge = New RadialDimensionLarge()
acRadDimLrg.SetDatabaseDefaults()
acRadDimLrg.Center = New Point3d(-3, -4, 0)
acRadDimLrg.ChordPoint = New Point3d(2, 7, 0)
acRadDimLrg.OverrideCenter = New Point3d(0, 2, 0)
acRadDimLrg.JogPoint = New Point3d(1, 4.5, 0)
acRadDimLrg.JogAngle = 0.707
acRadDimLrg.DimensionStyle = acCurDb.Dimstyle
'' 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acRadDimLrg)
acTrans.AddNewlyCreatedDBObject(acRadDimLrg, True)
'' 提交修改并销毁事务 Commit the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
创建弧长标注
弧长标注用于测量沿着圆弧段的长度并使用一个圆弧符号显示标注文字,它不是在标注文字的上面就是前面。当你需要标注圆弧的真实长度而不仅仅是它的起点与终点之间的距离时,可以使用弧长标注。
用户可以通过创建 ArcDimension 对象的实例来创建弧长标注。当用户创建一个 ArcDimension 对象的实例时,它需要一组定义标注的参数。当你创建一个新的 ArcDimension 对象时,下面的参数必须提供:
- Center point (Center property)
- 中心点 (Center 属性)
- Extension line 1 point (XLine1Point property)
- 延长线 1 的点(XLine1Point 属性)
- Extension line 2 point (XLine2Point property)
- 延长线 2 的点 (XLine2Point 属性)
- Arc point (ArcPoint property)
- 圆弧点 (ArcPoint 属性)
- Dimension text (DimensionText property)
- 标注文字(DimensionText 属性)
- Dimension style (DimensionStyleName or DimensionStyle properties)
- 标注样式 (DimensionStyleName 或 DimensionStyle 属性)
注意 DIMARCSYM 系统变量控制圆弧符号是否显示以及它显示在与它相关的标注文字的什么地方。
创建弧长标注
在模型空间中创建一个弧长标注。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("CreateArcLengthDimension")> _
Public Sub CreateArcLengthDimension()
'' 获得当前数据库 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 an arc length dimension
Dim acArcDim As ArcDimension = New ArcDimension(New Point3d(4.5, 1.5, 0), _
New Point3d(8, 4.25, 0), _
New Point3d(0, 2, 0), _
New Point3d(5, 7, 0), _
"<>", _
acCurDb.Dimstyle)
acArcDim.SetDatabaseDefaults()
'' 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acArcDim)
acTrans.AddNewlyCreatedDBObject(acArcDim, True)
'' 提交修改并销毁事务 Commit the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
创建坐标标注
坐标或基准标注用于测量从原点或称为基准点到被标注的特征象部件上的孔之间的垂直距离。这些标注通过保持特征与基准点之间的精确偏移量,来避免误差增大。
坐标标注由带引线的 X 或 Y 坐标组成。X 基准坐标标注沿 X 轴测量特征点与基准点的距离。Y 基准坐标标注沿着 Y 轴测量相同的距离。AutoCAD 使用当前用户坐标系 (UCS) 的原点确定测量的坐标。坐标使用绝对值。
标注文字将与坐标引线对齐,而不考虑当前标注样式定义的文字方向。用户可以接受默认文字,也可以提供自己的文字。
用户通过创建 OrdinateDimension 对象的实例来创建坐标标注。当用户创建一个 OrdinateDimension 对象的实例时,它的构造函数可以接受任意一组参数。当创建一个新的 OrdinateDimension 对象时,可以提供下列参数:
- Use X axis (UsingXAxis property)
- 使用 X 轴 (UsingXAxis 属性)
- Defining point (DefiningPoint property)
- 定义点 (DefiningPoint 属性)
- Leader endpoint (LeaderEndPoint property)
- 引线终点 (LeaderEndPoint 属性)
- Dimension text (DimensionText property)
- 标注文字(DimensionText 属性)
- Dimension style (DimensionStyleName or DimensionStyle properties)
- 标注样式 (DimensionStyleName 或 DimensionStyle 属性)
当传递值给 OrdinateDimension 对象的构造函数时,第一个值是一个布尔值标识,它指出标注是 X 基准还是 Y 基准坐标标注。如果输入 True,一个 X 基准坐标标注将被创建。如果输入 False,一个 Y 基准坐标标注将会被创建。UsingXAxis 属性也可以用于指定一个坐标标注是 X 基准还是 Y 基准。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("CreateOrdinateDimension")> _
Public Sub CreateOrdinateDimension()
'' 获得当前数据库 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 an ordinate dimension
Dim acOrdDim As OrdinateDimension = New OrdinateDimension()
acOrdDim.SetDatabaseDefaults()
acOrdDim.UsingXAxis = True
acOrdDim.DefiningPoint = New Point3d(5, 5, 0)
acOrdDim.LeaderEndPoint = New Point3d(10, 5, 0)
acOrdDim.DimensionStyle = acCurDb.Dimstyle
'' 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acOrdDim)
acTrans.AddNewlyCreatedDBObject(acOrdDim, True)
'' 提交修改并销毁事务 Commit the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
编辑标注
与对待 AutoCAD 中的其他图形对象一样,用户也可以使用为对象提供的标准方法和属性来编辑标注。
The following properties are available for most dimension objects:
以下属性可用于大多数标注对象:
- DimensionStyle
- 指定标注样式的 ObjectID。
- DimensionStyleName
- 指定标注样式的名字。
- DimensionText
- 为标注指定用户定义文本字符串。
- HorizontalRotation
- 为标注指定用弧度表示的旋转角度。
- Measurement
- 指定标注的实际测量值。
- TextPosition
- 指定标注文字的位置。
- TextRotation
- 指定标注文字的旋转角度。
另外,若修改一个标注对象除了利用它特有的属性和方法外,也可以复制和转换标注对象。
替代标注文字
可以使用 DimensionText 属性来替换所显示的标注值。使用此属性可以完全替换所显示的标注值,也可以向该值附加文字。若要在替代标注文字中表示测量值,请在文字中使用字符“<>”。
修改标注文字
本例向标注值附加了文字,所以既显示字符串,又显示标注值。
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
使用标注样式
命名标注样式是一组用于确定标注外观的设置。使用命名标注样式,可以建立和实施图形的绘图标准。
所有标注都使用活动标注样式来创建。如果在创建标注之前未定义或应用样式,则 AutoCAD 将应用默认样式 STANDARD。要设置活动标注样式,请使用当前 Database 的Dimstyle 属性。
要设置一个标注样式,请从命名和保存样式开始。新样式以当前样式为基础,并包括对标注组成部分的布局、文字位置以及注释外观的所有后续更改。这里的注释指主单位、换算单位、公差和文字。
创建,修改和复制标注样式
新的标注样式可以通过创建一个 DimStyleTableRecord 对象的实例,然后使用 Add 方法把它添加到 DimStyleTable 中来创建。标注样式在添加到表中之前,请使用 Name 属性设置新样式的名字。
用户也可以复制一种现有样式或一组替代。使用 CopyFrom 方法,将标注样式从源对象复制到新标注样式中。源对象可以是另一个 DimStyleTableRecord 对象、标注、Tolerance 或 Leader 对象,甚至可以是 Database 对象。如果从另一个标注样式复制样式设置,则样式被精确复制。如果从标注、Tolerance 或 Leader 对象复制样式的设置,则当前设置,包括所有对象替代会被复制到新样式中。如果复制 Database 对象的样式,则活动标注样式加上所有的图形替代,会被复制到新样式。
本样例创建三个新的标注样式,并将当前 Database、给定标注样式和给定标注的当前设置分别复制到各个新的标注样式中。如果在运行此样例之前进行适当的设置,将发现创建的是不同的标注样式。
- Create a new drawing and make it the active drawing.
创建新的图形并使其成为活动的图形。
- Create a linear dimension in the new drawing. This dimension should be the only object in the drawing.
在新的图形中创建线性标注。此标注应该是图形中仅有的对象。
- Change the color of the dimension line to yellow.
将标注线的颜色更改为黄色。
- Change the DIMCLRD system variable to 5 (blue).
将 DIMCLRD 系统变量改为 5(蓝色)。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("CopyDimStyles")>
Public Sub CopyDimStyles()
'' 获得当前数据库 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()
'' 以只读方式打开块表
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead)
'' 以只读方式打开模型空间的块表记录
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace),
OpenMode.ForRead)
Dim acObj As Object = Nothing
For Each acObjId As ObjectId In acBlkTblRec
'' 获取模型空间中的第一个对象
acObj = acTrans.GetObject(acObjId,
OpenMode.ForRead)
Exit For
Next
'' 以只读方式打开标注样式表
Dim acDimStyleTbl As DimStyleTable
acDimStyleTbl = acTrans.GetObject(acCurDb.DimStyleTableId,
OpenMode.ForRead)
Dim strDimStyleNames(2) As String
strDimStyleNames(0) = "Style 1 copied from a dim"
strDimStyleNames(1) = "Style 2 copied from Style 1"
strDimStyleNames(2) = "Style 3 copied from the running drawing values"
Dim nCnt As Integer = 0
''保存第一个标注样式的引用 Keep a reference of the first dimension style for later
Dim acDimStyleTblRec1 As DimStyleTableRecord = Nothing
'' 循环标注样式名数组 Iterate the array of dimension style names
For Each strDimStyleName As String In strDimStyleNames
Dim acDimStyleTblRec As DimStyleTableRecord
Dim acDimStyleTblRecCopy As DimStyleTableRecord = Nothing
''检查标注样式是否存在
If acDimStyleTbl.Has(strDimStyleName) = False Then
If acDimStyleTbl.IsWriteEnabled = False Then acDimStyleTbl.UpgradeOpen()
acDimStyleTblRec = New DimStyleTableRecord()
acDimStyleTblRec.Name = strDimStyleName
acDimStyleTbl.Add(acDimStyleTblRec)
acTrans.AddNewlyCreatedDBObject(acDimStyleTblRec, True)
Else
acDimStyleTblRec = acTrans.GetObject(acDimStyleTbl(strDimStyleName),
OpenMode.ForWrite)
End If
''确定新的标注样式是如何组装的 Determine how the new dimension style is populated
Select Case nCnt
'' Assign the values of the dimension object to the new dimension style
Case 0
Try
'' 指定一个对象给一个标注 Cast the object to a Dimension
Dim acDim As RotatedDimension = acObj
'' Copy the dimension style data from the dimension and
'' set the name of the dimension style as the copied settings
'' are unnamed.
acDimStyleTblRecCopy = acDim.GetDimstyleData()
acDimStyleTblRec1 = acDimStyleTblRec
Catch
'' Object was not a dimension
End Try
'' Assign the values of the dimension style to the new dimension style
Case 1
acDimStyleTblRecCopy = acDimStyleTblRec1
'' Assign the values of the current drawing to the dimension style
Case 2
acDimStyleTblRecCopy = acCurDb.GetDimstyleData()
End Select
'' Copy the dimension settings and set the name of the dimension style
acDimStyleTblRec.CopyFrom(acDimStyleTblRecCopy)
acDimStyleTblRec.Name = strDimStyleName
'' Dispose of the copied dimension style
acDimStyleTblRecCopy.Dispose()
nCnt = nCnt + 1
Next
'' 提交修改并销毁事务 Commit the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
替代标注样式
Class Dimension
Public Overridable Property Dimdle As Double
Public Overridable Property Dimdli As Double
Public Overridable Property Dimdsep As Char
Public Overridable Property Dimexe As Double
Public Overridable Property Dimexo As Double
Public Overridable Property Dimfrac As Integer
Public Overridable Property DimfxlenOn As Boolean
Public Overridable Property Dimfxlen As Double
Public Overridable Property Dimgap As Double
Public Overridable Property Dimjogang As Double
Public Overridable Property Dimjust As Integer
Public Overridable Property Dimldrblk As ObjectId
Public Overridable Property Dimlfac As Double
Public Overridable Property Dimdec As Integer
Public Overridable Property Dimlim As Boolean
Public Overridable Property Dimltex2 As ObjectId
Public Overridable Property Dimltype As ObjectId
Public Overridable Property Dimlunit As Integer
Public Overridable Property Dimlwd As LineWeight
Public Overridable Property Dimlwe As LineWeight
Public Overridable Property Prefix As String
Public Overridable Property Suffix As String
Public Overridable Property SuppressAngularLeadingZeros As Boolean
Public Overridable Property SuppressAngularTrailingZeros As Boolean
Public Overridable Property SuppressLeadingZeros As Boolean
Public Overridable Property SuppressTrailingZeros As Boolean
Public Overridable Property SuppressZeroFeet As Boolean
Public Overridable Property SuppressZeroInches As Boolean
Public Overridable Property Dimltex1 As ObjectId
Public Overridable Property AlternatePrefix As String
Public Overridable Property Dimclrt As Color
Public Overridable Property Dimclrd As Color
Public Property Normal As Vector3d
Public Property Elevation As Double
Public Property DimensionText As String
Public Property TextRotation As Double
Public Property DimensionStyle As ObjectId
Public Property TextAttachment As AttachmentPoint
Public Property TextLineSpacingStyle As LineSpacingStyle
Public Property TextLineSpacingFactor As Double
Public Property HorizontalRotation As Double
Public Property DimBlockId As ObjectId
Public ReadOnly Property DimBlockPosition As Point3d
Public ReadOnly Property Measurement As Double
Public Property DynamicDimension As Boolean
Public Overridable Property Dimclre As Color
Public Overridable Property Dimadec As Integer
Public Overridable Property Dimaltd As Integer
Public Overridable Property Dimaltf As Double
Public Overridable Property Dimaltrnd As Double
Public Overridable Property Dimalttd As Integer
Public Overridable Property Dimalttz As Integer
Public Overridable Property Dimaltu As Integer
Public Overridable Property Dimaltz As Integer
Public Overridable Property Dimarcsym As Integer
Public Overridable Property Dimasz As Double
Public Overridable Property Dimatfit As Integer
Public Overridable Property Dimaunit As Integer
Public Overridable Property Dimazin As Integer
Public Overridable Property Dimcen As Double
Public Overridable Property Dimalt As Boolean
Public Property UsingDefaultTextPosition As Boolean
Public Overridable Property AlternateSuffix As String
Public Overridable Property AltSuppressTrailingZeros As Boolean
Public Overridable Property Dimtm As Double
Public Overridable Property Dimtmove As Integer
Public Overridable Property AltSuppressLeadingZeros As Boolean
Public Overridable Property Dimtoh As Boolean
Public Overridable Property Dimtol As Boolean
Public Overridable Property Dimtolj As Integer
Public Overridable Property Dimtp As Double
Public Overridable Property Dimtsz As Double
Public Overridable Property Dimtvp As Double
Public Overridable Property TextStyleId As ObjectId
Public Overridable Property Dimtxt As Double
Public Overridable Property Dimtix As Boolean
Public Overridable Property Dimtxtdirection As Boolean
Public Overridable Property Dimupt As Boolean
Public Overridable Property Dimzin As Integer
Public Overridable Property Dimapost As String
Public Overridable Property Dimpost As String
Public Overridable Property Dimblk As ObjectId
Public Overridable Property Dimblk1 As ObjectId
Public Overridable Property Dimblk2 As ObjectId
Public Overridable Property Dimmzs As String
Public Overridable Property Dimaltmzs As String
Public Overridable Property Dimmzf As Double
Public Overridable Property Dimaltmzf As Double
Public Overridable Property Dimtzin As Integer
Public Overridable Property Dimtih As Boolean
Public Overridable Property Dimtofl As Boolean
Public Overridable Property Dimtfill As Integer
Public Overridable Property AltSuppressZeroFeet As Boolean
Public Overridable Property AltSuppressZeroInches As Boolean
Public Overridable Property AltToleranceSuppressLeadingZeros As Boolean
Public Overridable Property AltToleranceSuppressTrailingZeros As Boolean
Public Overridable Property AltToleranceSuppressZeroFeet As Boolean
Public Overridable Property AltToleranceSuppressZeroInches As Boolean
Public Overridable Property ToleranceSuppressLeadingZeros As Boolean
Public Overridable Property Dimtfillclr As Color
Public Overridable Property ToleranceSuppressZeroFeet As Boolean
Public Overridable Property ToleranceSuppressZeroInches As Boolean
Public Overridable ReadOnly Property CenterMarkType As DimensionCenterMarkType
Public Overridable ReadOnly Property CenterMarkSize As Double
Public Overridable Property ToleranceSuppressTrailingZeros As Boolean
Public Overridable Property Dimrnd As Double
Public Overridable Property DimensionStyleName As String
Public Overridable Property Dimtdec As Integer
Public Overridable Property Dimtad As Integer
Public Overridable Property Dimsoxd As Boolean
Public Overridable Property Dimse2 As Boolean
Public Overridable Property Dimtfac As Double
Public Overridable Property Dimsd2 As Boolean
Public Overridable Property Dimsd1 As Boolean
Public Overridable Property Dimscale As Double
Public Overridable Property Dimsah As Boolean
Public Overridable Property Dimse1 As Boolean
Public Property TextPosition As Point3d
每个标注都可以替代该标注的标注样式中的设置值。以下特性可用于大多数标注对象:
- Dimatfit
- 指定标注线仅仅显示在尺寸界线的内部,并强制标注文字和箭头在尺寸界线的内部或外部。
- Dimaltrnd
- 指定换算单位的舍入。
- Dimasz
- 指定尺寸线箭头、引线箭头和勾线的大小。
- Dimaunit
- 指定角度标注的单位格式。
- Dimblk1, Dimblk2
- 指定用作尺寸线箭头的块。
- Dimcen
- 指定半径标注和直径标注的中心标记大小和类型。
- Dimclrd
- 指定标注、引线或公差对象的尺寸线颜色。
- Dimclre
- 指定标注尺寸界线的颜色。
- Dimclrt
- 指定标注和公差对象的文字颜色。
- Dimdec
- 指定标注或公差的主单位显示的小数位数。
- Dimdsep
- Specifies the character to be used as the decimal separator in decimal dimension and tolerance values.
- 指定在十进制标注和公差值中用作小数分隔符的字符
- Dimexe
- Specifies the distance the extension line extends beyond the dimension line.
- 指定尺寸界线超出尺寸线的距离。
- Dimexo
- Specifies the distance the extension lines are offset from the origin points.
- 指定尺寸界线从原点偏移的距离。
- Dimfrac
- Specifies the format of fractional values in dimensions and tolerances.
- 指定标注和公差中的分数值的格式。
- Dimgap
- Specifies the distance between the dimension text and the dimension line when you break the dimension line to accommodate dimension text.
- 指定当用户截断尺寸线以放置标注文字时,标注文字与尺寸线之间的距离。
- Dimlfac
- Specifies a global scale factor for linear dimension measurements.
- 指定线性标注测量值的全局比例因子。
- Dimltex1, Dimltex2
- Specifies the linetypes for the extension lines.
- 指定尺寸界线的线型。
- Dimlwd
- Specifies the lineweight for the dimension line.
- 指定尺寸线的线宽。
- Dimlwe
- Specifies the lineweight for the extension lines.
- 指定尺寸界线的线宽。
- Dimjust
- Specifies the horizontal justification for dimension text.
- 指定标注文字的水平对正方式。
- Dimrnd
- Specifies the distance rounding for dimension measurements.
- 指定尺寸测量值取整后的距离。
- Dimsd1, Dimsd2
- Specifies the suppression of the dimension lines.
- 指定是否隐藏尺寸线。
- Dimse1, Dimse2
- Specifies the suppression of extension lines.
- 指定是否隐藏尺寸界线。
- Dimtad
- Specifies the vertical position of text in relation to the dimension line.
- 指定与尺寸线相关联的文字的垂直位置。
- Dimtdec
- Specifies the precision of tolerance values in primary dimensions.
- 指定主标注中公差值的精度。
- Dimtfac
- Specifies a scale factor for the text height of tolerance values relative to the dimension text height.
- 指定公差值文字高度相对于标注文字高度的比例因子。
- Dimlunit
- Specifies the unit format for all dimensions except angular.
- 指定角度标注除外所有标注的单位格式。
- Dimtih
- Specifies if the dimension text is to be drawn inside the extension lines.
- 指定是否在尺寸界线之内绘制标注文字。
- Dimtm
- Specifies the minimum tolerance limit for dimension text.
- 指定标注文字的最小公差下限。
- Dimtmove
- Specifies how dimension text is drawn when text is moved.
- 指定当文字移动时标注文字的绘制方式。
- Dimtofl
- 指定所有标注类型(坐标标注除外)的标注文字是否位于尺寸界线之内。
- Dimtoh
- 指定所有标注类型(坐标标注除外)的标注文字在尺寸界线之外的位置。
- Dimtol
- 指定公差是否要与标注文字一起显示。
- Dimtolj
- 指定公差值相对于标注文字的垂直对正方式
- Dimtp
- 指定标注文字公差的上限。
- Dimtxt
- 指定标注或公差文字的高度。
- Dimzin
- 指定是否隐藏标注值中的零英尺和零英寸测量值。
- Prefix
- 指定标注值的前缀。
- Suffix
- 指定标注值的后缀。
- TextPrecision
- 指定角度标注文字的精度。
- TextPosition
- 指定标注文字的位置。
- TextRotation
- 指定标注文字的旋转角度。
为对齐标注输入用户定义的后缀
本例在模型空间中创建对齐标注,并使用 Suffix 特性让用户来修改标注的文字后缀。
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.SetDatabaseDefaults()
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
模型空间和图纸空间中的标注
可以在图纸空间和模型空间中绘制标注。但是,如果要标注的几何图形位于模型空间中,则最好在模型空间中绘制标注,因为 AutoCAD 会将定义点放在绘制几何图形的空间中。
如果用户在图纸空间中绘制标注,而此图纸空间用于描述模型空间中的几何图形,则当用户使用编辑命令或者修改模型空间视口中显示的放大比例时,图纸空间标注并不会改变。当用户将视图从图纸空间切换到模型空间时,图纸空间标注仍会停留在原处。
如果正在图纸空间进行标注,并且线性标注的全局比例因子(DIMLFAC 系统变量)已设置为小于 0(零),则测量的距离将被乘以 DIMLFAC 的绝对值。如果正在模型空间进行标注,则即使 DIMLFAC 小于 0(零),仍将使用值 1.0。如果在“标注”提示下更改变量并选择“视口”选项,则 AutoCAD 将计算 DIMLFAC 的值。AutoCAD 将计算从模型空间到图纸空间的缩放比例,并将该值的负值指定给 DIMLFAC。
创建引线和注释
引线是图形中将注释连接到特征的线。引线与其注释是关联的,也就是说,如果用户修改注释,引线也会随着更新。请勿混淆 Leader 对象和 AutoCAD 作为尺寸线的一部分而自动生成的引线。
- 创建引线
- 向引线添加注释
- 引线关联性
- 编辑引线关联性
- 编辑引线
可以从图形中的任意点或特征创建引线,并在绘制时控制其外观。引线可以是直线段或平滑的样条曲线。引线颜色由当前的尺寸线颜色控制。引线缩放比例由活动标注样式中设置的全局标注比例控制。箭头的类型和大小,如果有,由活动样式定义的第一个箭头控制。
注释通常由一条称为基线的小线连接到引线。如果最后一条引线段与水平线的夹角大于 15 度,则基线会与多行文字和特征控制框一起显示。基线具有一个箭头的长度。如果引线没有注释,它也就不会有基线。
用户通过创建 Leader 对象的实例来创建引线对象。当创建一个引线对象的实例时,它的构造函数不接受任何参数。它的 AppendVertex 方法常常用于定义引线的位置和长度。
本例在模型空间中创建一条引线。引线没有关联的注释。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("CreateLeader")> _
Public Sub CreateLeader()
'' 获得当前数据库 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 leader
Dim acLdr As Leader = New Leader()
acLdr.SetDatabaseDefaults()
acLdr.AppendVertex(New Point3d(0, 0, 0))
acLdr.AppendVertex(New Point3d(4, 4, 0))
acLdr.AppendVertex(New Point3d(4, 5, 0))
acLdr.HasArrowHead = True
'' 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acLdr)
acTrans.AddNewlyCreatedDBObject(acLdr, True)
'' 提交修改并销毁事务 Commit the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
引线注释可以是 公差、多行文本或块参照对象。用户可以创建新注释,也可附加现有注释的副本。通过指定注释对象的 ObjectID 给引线对象的 Annotation 属性为引线添加注释。
引线关联性
引线与其注释是关联的,因此当注释移动时,引线的端点也会随着移动。在移动文字注释和特征控制框注释时,引线的最后一段会根据注释与引线的倒数第二个点之间的关系,决定是附加到注释的左侧还是右侧。如果注释的中点在引线的倒数第二个点的右侧,则引线将附着到右侧,否则将附着到左侧。
使用 Erase、Add(添加块)或 WBlock 方法从图形中删除对象将失去关联性。如果在一次操作中同时复制了引线及其注释,则新的副本也具有关联性。如果分别复制它们,则新的副本没有关联性。如果因为任何原因失去了关联性,例如,只复制了 Leader 对象或删除了注释,基线都将从引线中删除。
本例创建 MText 对象。接着使用 MText 对象作为其注释来创建引线。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("AddLeaderAnnotation")> _
Public Sub AddLeaderAnnotation()
'' 获得当前数据库 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 MText annotation
Dim acMText As MText = New MText()
acMText.SetDatabaseDefaults()
acMText.Contents = "Hello, World."
acMText.Location = New Point3d(5, 5, 0)
acMText.Width = 2
'' 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acMText)
acTrans.AddNewlyCreatedDBObject(acMText, True)
''创建引线和注释 Create the leader with annotation
Dim acLdr As Leader = New Leader()
acLdr.SetDatabaseDefaults()
acLdr.AppendVertex(New Point3d(0, 0, 0))
acLdr.AppendVertex(New Point3d(4, 4, 0))
acLdr.AppendVertex(New Point3d(4, 5, 0))
acLdr.HasArrowHead = True
'' 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acLdr)
acTrans.AddNewlyCreatedDBObject(acLdr, True)
''引线对象添加后附加注释 Attach the annotation after the leader object is added
acLdr.Annotation = acMText.ObjectId
acLdr.EvaluateLeader()
'' 提交修改并销毁事务 Commit the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
除了引线和注释之间的关联性关系以外,引线与其注释在图形中是完全独立的两种对象。编辑引线不会影响注释,编辑注释也不会影响引线。
虽然可以使用 DIMCLRT、DIMTXT 和 DIMTXSTY 系统变量通过定义文字注释的颜色、高度和样式来创建文字注释,但是,不能通过这些系统变量对其进行更改,因为文字注释不是真正的标注对象。文字注释的编辑方式必须与任何其他 MText 对象的编辑方式相同。
使用 Evaluate 方法来评估引线及其关联注释的关系。这个方法在需要时会更新引线。
编辑引线
任何会改变引线注释位置的修改都会影响到关联引线的端点位置。另外,旋转注释也会使引线基线(如果有)随之旋转。
要调整引线的大小,可以将其缩放。如果缩放引线,则注释将保持与引线端点的相对位置不变,而不会进行缩放。除了缩放以外,还可以移动、镜像和旋转引线。使用 TransformBy 方法来编辑引线。也可以使用它的成员属性和方法修改关联注释。
使用形位公差
形位公差表示特征的形状、轮廓、方向、位置和跳动的极限偏差。可以通过特征控制框来添加形位公差。这些框会包含一个标注的所有公差信息。
创建形位公差
用户可以通过创建一个 FeatureControlFrame 对象的实例来创建形位公差。当创建一个 FeatureControlFrame 对象的实例时,它的构造函数可以接受一组可选的参数。当创建新的 FeatureControlFrame 对象时下列参数可以提供给它。
- Text string comprising the tolerance symbol (Text property)
- 组成公差符号的文本字符串(Text 属性)
- Insertion point (Location property)
- 插入点(Location 属性)
- Normal vector (Normal property)
- 法向矢量(Normal 属性)
- Direction vector (Direction property)
- 方向矢量(Direction 属性)
创建一个形位公司
面示例在模型空间中创建一个单一的形位公差。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("CreateGeometricTolerance")> _
Public Sub CreateGeometricTolerance()
'' 获得当前数据库 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 Geometric Tolerance (Feature Control Frame)
Dim acFcf As FeatureControlFrame = New FeatureControlFrame()
acFcf.SetDatabaseDefaults()
acFcf.Text = "{\Fgdt;j}%%v{\Fgdt;n}0.001%%v%%v%%v%%v"
acFcf.Location = New Point3d(5, 5, 0)
'' 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acFcf)
acTrans.AddNewlyCreatedDBObject(acFcf, True)
'' 提交修改并销毁事务 Commit the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
编辑形位公差
形位公差受几个环境变量和属性影响。下面的环境变量和属性影响形位公差的外观: