- UID
- 292482
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-7-12
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2006-9-20 18:32:59
|
显示全部楼层
我采用了 在建立选择集前,删除所有的选择集。还有对多个选择集操作时候,可以设置活动的(当前)选择集,问题是接着就出来了,程序根本不按照我的思路来执行,请飞狐兄及其他的高手指教。(附有试验用的数据,请大家帮忙看看吧)
'悬垂点的检查
'悬垂点的检查
Sub chkpline()
' 创建选择集
Dim i, j, k, m, e As Integer
Dim sset As Object
For e = 0 To ThisDrawing.SelectionSets.count - 1
ThisDrawing.SelectionSets.Item(e).Delete
Next
Set sset = ThisDrawing.SelectionSets.Add("SS1")
On Error GoTo xxx
' 提示用户选择对象
sset.SelectOnScreen
Dim selsetCollection As AcadSelectionSets
Dim selset As AcadSelectionSet
Dim SelPoly As AcadSelectionSet
Dim Ent As AcadObject
Dim circleObj As AcadObject
Dim offsetOb As AcadObject
Dim n As Integer
Dim vps As Variant
Dim cen(0 To 2) As Double
Dim cen1(0 To 2) As Double
Dim NewCoord(0 To 23) As Double
Dim ying As String
Dim plineObj As AcadPolyline
'Dim dis, yjq As Double
ying = ThisDrawing.Utility.GetString(False, "两点相距多少视为一点<0.05>:")
If Trim(ying) = "" Then
ying = "0.05"
End If
Set selsetCollection = ThisDrawing.SelectionSets
' 查找图形中的每个选择集
i = 0
j = 0
For Each selset In selsetCollection
MsgBox "Selectionsets nub is: " & ThisDrawing.SelectionSets.count
MsgBox "Selectionset下的对象数目: " & selset.count
' 现在查找选择集中的每个对象,同时显示其类型
'ReDim newObjs(selset.count) As AcadObject
For i = 0 To selset.count - 1
Set Ent = selset.Item(i)
If Ent.ObjectName = "AcDbPolyline" Then
vps = Ent.Coordinates
MsgBox "i= " & i
For k = 0 To UBound(vps) - 1 Step 2
cen(0) = vps(k)
cen(1) = vps(k + 1)
cen(2) = 0
NewCoord(0) = vps(k) - Val(ying) / 1.414
NewCoord(1) = vps(k + 1) + Val(ying) / 1.414
NewCoord(2) = 0
NewCoord(3) = vps(k)
NewCoord(4) = vps(k + 1) + Val(ying)
NewCoord(5) = 0
NewCoord(6) = vps(k) + Val(ying) / 1.414
NewCoord(7) = vps(k + 1) + Val(ying) / 1.414
NewCoord(8) = 0
NewCoord(9) = vps(k) + Val(ying)
NewCoord(10) = vps(k + 1)
NewCoord(11) = 0
NewCoord(12) = vps(k) + Val(ying) / 1.414
NewCoord(13) = vps(k + 1) - Val(ying) / 1.414
NewCoord(14) = 0
NewCoord(15) = vps(k)
NewCoord(16) = vps(k + 1) - Val(ying)
NewCoord(17) = 0
NewCoord(18) = vps(k) - Val(ying) / 1.414
NewCoord(19) = vps(k + 1) - Val(ying) / 1.414
NewCoord(20) = 0
NewCoord(21) = vps(k) - Val(ying)
NewCoord(22) = vps(k + 1)
NewCoord(23) = 0
Set SelPoly = ThisDrawing.SelectionSets.Add("SelP0")
Set SelPoly = ThisDrawing.ActiveSelectionSet
ThisDrawing.SelectionSets.Item("SelP0").Clear
SelPoly.SelectByPolygon acSelectionSetCrossingPolygon, NewCoord
MsgBox "SelPoly.count: " & SelPoly.count
If SelPoly.count > 1 Then
Set circleObj = ThisDrawing.ModelSpace.AddCircle(cen, 5)
circleObj.Color = acGreen
End If
' Set plineObj = ThisDrawing.ModelSpace.AddPolyline(NewCoord)
Set sset = ThisDrawing.ActiveSelectionSet
ThisDrawing.SelectionSets.Item("SelP0").Delete
Next
End If
Next
Next
xxx:
ThisDrawing.SelectionSets.Item("SS1").Delete
End Sub
Sub chkpline()
' 创建选择集
Dim i, j, k, m, e As Integer
Dim sset As Object
For e = 0 To ThisDrawing.SelectionSets.count - 1
ThisDrawing.SelectionSets.Item(e).Delete
Next
Set sset = ThisDrawing.SelectionSets.Add("SS1")
On Error GoTo xxx
' 提示用户选择对象
sset.SelectOnScreen
Dim selsetCollection As AcadSelectionSets
Dim selset As AcadSelectionSet
Dim SelPoly As AcadSelectionSet
Dim Ent As AcadObject
Dim circleObj As AcadObject
Dim offsetOb As AcadObject
Dim n As Integer
Dim vps As Variant
Dim cen(0 To 2) As Double
Dim cen1(0 To 2) As Double
Dim NewCoord(0 To 23) As Double
Dim ying As String
Dim plineObj As AcadPolyline
'Dim dis, yjq As Double
ying = ThisDrawing.Utility.GetString(False, "两点相距多少视为一点<0.05>:")
If Trim(ying) = "" Then
ying = "0.05"
End If
Set selsetCollection = ThisDrawing.SelectionSets
' 查找图形中的每个选择集
i = 0
j = 0
For Each selset In selsetCollection
MsgBox "Selectionsets nub is: " & ThisDrawing.SelectionSets.count
MsgBox "Selectionset下的对象数目: " & selset.count
' 现在查找选择集中的每个对象,同时显示其类型
'ReDim newObjs(selset.count) As AcadObject
For i = 0 To selset.count - 1
Set Ent = selset.Item(i)
If Ent.ObjectName = "AcDbPolyline" Then
vps = Ent.Coordinates
MsgBox "i= " & i
For k = 0 To UBound(vps) - 1 Step 2
cen(0) = vps(k)
cen(1) = vps(k + 1)
cen(2) = 0
NewCoord(0) = vps(k) - Val(ying) / 1.414
NewCoord(1) = vps(k + 1) + Val(ying) / 1.414
NewCoord(2) = 0
NewCoord(3) = vps(k)
NewCoord(4) = vps(k + 1) + Val(ying)
NewCoord(5) = 0
NewCoord(6) = vps(k) + Val(ying) / 1.414
NewCoord(7) = vps(k + 1) + Val(ying) / 1.414
NewCoord(8) = 0
NewCoord(9) = vps(k) + Val(ying)
NewCoord(10) = vps(k + 1)
NewCoord(11) = 0
NewCoord(12) = vps(k) + Val(ying) / 1.414
NewCoord(13) = vps(k + 1) - Val(ying) / 1.414
NewCoord(14) = 0
NewCoord(15) = vps(k)
NewCoord(16) = vps(k + 1) - Val(ying)
NewCoord(17) = 0
NewCoord(18) = vps(k) - Val(ying) / 1.414
NewCoord(19) = vps(k + 1) - Val(ying) / 1.414
NewCoord(20) = 0
NewCoord(21) = vps(k) - Val(ying)
NewCoord(22) = vps(k + 1)
NewCoord(23) = 0
Set SelPoly = ThisDrawing.SelectionSets.Add("SelP0")
Set SelPoly = ThisDrawing.ActiveSelectionSet
ThisDrawing.SelectionSets.Item("SelP0").Clear
SelPoly.SelectByPolygon acSelectionSetCrossingPolygon, NewCoord
MsgBox "SelPoly.count: " & SelPoly.count
If SelPoly.count > 1 Then
Set circleObj = ThisDrawing.ModelSpace.AddCircle(cen, 5)
circleObj.Color = acGreen
End If
' Set plineObj = ThisDrawing.ModelSpace.AddPolyline(NewCoord)
Set sset = ThisDrawing.ActiveSelectionSet
ThisDrawing.SelectionSets.Item("SelP0").Delete
Next
End If
Next
Next
xxx:
ThisDrawing.SelectionSets.Item("SS1").Delete
End Sub |
|