algorithmic modeling for Rhino
Hi everybody,
I am going to ask something probably very stupid.
I would like to create a component that has variable number of inputs (the user can add o remove some) and creates an output which is the string concatenation of all the input parameters "line by line". (For some reason the concatenate component is not what I need)
In order to do this I would like to use the internal looping of the component, therefore leaving Item access and let the component do the nasty job.
With a fixed number of parameters that is easy because I can just send to "output" parameter the concatenation like this:
output = param1 & vbtab & param2 & vbtab & param3 etc...
and I would get a total number of output items equal to the "longest" input list
To grant maximum flexibility I would leave both number and name of parameters free.
I thought about looping through the parameters but how do I get the "item" of each single parameter?
I have gone so far:
Dim i As Integer
Dim CurString As String: CurString = ""
Dim param As IGH_Param
For i = 0 To CInt(Me.Component.Params.input.count) - 1
param = Me.Component.Params.Input(i)
CurString = CurString & param.volatiledata.AllData(True).First.tostring & vbtab
Next
strings_out = CurString
But since I have item access this doesn't work because there is no volatiledata IGH_Structure available with item access.
Thanks a lot!
Tags:
I'm not sure it's possible. There's no point accessing the input parameter volatile data, because that's all trees. If you want to use the in-build iteration logic for individual items, then you must look at the arguments of the RunScript method.
Using reflection you can find the names of all the arguments in a method signature, but you cannot get their values.
You will either set all inputs to tree access and write the complicated combinatorial code yourself, or use some existing grasshopper components to string together the strings.
Or, ultimately, switch to Visual Studio where you can access the values using an indexer.
Specifically, the attached code shows how to examine the signature of the RunScript method, it harvests the names and types of parameters, but it cannot harvest their values.
Thanks David!
Whoa, I really need to study a lot...
I understood that with reflection is also possible to write self modifying code, that would be the answer. Creating a line of code that concatenates all the parameters names and executing it.
It would be interesting but I guess it's really overkill and I imagine it would find lots of security issues, but good food for tought!
are you *sure* it wouldn't just be easier to get list access and handle the list management??
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by