CAD读数如图面100,时有,时无?
Public Sub numberVBA()
'定义点
Dim pt1 As Variant
Dim pt2 As Variant
pt1 = ThisDrawing.Utility.GetPoint(, "请选择第一点:")
pt2 = ThisDrawing.Utility.GetPoint(, "请选择第二点:")
'(1)安全地创建选择集
On Error Resume Next
Dim SSet As AcadSelectionSet
If Not IsNull(ThisDrawing.SelectionSets.Item("Example")) Then
Set SSet = ThisDrawing.SelectionSets.Item("Example")
SSet.Delete '及时删除不用的选择集非常重要
End If
Set SSet = ThisDrawing.SelectionSets.Add("Example")
'(2)向选择集中添加对象
'设置选择过滤器
Dim FilterType(0) As Integer
Dim FilterData(0) As Variant
FilterType(0) = 0
FilterData(0) = "TEXT"
'使用Crossing的选择模式
SSet.Select acSelectionSetCrossing, pt1, pt2, FilterType, FilterData
'(3)遍历其中的对象
Dim filterEnt As Object
Dim Textobj As AcadText
For Each filterEnt In SSet
If filterEnt.value = True Then
Dim A As Integer
Dim B As Integer
A = filterEnt.TextString
B = A * 2
Set Textobj = ThisDrawing.ModelSpace.AddText(B, pt1, 50)
End If
Next filterEnt
'(4)删除选择集
'SSet.Erase '删除选择集中所有对象,保留选择集对象
'SSet.Delete '删除选择集,保留其中对象
'删除选择集和其中所有对象
SSet.Delete
End Sub |