Accessing guid (sliderguid)


(IVELIN PEYCHEV) #1

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


#2

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


(IVELIN PEYCHEV) #3

Thanks Rolf,

I’ll try.


#4

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


(IVELIN PEYCHEV) #5

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


#6

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…


(David Rutten) #7

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).


(IVELIN PEYCHEV) #8

@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: