Grasshopper

algorithmic modeling for Rhino

Hi,

Does anyone have a sample code of how to pass a flat list into a Custom VB.net component created in Visual Studio?


for example, this doesn't seem to work


Dim SeedCurve As List(Of Curve)


        'Import Values

        If (Not DA.GetDataList(0, SeedCurve)) Then Return



Any suggestions/ideas?


Thanks.


kermin


Views: 652

Replies to This Discussion

You need to supply an existing (but empty) list of data if you want to use GetDataList

Dim SeedCurve As New List(Of Curve)
If (Not DA.GetDataList(0, SeedCurve)) Then Return



The error message actually is pretty accurate...

"Target List is a null reference. GH_IndexList.GetDataList() can only be called with a constructed List."


--
David Rutten
david@mcneel.com
Poprad, Slovakia
David,
Thanks for the info. So now the plot thickens. What if the user may provide a list of curves or a single curve? How might we set up code so we don't throw an error when we are reading a data item but a list is coming in and vice versa?

Do I have to do anything special at the

pManager.Register_CurveParam("xxxx")

declaration for passing in a list or a single item?

Furthermore, I'm still getting this error when trying to pass in the list of curves.




Thanks again.

kermin
Kermin,

you can't. If the input is a list parameter you must always accept the whole list. When someone supplies only a single item, you may decide to switch to a different branch of logic of course, but you must use GetDataList().

I cannot read the text in the image. When you upload images there's an option to link to the unscaled original. Please check it.

--
David Rutten
david@mcneel.com
Poprad, Slovakia

Hi Kermin,

it seems you are still calling GetDataList() on a parameter that has been set to item access. When you construct the parameter in RegisterInputParams, you have to pick Item (default), List or Tree. From this point onwards you should only use GetData(), GetDataList() or GetDataTree() respectively.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks. That worked. I guess it would help if I scrolled through the rest of the options for declaring input parameters.

Anything I should know about outputing items, list or trees? Or is the output parameter more flexible in that it adapts to whatever it is set to.

Thanks again.

Kermin
The output is more flexible, though you should probably stick to the same SetDataXXXX() method inside your SolveInstance function.

I haven't tested how it behaves when you call SetData on some iterations and SetDataList on others.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
David,

Do you have an example for reading in a datatree? I'm trying this so far and it's not the correct syntax.

Do I have to declare an empty tree or something like that?


pManager.Register_PointParam("Pts", "Pts", "Reaction Points", GH_ParamAccess.tree)
End Sub

Dim ReactionPts As New DataTree(Of Point)
If Not (DA.GetDataTree(0, ReactionPts)) Then Return


Thanks.

kermin

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