- UID
- 5244
- 积分
- 1648
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-18
- 最后登录
- 1970-1-1
|
发表于 2003-12-5 23:22:00
|
显示全部楼层
首先选择所有的直线,依次生成东、北、西、南的射线,求与直线的交点。
- [FONT=courier new]
- Sub test()
- Const PI = 3.1415926
-
- On Error Resume Next
- ' 创建选择集
- Dim SSetObj As Object
- Set SSetObj = ThisDrawing.SelectionSets("SSET")
- If Err.Number <> 0 Then
- Err.Clear
- Set SSetObj = ThisDrawing.SelectionSets.Add("SSET")
- End If
- SSetObj.Clear
-
- On Error GoTo ErrTrap
- '创建过滤机制
- Dim fType(0 To 0) As Integer
- Dim fData(0 To 0) As Variant
- fType(0) = 0: fData(0) = "LINE"
-
- '选择所有直线
- SSetObj.Select acSelectionSetAll, , , fType, fData
-
- ' 选择点
- Dim Pt As Variant
- Pt = ThisDrawing.Utility.GetPoint(, "指定单元格内的一点: ")
-
- ' 确定射线的另一点(两点定出方向,这里是东向)
- Dim tPt As Variant
- tPt = ThisDrawing.Utility.PolarPoint(Pt, 0, 1)
- ' 创建射线
- Dim RayObj As AcadRay
- Set RayObj = ThisDrawing.ModelSpace.AddRay(Pt, tPt)
-
- Dim MaxX As Double
- MaxX = 99999999
- Dim EntObj As AcadEntity
- Dim v As Variant
- ' 枚举选择集
- For Each EntObj In SSetObj
- v = EntObj.IntersectWith(RayObj, acExtendNone)
- ' 直线与射线相交
- If Not IsEmpty(v) Then
- If UBound(v) > 0 Then If v(0) <= MaxX Then MaxX = v(0)
- End If
- Next
- RayObj.Delete
-
- ' 确定射线的另一点(两点定出方向,这里是北向)
- tPt = ThisDrawing.Utility.PolarPoint(Pt, PI / 2, 1)
- ' 创建射线
- Set RayObj = ThisDrawing.ModelSpace.AddRay(Pt, tPt)
-
- Dim MaxY As Double
- MaxY = 99999999
- ' 枚举选择集
- For Each EntObj In SSetObj
- v = EntObj.IntersectWith(RayObj, acExtendNone)
- ' 直线与射线相交
- If Not IsEmpty(v) Then
- If UBound(v) > 0 Then If v(1) <= MaxY Then MaxY = v(1)
- End If
- Next
- RayObj.Delete
-
- ' 确定射线的另一点(两点定出方向,这里是西向)
- tPt = ThisDrawing.Utility.PolarPoint(Pt, PI, 1)
- ' 创建射线
- Set RayObj = ThisDrawing.ModelSpace.AddRay(Pt, tPt)
-
- Dim MinX As Double
- MinX = -99999999
- ' 枚举选择集
- For Each EntObj In SSetObj
- v = EntObj.IntersectWith(RayObj, acExtendNone)
- ' 直线与射线相交
- If Not IsEmpty(v) Then
- If UBound(v) > 0 Then If v(0) >= MinX Then MinX = v(0)
- End If
- Next
- RayObj.Delete
-
- ' 确定射线的另一点(两点定出方向,这里是南向)
- tPt = ThisDrawing.Utility.PolarPoint(Pt, PI * 3 / 2, 1)
- ' 创建射线
- Set RayObj = ThisDrawing.ModelSpace.AddRay(Pt, tPt)
-
- Dim MinY As Double
- MinY = -99999999
- ' 枚举选择集
- For Each EntObj In SSetObj
- v = EntObj.IntersectWith(RayObj, acExtendNone)
- ' 直线与射线相交
- If Not IsEmpty(v) Then
- If UBound(v) > 0 Then If v(1) >= MinY Then MinY = v(1)
- End If
- Next
- RayObj.Delete
- Set RayObj = Nothing
- Set EntObj = Nothing
- Set SSetObj = Nothing
-
- ' 打印数据
- Debug.Print "单元格的宽度: " & MaxX - MinX
- Debug.Print "单元格的高度: " & MaxY - MinY
- Debug.Print "单元格的左下角点: " & MinX & "," & MinY
- Debug.Print "单元格的右上角点: " & MaxX & "," & MaxY
- Debug.Print "单元格的中心点: " & (MinX + MaxX) / 2 & "," & (MinY + MaxY) / 2
- Exit Sub
-
- ErrTrap:
- On Error GoTo 0
- End Sub
- 立即窗口内容:
- 单元格的宽度: 106.349332501451
- 单元格的高度: 64.3045875866011
- 单元格的左下角点: 181.33924617877,84.7403666158115
- 单元格的右上角点: 287.688578680221,149.044954202413
- 单元格的中心点: 234.513912429495,116.892660409112
- [/FONT]
|
|