Set value of python component output / ghenv.Component.Params.Output[1].SetValue

Hello!

First of all, thanks for your help!

How can I set the value of an output without explicitly using a = 5.
I think it can be done using ghenv.Component.Params.Output[1].SetValue(), but I don’t know exactly what I need to provide to the function.

Error message:
“”"
Runtime error (TypeErrorException): cannot access protected member SetValue without a python subclass of GH_DocumentObject

Traceback:

  • line 17, in script*
    “”"

ghenv_Component_Params_Output_Set_Value.gh (3.4 KB)

import Grasshopper as gh
ghenv.Component.Params.Output[1].VolatileData.Clear()
ghenv.Component.Params.Output[1].AddVolatileData(gh.Kernel.Data.GH_Path(0), 0, "Data")
private void RunScript(object x, object y, ref object A) {}
// <Custom additional code> 
public override void AfterRunScript()
{
  Component.Params.Output[1].VolatileData.Clear();
  Component.Params.Output[1].AddVolatileData(new GH_Path(0), 0, "Data");
}
[AddVolatileData.gh|attachment](upload://gna4BvFDwIzEr4A4Hur3elEH95T.gh) (7.1 KB)
1 Like

What I would like to do is pass through the value from all inputs to outputs. The exec way works for now, but is not good python code and I don’t think it would work for more complex data types. Your python example leads to a < null > element at index 0, is this a bug? The attached code snippet doesn’t seem to make much sense now, but I am planning to either pass through or return a different value later on.
How can I actually return the value - for example 6?

pass_through.gh (3.7 KB)

Hi! I would just like to check if there has been any developments on this?

I too am trying to work on something similar. What I’m trying to do is pass data from dynamic and variable inputs to dynamic and variable outputs as well. I am mostly looking into AddVolatileData but I am not exactly sure yet how this works.

Does anyone have any new leads on this?

The exec method is the way to go. It could be adapted to be positional rather than nominal (first with first, etc). If you don’t like exec, which is understandable, you could use

globals()[output.NickName] = input_value

Thanks,

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

2 Likes