Accessing guid (sliderguid)

Can I access the guid (sliderguid) of a component connected to the input of ghpython component?

Short answer: Yes.

Try to translate this to Python:


    // Checking the first Input param (at index = 0)

    var param = Component.Params.Input[0];
    if (param.Sources.Count < 1)
    {        
        return; // No source was connected to inport
    }

    // get the actual source component

    var gh = Component.OnPingDocument();

    var id = param.Sources[0].Attributes.Parent.InstanceGuid; // <-- you want this
    var source_component = gh.FindComponent(id);
    if (source_component == null)
    {        
        return; // Failed to access the source component
    }

    // From here you're good to go

// Rolf

1 Like

Thanks Rolf,

I’ll try.

Ops, that code seems to work only when having a ScriptComponent as the source (not a slider).

This should work better for a Slider:

    // Checking the first Input param (at index = 0)
    var param = Component.Params.Input[0];
    if (param.Sources.Count < 1)
    {        
      return; // No source was connected to inport
    }

    A = param.Sources[0].InstanceGuid; // Output the Guid

// Rolf

2 Likes

Thanks it worked with csharp component, I’ll try to translate it.

Is there a similar method to access guid of down stream components?
likewise I tried Component.Params.Output[0].Sources[0]
but Sources is empty list even if I have stuff connected to it…

You cannot connect a source to an output parameter. Parameters have Sources (connected to the left hand side) and Recipients (connected to the right hand side).

1 Like

@Will_Wang

I saw a script provided by @piac where he uses Reflection inside python to get inputs downstream.

He was basically checking what type of object was connected to the component this.component was connected to :smiley: