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)