fadai 发表于 2009-12-14 22:22:00

請問如何選取畫好的pline找到各節點座標跟bulge

<p>謝謝大大</p><p>想請問一下這個問題</p><p>選取畫好的pline找到各節點座標跟bulge</p><p>目前座標已經解決 可是bulge一直抓不到 方法也有查到可是抓出來資料一直是0不正確</p><p>寫法在下面 有錯誤請大大們指正 謝謝</p><p>Public&nbsp;Sub&nbsp;ShowPolyLinePoint1()<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;objAcadEntity&nbsp;As&nbsp;AcadEntity<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;varPickedPoint&nbsp;As&nbsp;Variant<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;intIndex&nbsp;As&nbsp;Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;varCoordinates&nbsp;As&nbsp;Variant<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;dblX&nbsp;As&nbsp;Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;dblY&nbsp;As&nbsp;Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;dblZ&nbsp;As&nbsp;Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;varbulge&nbsp;As&nbsp;Variant<br/>&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;objpline&nbsp;As&nbsp;AcadLWPolyline<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;UserForm1.Hide<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;ThisDrawing.Utility.GetEntity&nbsp;objAcadEntity,&nbsp;varPickedPoint,&nbsp;"請選擇&nbsp;Polyline"<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;TypeOf&nbsp;objAcadEntity&nbsp;Is&nbsp;AcadLWPolyline&nbsp;Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set&nbsp;objLwpolyline&nbsp;=&nbsp;objAcadEntity<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;varCoordinates&nbsp;=&nbsp;objLwpolyline.Coordinates<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;varbulge&nbsp;=&nbsp;objLwpolyline.GetBulge(3)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For&nbsp;intIndex&nbsp;=&nbsp;LBound(varCoordinates)&nbsp;To&nbsp;(UBound(varCoordinates)&nbsp;-&nbsp;1)&nbsp;/&nbsp;2<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'取得&nbsp;(X,Y)&nbsp;座標<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dblX&nbsp;=&nbsp;varCoordinates((intIndex)&nbsp;*&nbsp;2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dblY&nbsp;=&nbsp;varCoordinates((intIndex)&nbsp;*&nbsp;2&nbsp;+&nbsp;1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;db1Z&nbsp;=&nbsp;varbulge((intIndex))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox&nbsp;("X("&nbsp;+&nbsp;CStr(intIndex)&nbsp;+&nbsp;")="&nbsp;+&nbsp;CStr(dblX))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox&nbsp;("Y("&nbsp;+&nbsp;CStr(intIndex)&nbsp;+&nbsp;")="&nbsp;+&nbsp;CStr(dblY))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox&nbsp;("bulde("&nbsp;+&nbsp;CStr(intIndex)&nbsp;+&nbsp;")="&nbsp;+&nbsp;CStr(dblZ))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Next<br/>&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;If<br/><br/>End&nbsp;Sub<br/></p><p></p>

woaishuijia 发表于 2009-12-15 08:07:00

Public Sub ShowPolyLinePoint1()
    Dim objAcadEntity As AcadEntity
   
    Dim varPickedPoint As Variant
    Dim intIndex As Integer
    Dim varCoordinates As Variant
    Dim dblX As Double
    Dim dblY As Double
    Dim dblZ As Double
'    Dim varbulge As Variant
'    Dim objpline As AcadLWPolyline
    Dim objLwpolyline As AcadLWPolyline
   
    UserForm1.Hide
   
    ThisDrawing.Utility.GetEntity objAcadEntity, varPickedPoint, "請選擇 Polyline"
   
    If TypeOf objAcadEntity Is AcadLWPolyline Then
      
      Set objLwpolyline = objAcadEntity
      
      
      
      varCoordinates = objLwpolyline.Coordinates
      
'      varbulge = objLwpolyline.GetBulge(3)
      
      
      For intIndex = LBound(varCoordinates) To (UBound(varCoordinates) - 1) / 2
            '取得 (X,Y) 座標
            dblX = varCoordinates((intIndex) * 2)
            dblY = varCoordinates((intIndex) * 2 + 1)
'            db1Z = varbulge((intIndex))
            dblZ = objLwpolyline.GetBulge(intIndex)
         
            MsgBox ("X(" + CStr(intIndex) + ")=" + CStr(dblX))
            MsgBox ("Y(" + CStr(intIndex) + ")=" + CStr(dblY))
            MsgBox ("bulde(" + CStr(intIndex) + ")=" + CStr(dblZ))
      Next
    End If
End Sub

fadai 发表于 2009-12-15 11:28:00

<p>謝謝大大 問題已經解決了</p><p>想請問一下 關鍵是因為 Dim objLwpolyline As AcadLWPolyline 這句嗎?</p><p>可是不是也已經有了 objLwpolyline 不是已經是objAcadEntity了嗎?</p><p>為什麼還可以是AcadLWPolyline</p><p>小弟是新手 所以還不太懂 謝謝</p>

woaishuijia 发表于 2009-12-15 11:48:00

<p>你的代码存在3个错误</p><p>1.</p><p><font color="#000000">Dim objpline As AcadLWPolyline 中变量 objpline 与后面用到的 objLwpolyline 不一致.因此把这一行改为</font></p><p><font color="#000000">Dim objLwpolyline As AcadLWPolyline</font></p><p>2.</p><p><font color="#000000">varbulge = objLwpolyline.GetBulge(3) 与你的目的不符.GetBulge() 函数用于获取指定顶点的凸起值,这一行运行的结果是 varbulge 被赋予一个双精度数,就是多段线第4个顶点(索引值是你代码中的"3")的凸起值,而不是一个数组.因此把这行移到了循环体内部,针对每个顶点分别获取.</font></p><p>3.</p><p><font color="#000000">db1Z = varbulge((intIndex)).首先 db1Z 中间的字符是阿拉伯数字"1"而不是你声明的字母"l",写错了;其次,前面已经说了 varbulge 不是一个数组;最后, intIndex 外面为什么要用两层括号呢?</font></p>
页: [1]
查看完整版本: 請問如何選取畫好的pline找到各節點座標跟bulge