Grasshopper

algorithmic modeling for Rhino

And also, is it possible to do a List of Lists in VB?

Views: 950

Replies to This Discussion

Yes you can do lists of lists

Dim lLists as new list(of List(of string))
Dim lList1 as new list (of string)
Dim lList2 as new list (of string)
llist1.add("hello")
llist2.add("me")
llists.add(llist1)
llists.add(llist2)
Weird, I thought I tried it that way. But I just tried again and it works so that's good. Thanks.

Hey, do you know what the <> symbols mean that are usually auto-filled when I type List? I just erase that part, but I'd love to know what I'm erasing.

Also, I'm still looking to know how paths are output if anyone knows that one.
check to make sure you created an instance of the List object by sepcifying New in the Dim statement
Hi Chris,

the < > symbols are for C#:


Dim data As List(Of T) ' this is VB syntax
List<T> data; // this is C# syntax


The code editor is simply buggy.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Yes you can, you use dataTrees instead of list objects. I'm not 100% on how this all works but its got me by so far.

dim pathStructure as new DataTree (of object)

when you add things to your tree, you need to specify the branch path as well as the object youre adding.

dim branch as new GH_Path(0,0)
pathStructure.add(item, branch)

will add item to path {0;0}

Also, if you input a path structure, VB usually outputs a path structure - it treats each branch seperately though.
Thank you!!!

Can anyone elaborate on the DataTree class?
Chris, have a read on page 42 of the grasshopper primer - there's an outline on data tree structures.

Basically it's a way to access networks of data paths. vers. 0.7 also now allows for script components (C# / VB) to access data tree's rather than a flattened list.

<> is the symbol for 'does not equal' - not sure why it is dropped in the intellisense after List though?

There's a number of ways you can develop nested data - Nested List; ArrayList; dataTree; etc. Each class may also be more efficient in returning data depending on the search pattern of data contained. If you want to explore further, it would be useful to search the Rhino SDK / RhinoCommon SDK forums.
Hi Chris, hi Dirk,

the <> symbols after DataTree are actually an error of autocompletion. They are meant to be used from C# and are the same as (Of ...) in VB.Net. E.g.: List<Point3d> in C# is the same as List(Of Point3d) in VB.Net.

They mean containing (or working on) Point3ds. You can see Generic Programming on wikipedia for a general introduction. The non-generic version of List<>, known as ArrayList, can contain everything but it slower on certain types and more error prone, as it's more difficult to always predict what a "black box" like ArrayList actually contains.

- Giulio
Yes generic lists are the way to go. I understand that it is more effcient as we know the data it contains beforehand and hence provides an early bound solution, there is no "boxing" and "unboxing" of data.

Is there a difference between a "Nested List" "Linked List" and simply defining a generic list of list - as in my example above? Is this a linked list?
Hi Steve,

List<Something> is based on an underlying array. Arrays are not resizable, so the array is swapped when the list notices that it has run out of space inside it. At this point, it will pay the cost of copying all the content from the old array to the new one. The current default size for List<Something> is 4 if I remember correctly, but this is just an implementation detail. You can use the constructor with another capacity to change it.

You can also see the .NET Framework Class Library reference for other generic collections, like the LinkedList<Something>.

- Giulio

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service