Intersectwith方法得出错误结果
您好;ve外部参照是一个分解的多面网格,因此它由三角形面组成。我正在编写代码,使用网格中的三角形计算直线上的标高。本人';我写了一个版本,它可以工作,但速度很慢-对于多段线中的每个点,它会查看网格中的每个三角形,直到找到该点所在的三角形,然后对该级别进行插值。所以我想我可以通过减少要循环通过的三角形的数量来加快速度,通过找到哪些三角形切割多段线,然后我只需要循环通过这些三角形。问题是我的代码没有';t work-表示网格中的每个三角形都与直线相交代码如下(这只是要查找的位来过滤三角形,而不是插值位):Sub LevelFromTria2()
Dim objPLine As AcadLWPolyline
Dim objTria As Acad3DFace
Dim varCoords As Variant'
Dim objBlock As AcadBlock
Dim lngCount As Long
Dim objTriaSides As AcadLWPolyline
Dim varIntPoints As Variant
Dim dblTriaSidesCoords(0 To 5) As Double
Dim varPnt As Variant
On Error Resume Next '* Do so that if layer exists no error
ThisDrawing.Layers.Add ("Temp Triangles")
On Error GoTo 0
ThisDrawing.Utility.GetEntity objPLine, varPnt, "Select polyline: "
Set objBlock = ThisDrawing.Blocks("draw tria exploded")
'* Go through all the items in the xref
For lngCount = 0 To objBlock.Count - 1
'* See if the item is a 3d face
If objBlock.Item(lngCount).ObjectName = "AcDbFace" Then
'* If it is get the face element
Set objTria = objBlock.Item(lngCount)
'* See if the face intersects with the polyline
varIntPoints = objTria.IntersectWith(objPLine, acExtendNone)
'* If it does, draw the triangle - TEMP MEASURE TO SEE IF IT IS FINDING THE RIGHT TRIANGLES
If VarType(varIntPoints)vbEmpty Then
'* Get co-ords of the 3d face
varCoords = objTria.Coordinates
'* Set up 2d coords for the triangle edge
dblTriaSidesCoords(0) = varCoords(0)
dblTriaSidesCoords(1) = varCoords(1)
dblTriaSidesCoords(2) = varCoords(3)
dblTriaSidesCoords(3) = varCoords(4)
dblTriaSidesCoords(4) = varCoords(6)
dblTriaSidesCoords(5) = varCoords(7)
'* Add a LW polyline to show the triangle which intersects with the polyline
Set objTriaSides = ThisDrawing.ModelSpace.AddLightWeightPolyline(dblTriaSidesCoords)
objTriaSides.Closed = True
objTriaSides.Layer = "Temp Triangles"
objTriaSides.color = acMagenta
objTriaSides.Update
End If
End If
Next lngCount
End Sub
附件是我正在测试的图形。我试图获取级别的那条线是黄线-因此在提示时选择它
I';我想我';我的相交方法出了点问题。而不是使用脸本身;我也试着用它做一条LW多段线,但这并没有#039;也不行
如果您能就如何实现上述功能提出任何建议,我们将不胜感激。(或者,如果你有另一个概念来加速从三角测量中获取水平线的方式,我也很感兴趣!)
谢谢Jon
**** Hidden Message ***** PS:在示例中,绘制的线位于许多三角形的边缘,在情况I#039中可能会发生很多情况;我为…提供餐饮。我不知道';我不知道这是否会引发测试I#039;我在做,但奇怪的是为什么它选择了所有的三角形? 如果VarType(varIntPoints)<&燃气轮机;vbEmpty  ;不#039;t工作,因为计数-1(无交点)不为空 谢谢Bryco。我在Autodesk论坛上找到了类似的答案。我只是按照帮助文件-这是错误的!
页:
[1]