Rhino.Runtime.HostUtils: receiver component question

Hello
How to assign “a self guid” to the receiver component to prevent other copies from receiving data?

rir.gh (3.7 KB)

I think you can by creating a receiver object (as in OOP object) that generates an id for each instance, which can imo be a simple counter.

Thanks @Gijs
I don’t understand your solution, actually i used enable condition to prevent new component from working but the user need only one in the canvas, it’s just in case when it added by fault

Hey! @anon39580149, @Gijs, I’m new with C# and I was trying to create a sender component to a clustered receiver, can anyone help me please?
Sender:

using System;
using Grasshopper.Kernel;

public class SenderComponent : GH_Component
{
    public SenderComponent() : base("Sender", "S", "Send numeric data to receiver", "Test", "Data") { }

    protected override void RegisterInputParams(GH_InputParamManager pManager)
    {
        pManager.AddNumberParameter("Data", "D", "Numeric data to send", GH_ParamAccess.item);
    }

    protected override void RegisterOutputParams(GH_OutputParamManager pManager) { }

    protected override void SolveInstance(IGH_DataAccess DA)
    {
        double data = 0;

        if (!DA.GetData(0, ref data)) return;

        // Get the nickname of the target receiver
        string targetNickname = "ReceiverNickname";

        // Find the remote component with the given nickname within the cluster
        GH_Component targetComponent = null;
        foreach (IGH_DocumentObject obj in OnPingDocument().Objects)
        {
            if (obj is GH_Cluster)
            {
                GH_Cluster cluster = obj as GH_Cluster;
                foreach (IGH_Component clusterComponent in cluster.ClusterObjects(true))
                {
                    if (clusterComponent.NickName == targetNickname && clusterComponent is GH_Component)
                    {
                        targetComponent = clusterComponent as GH_Component;
                        break;
                    }
                }
            }
        }

        // Check if the target component was found
        if (targetComponent != null)
        {
            // Send data to the target component
            targetComponent.Params.Input[0].AddVolatileData(new GH_Path(0), 0, data);
        }

        // Expire solution to update the changes
        ExpireSolution(true);
    }

    public override Guid ComponentGuid
    {
        get { return new Guid("GUID_HERE"); }
    }
}

Receiver:

using System;
using Grasshopper.Kernel;

public class ReceiverComponent : GH_Component
{
    public ReceiverComponent() : base("Receiver", "R", "Receive numeric data from sender", "Test", "Data") { }

    protected override void RegisterInputParams(GH_InputParamManager pManager) { }

    protected override void RegisterOutputParams(GH_OutputParamManager pManager)
    {
        pManager.AddNumberParameter("Data", "D", "Received numeric data", GH_ParamAccess.item);
    }

    protected override void SolveInstance(IGH_DataAccess DA)
    {
        double data = 0;

        // Receive data from the sender component
        DA.GetData(0, ref data);

        // Do something with the received data...

        // Output the received data
        DA.SetData(0, data);
    }

    public override bool Read(GH_IReader reader)
    {
        // Perform any additional reading here if needed
        return base.Read(reader);
    }

    public override bool Write(GH_IWriter writer)
    {
        // Perform any additional writing here if needed
        return base.Write(writer);
    }

    protected override void ExpireDownStreamObjects()
    {
        // Expire downstream objects to trigger a re-computation when data is received
        OnPingDocument().NewSolution(true);
        base.ExpireDownStreamObjects();
    }

    public override Guid ComponentGuid
    {
        get { return new Guid("GUID_HERE"); }
    }
}

Thanks!