Grasshopper

algorithmic modeling for Rhino

Hi everyone,

I was wondering if anybody knows how to get the datalist of newly created (via ZUI - InsertParameter) input parameters (type String with list access)?
 
Situation: A component with by default two List (Of String) inputs, and the ZUI-possibility to add more List (Of String) inputs. How do I implement the DA.GetDataList for the additional inputs in a smart way?

I read somewhere on the net that declaring and instantiating variables in a loop isn't advisable. Should I get the data from the VolatileData and try cast that to a list? I searched (of coarse) for examples but found no comparable case.

Kind regards, Pieter

Views: 860

Replies to This Discussion

for (int i = 0; i < Params.Input.Count; i++)

  List<string> data = new List<string>();

  DA.GetDataList(i, data);

Something like this?

Thanks David:) Yes, something like that.
I'll try to invent a way to have a unique name for each variable that holds an additional datalist next. If you can head that one in too, you're more than welcome to do so (because I'm thinking of a loop) ;)

The GH_ComponentParamServer class (or 'Params' if you're inside a component) has static methods for coming up with unique names: InventUniqueNickname(). It's not particularly good, but it may help you on your way.

Thanks for thinking with me. I got my NickNames for the inputs as L0, L1, L2... Lx and that's working fine, but the trouble I'm having is to declare and instatiate the variables. Now their all called 'data' (right?), and my goal is to have them named data0, data1, data2 etc. so I can get their (separate) contents (list of string) via their unique name. I'm not achieving much progress on that matter here (yet).

The best place to make sure your naming is all ship-shape is to put the logic in the VariableParameterMaintenance method. There you can assign nicknames, regular names, descriptions, access states, etc. to all parameters and you can be certain that you'll always be called before a new solution starts, provided stuff has changed. You may also elect to set the MutableNickName property to false for your parameters, if you don't want users to mess about with your indexing scheme.

I think I got that all running (see attachment), but I'm all loopy by now about how I can dynamically generate the naming
Dim data0 As New List (Of String)
Dim data1 As New List (Of String)
Dim data2 As New List (Of String)
...
...
and then do something like:
DA.GetDataList(i, "data" & i)  to assign the input lists.
 
Thusly loopy, that I'm taking a break now to cook some diner:)

Attachments:

Something like this should work:

Dim Dic As New Dictionary(Of Integer, list(Of String))

For i As int32 = 0 To Params.Input.Count - 1
Dic(i) = New list(Of String)
GetData(Dic(i))
Next

A = Dic(2) 'Instead of a variable name, use Dic(index).

'This function simulates the DA.GetDataList().

Function GetData (ByRef L As list(of string)) As Boolean 

L = New list(Of String) From {"Bla","Bla"}
Return True
End Function

Thank you very much for your effort Dani, I'm going to try and adapt it (once I grasp what's going on) to work with my component.
(The "Bla","Bla" actually should be read in from the input list)

In case anyone is wondering how I solved my issue:


Dim dict As New Dictionary(Of Int32, List(Of String))        

For i As Int32 = 0 To Params.Input.Count - 1
    Dim dataStr As New List(Of String)()
    DA.GetDataList(i, dataStr)
    dict(i) = dataStr
Next


Please speak up if you know there's room for improvement!

Thanks again guys:)

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