代码改变世界

VB编程修改AutoCAD长度型尺寸标注

2011-06-19 22:35  精诚所至 金石为开  阅读(935)  评论(0编辑  收藏  举报

用于长度型尺寸标注编辑的属性十分丰富,TextOverride属性可用于修改尺寸标注的文本,该属性适用于除了导线型标注之外的所有尺寸标注对象,尺寸标注的默认数值默认显示为AutoCAD自动计算的实际测量值。

要修改尺寸标注的文本显示,可设置TextOverride属性,用自定义字符串取代实际测量值。下面的程序用AddDimAligned方法返回尺寸标注的实际测量值,设置TextOverride属性,用自定义数值取代尺寸标注的实际测量值。

Private Sub Command1_Click()
    Dim leaderobj As AcadLeader
    Dim points(0 To 8) As Double
    Dim leadertype As Integer
    Dim annotationobject As AcadObject
    Dim mtextobj As AcadMText
    Dim corner(0 To 2) As Double
    Dim width As Double
    Dim text As String
    corner(0) = 0#: corner(1) = 15#: corner(2) = 0#
    width = 30
    text = "R1.5(min)"
    Set mtextobj = acadapp.ActiveDocument.ModelSpace.AddMText(corner, width, text)
    Set annotationobject = mtextobj
    points(0) = 0: points(1) = 0: points(2) = 0
    points(3) = 4: points(4) = 4: points(5) = 0
    points(6) = 4: points(7) = 5: points(8) = 0
    leadertype = acLineWidthArrow
    Set leaderobj = acadapp.ActiveDocument.ModelSpace.AddLeader(points, annotaionobject, leadertype)
    ZoomExtents
End Sub

DimensionLineColor属性用来设置标注尺寸线的颜色,适用于所有尺寸标注对象,不同的颜色可用颜色索引值或内置颜色来设置。VerticalTextPosition属性设置标注文字在垂直标注线方向的位置,适用于所有尺寸标注对象,下面的代码创建一个指定角度的尺寸标注,并设置标尺文字位于标注线中心位置。

Private Sub Command1_Click()
    Dim dimobj As AcadDimRotated
    Dim point1(0 To 2) As Double
    Dim point2(0 To 2) As Double
    Dim location(0 To 2) As Double
    Dim rotangle As Double
    point1(0) = 5#: point1(1) = 0#: point1(2) = 0#
    point2(0) = 5#: point2(1) = 25#: point2(2) = 0#
    location(0) = 30#: location(1) = 0#: location(2) = 0#
    rotangle = 90
    rotangle = rotangle * 3.14 / 180#
    Set dimobj = acadapp.ActiveDocument.ModelSpace.AddDimRotated(point1, point2, location, rotangle)
    dimobj.VerticalTextPosition = acOutside
    dimobj.Update
    ZoomExtents
End Sub