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