(3)复制基点与目标点和原文字与目标文字插入点的计算
这个就不详细说了,一些简单的计算
(4)生成一个新单行文字
这里用的AcadText对象的copy +move方法
以下为增量复制的完整代码
-
- Public Sub CopyTextIncrement() '增量复制
- Dim objText As AcadText, blnESC As Boolean
-
- SelectSingleText objText, blnESC
-
- If blnESC Then Exit Sub
-
- On Error GoTo Err2
-
- Dim IncreaseNum As Double
-
- IncreaseNum = ThisDrawing.Utility.GetReal("请输入增加量(可以为负,默认为1):")
-
- If IncreaseNum = 0 Then IncreaseNum = 1
-
- On Error GoTo err1
-
- Dim copyObj As AcadText, pt1, pt2
-
- Dim dx As Double, dy As Double, InsPt(2) As Double
-
- pt1 = ThisDrawing.Utility.GetPoint(, "请指定复制基点:")
- dx = pt1(0) - objText.InsertionPoint(0)
- dy = pt1(1) - objText.InsertionPoint(1)
-
- Do
- InsPt(0) = objText.InsertionPoint(0) + dx
- InsPt(1) = objText.InsertionPoint(1) + dy
- pt2 = ThisDrawing.Utility.GetPoint(InsPt, "请指定复制到点:")
- Set copyObj = objText.Copy()
-
- Dim strText As String, iPos As Integer, iDotPos As Integer, strFormat As String
-
- strText = RTrim(objText.TextString)
- iPos = Len(strText)
-
- Do While IsNumeric(Mid(strText, iPos))
- iPos = iPos - 1
-
- If iPos = 0 Then Exit Do
- Loop
-
- If iPos = Len(strText) Then
- strText = strText & CStr(IncreaseNum)
- Else
- iDotPos = InStr(iPos + 1, strText, ".", vbTextCompare) '取小数点位置
-
- If iDotPos 0 Then
- strFormat = "#." & String(Len(strText) - iDotPos, "0")
- strText = Mid(strText, 1, iPos) & Format(Val((Mid(strText, iPos + 1)) + _
- IncreaseNum), strFormat)
- Else
- strText = Mid(strText, 1, iPos) & CStr(Val((Mid(strText, iPos + 1)) + _
- IncreaseNum))
- End If
- End If
-
- copyObj.TextString = strText
- copyObj.Move InsPt, pt2
- objText.Highlight False
- Set objText = copyObj
- objText.Highlight True
- Loop
-
- Exit Sub
-
- err1:
- Err.Clear
- objText.Highlight False
- Debug.Print Err.Description
-
- Exit Sub
-
- Err2:
- Err.Clear
-
- Resume Next
-
- End Sub
|