Retain wire connections when script is pasted into another script


I was wondering what is the exact logic in Grasshopper regarding wire connections when part of a definition is pasted from one file to another, the files including some identical parts. I am copying a part of a definition to another file, which is nearly identical to the file i am copying from, and some upstream wire connections are retained while others are not.

Is there a specific logic that defines which upstream connections are retained?


Just deal with it.

You do realize that this is not an answer to the question, right? I would have started dealing with it, but this is a process that needs to be repeated in more than 200 files, multiple wire connections each, hence the question.

It is a realistic answer to your question, just not the one you are hoping to hear.

If i had asked : “what do you think i should do?”, then it would have been an answer.
What i was hoping for was an answer to the question i asked, which could point towards a solution to my issue, and maybe help others in the future.

That is not true under the hood, since each component of same definition in different documents will have different instance guid, so it can be identical for us but not for software that does not understand the context that we take for granted.

You can automate it with custom code, but once you copy a component it doesn’t keep any association with its original, so you should use heuristics or ad hoc solutions for your particular case. You could generalize with some signature/contract to paste and auto connect some wires, but same, with custom code.

So does that mean that the wire connections that are now retained when i copy a part from one document into another are retained based on chance?

That means that some are retained and others not by chance?

I don’t know what you’re referring to exactly.

Ok I get it. In GH1 a wire is just like a pair of instance guids of parameters. When you copy paste, this instances guids are new, but the connectivity is preserved. GH can do that bc in taht context it is aware of the elements to copy and reconnect, but no about other elements in a new document. In this case, the source components (the ones you can to auto connect) of that part of the definition have different instance guids that the originals.

Ok now i understand, thank you for this explanation!

To see if two objects in two files are almost certainly supposed to be the “same” object, you can compare their pivots and ComponentGuids.

public bool AreProbablyIdentical(IGH_DocumentObject a, IGH_DocumentObject b)
  if (a.ComponentGuid == b.ComponentGuid)
    if (a.Attributes.Pivot.Equals(b.Attributes.Pivot))
      return true;
  return false;

It gets harder if there’s some offset between the objects, such as you get during regular copy-paste. It may only be possible to determine “same-ness” for a large set of objects where you can can find the same relative offset between same-type-objects over and over again.

1 Like