- 积分
- 23130
- 明经币
- 个
- 注册时间
- 2008-11-22
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2014-10-25 22:57:03
|
显示全部楼层
本帖最后由 zzyong00 于 2014-10-25 22:58 编辑
2、坐标标注
坐标标注本身很简单,类似的工具满天飞,我这里也贴一个
- Public Sub SeriesCoordinate() '连续标坐标
- Dim blnExitSeriesCoord As Boolean
- ' InitCommonVar
- '全局变量
- Coordinate_TextHeight = 3
- ratio = 1
- TextRowSpace = 0.6
- Do
- Coordinate blnExitSeriesCoord '本子过程源码需要回复才能看到
- Loop Until blnExitSeriesCoord
- End Sub
- On Error GoTo err1
- ' Dim Coordinate_TextHeight As Double '文字高
- ' Dim Ratio As Double '全局比例
- ' Dim TextRowSpace As Double '文字行间距
- ' Coordinate_TextHeight = 3
- ' Ratio = 1
- ' TextRowSpace = 0.6
- Dim p1, p2 '标注点坐标,标注文字位置
- p1 = ThisDrawing.Utility.GetPoint(, "请点击要标注的点(按回车键退出):")
- p2 = ThisDrawing.Utility.GetPoint(p1, "请点击标注位置(按回车键退出):")
- Dim T1 As AcadText, T2 As AcadText
- Dim strT As String, intStrL1 As Integer, intStrL2 As Integer 'Y和X坐标文字的长度
- strT = "X " & Format$(p1(1), "0.000")
- intStrL1 = Len(strT)
- Dim pt1(2) As Double, pt2(2) As Double '文字坐标
- If p2(0) > p1(0) Then '确定标注点与标注文字位置的左右关系,以确定文字插入点
- pt1(0) = p2(0)
- pt1(1) = p2(1) + TextRowSpace / 2 * Coordinate_TextHeight * ratio
- Else
- pt1(0) = p2(0) - intStrL1 * Coordinate_TextHeight * ratio * _
- ThisDrawing.ActiveTextStyle.Width ^ 2 '宽度比例(总是宽度比例的平方,因为当前文字样式设了宽度,而AcadText本身又有个ScaleFactor,而且等于width)
- pt1(1) = p2(1) + TextRowSpace / 2 * Coordinate_TextHeight * ratio
- End If
- Set T1 = ThisDrawing.ModelSpace.AddText(strT, pt1, Coordinate_TextHeight * ratio)
- T1.Visible = False
- strT = "Y " & Format$(p1(0), "0.000")
- intStrL2 = Len(strT)
- pt2(0) = pt1(0)
- pt2(1) = pt1(1) - T1.Height * (1 + TextRowSpace) 'TextRowSpace代表文字间距是TextRowSpace倍的字高
- Set T2 = ThisDrawing.ModelSpace.AddText(strT, pt2, Coordinate_TextHeight * ratio)
- T2.Visible = False
- Dim Pend(2) As Double '标注结束点
- Pend(0) = p2(0)
- Dim TminP, TmaxP
- If intStrL1 > intStrL2 Then '取最长文字长度
- T1.GetBoundingBox TminP, TmaxP
- Else
- T2.GetBoundingBox TminP, TmaxP
- End If
- If p2(0) > p1(0) Then '确定标注点与标注文字位置的左右关系,以确定标注结束点位置
- Pend(0) = p2(0) + (TmaxP(0) - TminP(0))
- Pend(1) = p2(1)
- Else
- Pend(0) = p2(0) - (TmaxP(0) - TminP(0))
- Pend(1) = p2(1)
- pt1(0) = Pend(0)
- pt2(0) = Pend(0)
- T1.InsertionPoint = pt1
- T2.InsertionPoint = pt2
- End If
- T1.Visible = True
- T2.Visible = True
- Dim L1 As AcadLine, L2 As AcadLine
- Set L1 = ThisDrawing.ModelSpace.AddLine(p1, p2)
- Set L2 = ThisDrawing.ModelSpace.AddLine(p2, Pend)
- Exit Sub
- err1:
- Err.Clear
- blnExitSeriesCoord = True
- End Sub
对于vb或vba来说,在没创建AcadText对象之前,很难精确算出AcadText对象的长度,本例子中,先大致估算,然后生成AcadText对象,但暂时隐藏它,通过GetBoundingBox 取得AcadText对象真实大小后,再调整AcadText对象位置和直线长度!
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|