Custom Speckle Object integrating with existing Speckle GH Components

My aim is to create a very simple custom Speckle Object that can interact with the existing Speckle GH Components, like Extend Speckle Object, or Speckle Object Keys, etc.

I can define, create, and send the object to a Stream just fine.
I can also use the Deconstruct Speckle Object Component.

However things break when using some other GH Components.
Correct me if I’m wrong, but I believe it is because these components try to either a) check if an incoming object is/casts to a GH_SpeckleBase and then grab its .Value, or b) use a Converter, which has to implement ISpeckleConverter?

I don’t think I can implement a CastTo<GH_SpeckleBase> in my GH_Goo wrapper because that lies in the GrasshopperConnector, correct? The best I could do is cast to GH_Goo<Base> I believe

Do I have to implement a whole ISpeckleConverter then? If so, how do the Speckle GH Components know how to seek those methods? (ie, how should the project structure look?)

Alternately, is there a reason why those GH Components need to check for input objects being GH_SpeckleBase, and not just GH_Goo<Base>?

Hi @daniel-fink!

What you’re describing should be 100% doable already.

We do have our own subclass of GH_Goo<Base> for convenience reasons. But for the purpose of your component, returning a GH_Goo<Base> as output should be just fine, as GH_SpeckleBase inherits directly from that.

I would love to see the class (and how you’re outputting it) because it seems quite weird.

All those components actually do their own checking in the solution to support ToSpeckle conversions automatically if available. And for that, we’re not even casting to GH_Goo, we’re directly grabbing the value of an IGH_Goo and checking if said Value is Base

As for GH_SpeckleBase, it is already capable of casting generic GH_Goo<Base> to itself using Grasshopper’s own CastFrom logic.

Would it be possible to share a reproducible example with us? Would be keen to investigate what’s going on here, and if anything needs fixing on our side… we sure will!

Thanks @AlanRynne for the quick reply.

Correct me if I’m wrong, but I think there is some missing casting in some GH Components?
I can use the Extend Speckle Object Component fine (because, as you say, it checks whether the .Value property of an object cast to IGH_Goo is a Speckle Base, however is that cast missing from Extend Speckle Object By Key Value?

I haven’t checked the other components that are throwing errors for their casting logic yet…

:thinking: Oh I see! We must have miss-aligned this behaviour at some point.

I’ve opened a ticket for this, and most likely will release a hotfix of 2.14 with this included.

This doesn’t really solve the whole issue though… As Gh_SpeckleBase should already be able to cast any Gh_Goo to itself, the other failing components (such as Get Object Value by Key) should work with your output already but they’re not. :smiling_face_with_tear:

Can you share with us some reproducible example of this? Or at least some screenshots of the parameters you’re setting as output and the GH_Goo that backs them?

1 Like

@AlanRynne yes I think I know what you mean re:
var value = goo.GetType().GetProperty("Value")?.GetValue(goo); should still return a valid Base for GH_Goo<Base>s

I just pushed my code here: rangekeeper/RangekeeperGrasshopper at speckle-interop · daniel-fink/rangekeeper · GitHub

The intention is to make a simple Entity-Relationship graph from [Detached] Bases in a class that inherits from Collection (called Assembly). I’d say most of the GH Component logic is from just copying how Speckle is doing it for generic Speckle objects in GH… Let me know what you find.

1 Like