Attempt to give K1 an K2-style "On" input; only work outside cluster

grasshopper
unhandled
scripting
cluster

(Keyu Gan) #1

I’m trying to give K1 solver an ‘On’ input. My attempt was successful outside a cluster. But when I move solver and my component into a cluster, it doesn’t work. So I’m looking for some suggestions. I think the problem might lie in how GH deals with nested documents (cluster and its owner).

Technical details:
I use Reflection to enable ActiveSimulation in downstream K1 solver component.

var pOutputs = Component.Params;
var index = pOutputs.IndexOfOutputParam("DirectlyToK1");
if(index == -1)
  return;

var recComp = pOutputs.Output[index].Recipients;
if(recComp.Count != 1)
  return;

if(recComp[0].Kind != GH_ParamKind.input)
  return;

var K1Comp = recComp[0].Attributes.GetTopLevel.DocObject;
if(K1Comp.GetType().ToString() != "GhKangaroo.KangarooA")
  return;

var switchSimulation = K1Comp.GetType().GetProperty("ActiveSimulation",
  System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public
  );

if(switchSimulation == null || !switchSimulation.CanWrite)
  return;

switchSimulation.SetValue(K1Comp, Run);

DirectlyToK1 = Reset;

k1on.gh (16.3 KB)