intersectWith函数存在Bug?
<P>具体内容请参加下面的贴子:<BR><A href="dispbbs.asp?boardID=14&ID=48355&page=1" target="_blank" >dispbbs.asp?boardID=14&ID=48355&page=1</A></P><P>下面是我写的一段测试代码:<BR>Public Sub test()<BR> On Error GoTo LAST<BR> <BR> Dim sset As AcadSelectionSet<BR> Set sset = ThisDrawing.SelectionSets.Add("Exapmle")<BR> sset.SelectOnScreen<BR> <BR> If sset.Count = 2 Then<BR> Dim ent1 As AcadEntity, ent2 As AcadEntity<BR> Set ent1 = sset.Item(0)<BR> Set ent2 = sset.Item(1)<BR> Dim pt As Variant<BR> pt = ent1.IntersectWith(ent2, acExtendNone)<BR> <BR> If UBound(pt) < 0 Then<BR> MsgBox "无交点"<BR> Else<BR> MsgBox "有交点"<BR> End If<BR> End If<BR> <BR>LAST:<BR> sset.Delete<BR>End Sub<BR></P> <P>请版主多多发上VBA知识!</P> 试了一下确实有问题,我试了有3组有交点,一组无交点,怪了。 <P>确实只能求2个交点。。。</P>
<P>可能是cad实数运算的误差导致,但是用region的时候,在很小的阈值内cad自动处理了(当作闭合)</P> 同意楼上的意见,已经准备用别的方案来实现。 请教版主,如何求面域和直线的交点?
运行代码时,老是提示:object requred!
Sub Ch4_CreateRegion()
' 定义数组以保存面域的边界。
Dim curves(0 To 0) As AcadCircle
' 创建形成面域边界的圆。
Dim center(0 To 2) As Double
Dim radius As Double
center(0) = 2
center(1) = 2
center(2) = 0
radius = 5#
Set curves(0) = ThisDrawing.ModelSpace.AddCircle(center, radius)
Dim regionObj As Variant' 创建面域
regionObj = ThisDrawing.ModelSpace.AddRegion(curves)
Dim pnt(0 To 2) As Double, pnt2(0 To 2) As Double
pnt(0) = 0: pnt(1) = 0: pnt(2) = 0
pnt2(0) = 0: pnt2(1) = 50: pnt2(2) = 0
Dim line As AcadLine
Set line = ThisDrawing.ModelSpace.AddLine(pnt, pnt2)
Dim inter_pnt As Variant
inter_pnt = line.IntersectWith(regionObj, acExtendNone)
MsgBox inter_pnt(0)
ZoomAll
End Sub
交点最好用集合来做selectiom.item改成collection.item。 本帖最后由 crazylsp 于 2014-12-3 17:13 编辑
Dim regionObj As Variant' 创建面域
面域是变量?可能是acadobject或acadRegion。 跟高程有关吧?elevation 两条相交线的高程应相等?
页:
[1]