Data Transfer between grasshopper scripts through Data Input/Output

Hi everybody,

I divided my code into some small codes and want to change these small codes in order to vary my design with each execution. Therefore, I wanted use Data Input/Output component. This component provides all my needs. However, I should have a control on the path of these components to vary my design automatically. Is there a way to do it? I saw some same questions from 3-4 years ago. But, they are old topics. Therefore, I wanted to discuss it in new topic.

Hi MK,
I suggest to use python script
(42) How to Automate Grasshopper with Python - Part 2 - YouTube

Part one here: https://youtu.be/bEynt5y_Vy8

This python script is useful to change slider or some parameters, I think. But, what I need is a little bit complexer than that.
grafik
As you see in the picture, I have some surfaces and add some patterns to surfaces, than I take it back. Actually, Data Input/Output do exactly, what I need. However, I want to change the Skin_1 with Skin_2 and get some new geometry. So, I can vary my design. For that reason, I could change the Path somehow automatically.

1 Like

Don’t you have any other suggestion?

you might access existing nodes on the canvas (e.g. by name) like so:

GrasshopperDocument = base.OnPingDocument();
            if (GrasshopperDocument == null) return;
            var ghObjs = GrasshopperDocument.Objects;
            object a = null;
            for (int i = 0; i < ghObjs.Count; i++)
            {
                if (ghObjs[i].NickName == name)
                    a = ghObjs[i];
            }

or another example I used to check if another node is activated or not :

SerialPort _port = new SerialPort();
Guid _guid = new Guid(“eaeb4940-873f-4762-9300-bdb759fbde30”); // OpenPortGuid
var doc = OnPingDocument();
for (int i = 0; i < doc.Objects.Count; i++)
{
if (doc.Objects[i].ComponentGuid == _guid)
{
OpenPort _comp = doc.Objects[i] as OpenPort;
_port = _comp._serialPort;
}
}
if (_port.IsOpen)
{
DA.SetData(0, true);
}
else
{
DA.SetData(0, false);
}
}

you can access all variables from another node by adressing it by GUID. you can make a value list for the “receiver node” that describes your node you want to connect and gives out the GUID to connect easily. then you can output your geometry base or whatever you want to output from your receiver node. this would allow you to change the path of calculation by two clicks.

hope this helps

b

Thank you benedict for your answer. I didn’t write a script in python or c for grasshopper. But, I will learn and try your solution :slight_smile:

Oh, I’m sorry, I missunderstood your

but indeed, it’s not marked “c#” or anything, so I apologize.

In this case you might want to have a look at clusters in grasshopper. It allows you to group parts of code together and combine them to a single node. By doing this you can connect the groups easily (without learning c#. no need to overcomplicate things)

just select the group of nodes you want combined, right click on the canvas (not on any node) and select “cluster”. then you can doubleclick on the new node to modify it and define the inputs and outputs.

I know cluster and I used it also. But in this case, I need more complicated stuff, I think. Because, As you see the image from my before message, I have some different geometries for Skin_1 cluster (I defined it in this case as a new model, but you can see it also as a cluster). I want to change this cluster with other cluster, lets say Skin_2, then I want to calculate whole model one more time and have a new design.

I will execute all this gh code from HEEDS. Therefore, the whole design concept will be completely automatic. So, I need to change path of the DATA INPUT/OUTPUT automatically, not select with hand. I think, only solution for that is writing a code.

Hi -
I’m afraid I still don’t completely understand what you are trying to do but if you have a definition that, conceptually, consists of 2 parts, A and B, where A can either be A1 or A2, it sounds like you should be able to put part B in a different .gh file and call that with the Hops component. A1 and A2 could then be different .gh files as well.
-wim

Hi Wim,
thank you for your response. I tried to use hops. But I’m getting this error:
“1. Path appears valid, but to something that is not Hops related” (But this gh document is working with using of Data Input and Output.)
Could you explain please, what the difference is between Data Input/Output and Hops? I have also another question. Does baking a geometry make the process slowly? If yes, is there a option to transfer data without baking?
FlowPath_1_sam.gh (55.4 KB)

I tried to use hops also with a simple code (see image). But I got the same error. Is it so only in my computer or do you have the same problem?