Grasshopper

algorithmic modeling for Rhino

create triangular polyline in Vb with new Rhinocommon language

Long time ago, when we were working with old RhinoSDK, we often create polylines, for instance, like this:

Public Function createPolyline(ByVal pts As list (Of on3dPoint)) As OnPolyline

  Dim p As OnPolyline
    p = New OnPolyline()

    Dim arrpts(0) As Double
    Dim k, l As Int32
    k = 0
    l = -1

    For k = 0 To pts.count - 1
      l = l + 3
      ReDim Preserve arrpts(l)
      arrpts(l - 2) = pts.item(k).x
      arrpts(l - 1) = pts.item(k).y
      arrpts(l - 0) = pts.item(k).z
    Next
    l = l + 3
    ReDim Preserve arrpts(l)
    arrpts(l - 2) = pts.item(0).x
    arrpts(l - 1) = pts.item(0).y
    arrpts(l - 0) = pts.item(0).z

 
    p.Create(3, False, 3, arrpts) ???

    Return p
  End Function

How should I proceed with Rhinocommon right in this example?

(Of course we need to change Polyline instead of OnPolyline, Point3d instead of On3dPoint etc)

Thanks in advance, and keep up the good work!

Views: 751

Replies to This Discussion

Public Function createPolyline(ByVal pts As List(Of Point3d)) As Polyline

  Dim p as new Polyline(pts)

  return p

End Function

Of course; the case here is that with old method we used to create polyline by means of (point dimension As Int32, bRational As Boolean, point stride as Int32, and finally an array of Double that is in my case arrpts)

so I need to create a polyline based on that list of doubles, stored in arrpts

The function Steve wrote does the same thing as your original function. What does it matter how it works internally, whoever calls this function won't be able to tell the difference.

I see you also close the polyline in your original function, so I suppose in RhinoCommon it should be:

Public Function CreatePolyline(byval pts As IEnumerable(Of Point3d)) As Polyline

  Dim p As New Polyline(pts)

  If (Not p.IsClosed) Then

    p.Add(p(0))

  End If

  Return p

End Function

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service