13022164437 发表于 2008-10-21 11:57:00

求高手指点,若有交点,交点坐标写入数组,若无则不写入

For Each ent In ThisDrawing.ModelSpace
   
intPoints = vbEmpty

intPoints = lineObj.IntersectWith(ent, acExtendNone)
      If VarType(intPoints)vbEmpty Then
   
ReDim Preserve px(I) As Variant
   
ReDim Preserve py(I) As Variant
   
ReDim Preserve pz(I) As Variant
   
px(I) = intPoints(0)
   
py(I) = intPoints(1)
   
pz(I) = intPoints(2)
   
   
MsgBox px(I) & py(I) & pz(I)

End If
Next ent

sailorcwx 发表于 2008-10-21 12:54:00

看不懂你的,我写了一个Sub test()
On Error Resume Next
Dim obj1 As AcadEntity
Dim pt As Variant
ThisDrawing.Utility.GetEntity obj1, pt
Dim bpts(0 To 11) As Double
Dim minpt As Variant
Dim maxpt As Variant
obj1.GetBoundingBox minpt, maxpt
bpts(0) = minpt(0)
bpts(1) = minpt(1)
bpts(2) = minpt(2)
bpts(3) = minpt(0)
bpts(4) = maxpt(1)
bpts(5) = minpt(2)
bpts(6) = maxpt(0)
bpts(7) = maxpt(1)
bpts(8) = maxpt(2)
bpts(9) = maxpt(0)
bpts(10) = minpt(1)
bpts(11) = maxpt(2)
Dim ss As AcadSelectionSet
ThisDrawing.SelectionSets.Add ("test")
Set ss = ThisDrawing.SelectionSets.Item("test")
ss.SelectByPolygon acSelectionSetCrossingPolygon, bpts
For Each obj In ss
If Not (obj Is obj1) Then
'MsgBox "OK"
'Else
Dim ipts As Variant
ipts = obj1.IntersectWith(obj, acExtendNone)
MsgBox "有" & (UBound(ipts) + 1) / 3 & "个交点"
End If
Next
End Sub

13022164437 发表于 2008-10-21 14:06:00

我想获取模型空间中指定直线的交点,但是判断语句不对,执行时不管与指定直线有没有交点,i值总是加1
如何判断有交点时i加1,没有时i值不变?

13022164437 发表于 2008-10-21 14:26:00

刚才运行了sailorcwx的代码,感觉判断语句有问题,结果上传如图。
页: [1]
查看完整版本: 求高手指点,若有交点,交点坐标写入数组,若无则不写入