alexluoke 发表于 2006-5-25 11:10:00

[VBA]

<P>请教高手:</P>
<P>怎样判断两个图元对象是否有交点?&nbsp;&nbsp;&nbsp; </P>
<P>我用 if TypeOf obj1.Intersectwith(obj2,acExtendnone) Is Null</P>
<P>和if&nbsp; obj1.Intersectwith(obj2,acExtendnone)&nbsp;= Null均无效</P>

xinghesnak 发表于 2006-5-25 15:02:00

<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>&nbsp;&nbsp;&nbsp;&nbsp;Err.Clear<BR>&nbsp;&nbsp;&nbsp; MsgBox "两个图元没有交点!"<BR>&nbsp;&nbsp;&nbsp; Exit Sub<BR>Else<BR>&nbsp;&nbsp;&nbsp; MsgBox "两个图元的交点坐标为 (" &amp; retval(0) &amp; "," &amp; retval(1) &amp; "," &amp; retval(2) &amp; ")"<BR>End If</P>
<P>on error goto 0<BR>'继续你的程序<BR>End Sub</P>
页: [1]
查看完整版本: [VBA]