- 积分
- 10513
- 明经币
- 个
- 注册时间
- 2002-6-3
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2003-11-24 19:58:00
|
显示全部楼层
- Sub Example_Select()
-
- ' 创建选择集
- Dim ssetObj As AcadSelectionSet
-
- On Error Resume Next
- Set ssetObj = ThisDrawing.SelectionSets("SSET")
- If Err Then
- Err.Clear
- Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
- End If
- ssetObj.Clear
-
- '构造过滤机制
- Dim groupCode(0) As Integer
- Dim dataCode(0) As Variant
- groupCode(0) = 0
- dataCode(0) = "lwPolyline"
- ssetObj.Select acSelectionSetAll, , , groupCode, dataCode
-
- '更好的方法是只选中与直线外框相交或者位于其中的对象
-
- '获取直线的外框
- Dim corner1 As Variant
- Dim corner2 As Variant
- 'Dim lineObj As AcadLine
- 'Set lineObj = ThisDrawing.ModelSpace(0)
- lineObj.GetBoundingBox corner1, corner2 'lineObj为位于0层的直线
-
- ssetObj.Select acSelectionSetCrossing, corner1, corner2, groupCode, dataCode
-
- '枚举交点,判断是否相交
- Dim Pts As Variant
- Dim i As Integer
- Dim j As Integer
- For i = 0 To ssetObj.Count - 1
- Pts = ssetObj(i).IntersectWith(lineObj, acExtendNone)
- If Not IsEmpty(Pts) Then
- Debug.Print "多段线(" & ssetObj(i).Handle & ")与直线(" & lineObj.Handle & ")相交"
- For j = 0 To UBound(Pts) Step 3
- Debug.Print "交点:" & Pts(j) & "," & Pts(j + 1) & "," & Pts(j + 2)
- Next
- End If
- Next
- End Sub
- 多段线(2D)与直线(2B)相交
- 交点:128.258445252942,175.187446678566,0
- 多段线(2C)与直线(2B)相交
- 交点:124.856166338691,177.858572554345,0
- 交点:146.95855737489,160.506006788479,0
- 交点:176.484246297653,137.325417051576,0
|
|