Simple grid script not working?

It has been several days I have been trying to understand the ways of VB.Net coming from Bentley GC and Csharp. But still I seem to be crawling...

Can someone point out whats wrong with this code?


Private Sub RunScript(ByVal point As On3dPoint, ByRef A As Object, ByRef B As Object)

Dim yArray As New ArrayList

Dim count As Double : count = 10
Dim i As Int16

For i = 1 To count Step 1
Dim xArray As New List (Of On3dPoint)
Dim j As Int16

For j = 1 To count Step 1
Dim nPoint As New On3dPoint
nPoint.x = i
nPoint.y = j
nPoint.z = 0
xArray.Add(nPoint)

Next

yArray.Add(xArray)

Next

A = yArray


As a side point i reckon grasshopper is fantastic, not having to promote and export in and out from rhino saves hours each day! But would benefit from a more useful debugger also even simple definitions run quite slowly, is there plans of allowing people to compile definitions into rhino native plugins? That would be great!
  • up

    David Rutten

    Hi Erik,

    Your code, with changes (no fixes yet):

    -------------------------------------------
    Dim yArray As New List(Of List(Of On3dPoint))
    Dim count As Int32 = 10

    For i As Int32 = 1 To count
    Dim xArray As New List(Of On3dPoint)

    For j As Int32 = 1 To count
    Dim nPoint As New On3dPoint(i, j, 0)
    xArray.Add(nPoint)
    Next

    yArray.Add(xArray)
    Next
    A = yArray
    -------------------------------------------

    - ArrayList is a DotNET 1.0 legacy class. You should always try to use type specific classes such as List(Of T).
    - Int16 is only rarely useful. Its numeric scope is too limited for a lot of purposes. Int32 is to be preferred.
    - You can declare iteration variables (i & j) inside the loop code.

    The reason your code doesn't work is not because there's anything wrong with it. It's simply that Grasshopper doesn't understand lists of lists if you supply them in this fashion. Only one dimensional collections can be outputted like this. Thus, if you want to put all the points into a single list:

    -------------------------------------------
    Dim points As New List(Of On3dPoint)
    Dim count As Int32 = 10

    For i As Int32 = 1 To count
    For j As Int32 = 1 To count Step 1
    Dim nPoint As New On3dPoint(i, j, 0)
    points.Add(nPoint)
    Next
    Next
    A = points
    -------------------------------------------

    If you want to output lists of lists, you must supply it as a DataTree(Of T):

    -------------------------------------------
    Dim points As New Grasshopper.DataTree(Of On3dPoint)
    For i As Int32 = 1 To x
    For j As Int32 = 1 To y
    Dim nPoint As New On3dPoint(i, j, 0)
    points.Add(nPoint, New Grasshopper.Kernel.Data.GH_Path(i))
    Next
    Next
    A = points
    -------------------------------------------


    --
    David Rutten
    david@mcneel.com
    Poprad, Slovakia
    9
  • up

    David Rutten

    "even simple definitions run quite slowly"

    Some operations take a lot longer to complete than others. Some components can probably be sped up, but most of the slow ones involve complicated geometric operations which are already running quite fast, all things considered.

    Compiling things into native rhino plugins (what's an unnative Rhino plugin?) won't speed things up in the slightest. Grasshopper is a native Rhino plugin and is using the exact same functions any other plugin would use to accomplish the same ends.

    --
    David Rutten
    david@mcneel.com
    Poprad, Slovakia
    3
    • up

      Ben Fortunato

      Is there some documentation on the methods and classes specific to Grasshopper? This seems to be important in order to interface with Grasshopper, for example with the datatree class, but I can not find any documentation or help on it.

      BEst,

      Ben
      1