如果两个对象不相交,则没有返回数据。也就是说如果你定义RetVal为变体,如果相交可以得到一个双精度数组,可以通过错误处理来判断(下面是我临时写的,具体的东西和你不太一样,你参考一下就行了)
Sub main() Dim retval As Variant Dim obj1 As AcadLine Dim obj2 As AcadLine Set obj1 = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 2) Set obj2 = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1) retval = obj1.IntersectWith(obj2, acExtendNone) On Error Resume Next Dim aa As Double aa = retval(0) If Err Then Err.Clear MsgBox "两个图元没有交点!" Exit Sub Else MsgBox "两个图元的交点坐标为 (" & retval(0) & "," & retval(1) & "," & retval(2) & ")" End If
on error goto 0 '继续你的程序 End Sub |