Sending info contained in python instances of a custom Class in grasshopper

Hello there
I have created a class using ghPython component in grasshopper which contains a lot of specific information on a certain element in each of its attributes (like points, breps, doubles and strings) and need to send it via speckle. I am trying to send a tree, in which every branch is a dictionary containing this instances so another user can access it. How should I proceed?

Hi @Luiza_Longo!

Could you give us more details about:

  • How does the data look in Python
  • How are you expecting that to look in GH

In speckle we have no concept for “data tree”. Every data tree sent from Grasshopper is just a Base object with each branch becoming a property with the branch path {0;0;0}

I wouldn’t recommend doing this unless the tree you’re sending is attached as a property to the top-level commit object. Adding DataTrees at any given level of the commit object structure is not really supported. Though may work in some cases.


The recommended approach would be to just structure your data in Base objects so that the information is logically grouped. Once received that commit in Grasshopper, Deconstruct Speckle Object will create deeper trees when needed.

Anyhow, if you give us more details of exactly what you’re trying to achieve, with a minimal example of how that would look on both sides, we can come up with a more specific solution.

Thank you for your quick response!
I am sending this:

each Data instance is a dictionary.
I would like that I get those same instances on the other end.

The Data Class is just to access the dictionary.

Each value on the dictionary contains an object that looks like this:
So each attribute contains different information on this instance. Some of them are points, vectors, breps, etc.

I am trying to avoid getting the instance values (all the points, all the breps) and sending them separately because there are many dictionaries and instances and it can get pretty messy. Ideally, I would like that on the other end the user receives the dictionary, and then chooses which attribute to access via a custom ghPython component. currently I am only getting Null values:

Hope the explanation is clear. Thank you in advance!

Hmm interesting! Let me double check I got things right:

  • You’re creating the dictionaries inside a python script within Grasshopper
  • You want to send said dictionaries to speckle from Grasshopper
  • You want some other user in another script to be able to receive said dictionaries natively.
  • You wish the branches to be preserved on send/receive operations (this is already supported)

Are these statements correct?

If all these are true, the only issue I can see with your approach is a bit technical in nature:

Grasshopper is coded on C# programming language but is capable of running python by doing some black magic (not important here). The important part is that even though you can run python code, if you output purely python entities (such as python dictionaries) these won’t be compatible with the equivalent in c# (which are also called dictionaries).

I’m going to do a couple of tests and get back to you, but meanwhile could you please confirm my assumptions are correct?

thanks for bringing this up! Super interesting use-case, if you can share some details about your workflow (once it works!) i’m sure other community members would find it useful!

Side thought but… have you tried just sending the data from Grasshopper with a Create Speckle Object Component?

This is equivalent to creating a Key/Value dictionary, but it’s fully compatible with the way speckle converts objects and will ensure every geometry gets properly converted before send.

In general I would recommend this approach unless you’ve already tried it and it doesn’t fit your needs! (in which case i’d love to know why it doesn’t in your particular case :pray:t3:)