GHPythonScript: How do I read the name of the output parameters

Hi There,

Hoping this is a simple one!
I’d like to know how to read the output parameters from a GHPythonScript module.

Basically, I am trying to give the module a “dictionary” of sorts and then take out the information specified as output parameters.

Inside the python block will need to be something like:
" for output in [List of Output Parameters]:
Do Something

Appreciate any help you can provide!

Thanks

‘ghenv.Component.Params.Output[i]’

‘i’ = index number of the output

Thanks!

I’m just missing the last piece of the puzzle in which I need to assign the output value as the value retrieved from a dictionary. Do you know what the .??? should be to get this working?

image

Oh you mean assigning the value :smiley:

this is as simple as OUTPUTNAME = VALUE :slight_smile:

in your case:

egg = value
milk = value1

There is something tricky though, if your output is a list you’ll have to define it as a list to get the .append method.

milk = []
for i in x:
    milk.append(i)
# you don't need further milk assignments, as after this milk is a list of all the items from x (list)

Yes that would be simple!
However, In this scenario the output names will be varied.

I am hoping the end result will be that I can type in a output variable externally to the component and the component will be clever enough to read from a python dictionary and assign the value to the that output variable.

EG. I add a new output variable to component, “egg”.
Component reads python dictionary for “egg” and gets attached variable “value”.
Component assigns “value” to output variable “egg” for use.

Hope this makes sense!

you can check the name of the output and

if ghenv.Component.Params.Output[i].Name == "egg":
    egg = value

NOTE: I haven’t tested this with outputs, only with inputs.