Creating Custom Contextual Components

What a nice bit of alliteration to start off a rainy Tuesday, eh?

For reasons unknown, I’d like to create a custom Contextual Component. IGH_ContextualParameter is available in the default Grasshopper Library. But Grasshopper doesn’t seem to recognise it as a Contextual Component when I implement this alongside GH_PersistentParam<T>. Butternuts.

I’ve discovered that the real meat and bones is sequestered away inside the CurveComponents.gha plugin which has an abstract class called ContextualParameter<T>. The only way I can access this is to reference that plugin into my project. Which works! It’s completely identical hurrah!

So. Questions. Questions. Questions.

  1. Do I need this abstract class? Are there other ways? Is Grasshopper/Rhino or whoever internally checking for this abstract class when GrasshopperPlayer is called?
    1.1 If I do need this class, is there a better way to package/reference it? Or can I rely on it always being there?
  2. Is what I’m doing a supported/expected idea, or should I avoid such tomfoolery?
  3. Any other hints?
  4. Are there any samples? I can’t find any :blush:

– cs

@AndyPayne a little birdie told me you may some insight :bird:

Hey Callum. I spoke with Steve about your questions. In general, these components weren’t really designed with the intent of 3rd parties extending them. It would probably be best to figure out what it is you’re trying to do and then we can either implement it ourselves or get the classes structured so that you can properly implement this without us accidentally breaking our SDK because you’re using something we didn’t really intend to be public. Does that makes sense?

Hey @AndyPayne thanks! That’s good to know :blush:.
I was trying to create a Get Plane contextual parameter

1 Like

So, this should already work with the Get Geometry component. I know we didn’t expose the Plane as one of the object types… but I just tested a really simple example (see attached) and it does work with the GH Player.

MovePlane.gh (4.1 KB)

1 Like

I did try this, and it does work. But it doesn’t prompt a user to create a plane, a user can’t exactly (as far as I know) create a plane in Rhino to select later. And I need to get a plane oriented in space

Ah. I see. The Get Geometry prompt doesn’t let you create a plane, but you can select one already made. Rhino does have a Plane command although it really just makes a planar surface. Still, maybe this could be used for your purpose?
As you’ve rightly described, Rhino doesn’t really have a native way to create a “Plane” within the Rhino context. Is this why you wanted to make you’re own Context Component? Hmm… I need to think about this some more.

I was hoping to use it with Grasshopper Player to let the user Define a Plane Input yes :slight_smile:

Would a Plane Surface work? Meaning, could you use the Plane command and use that?

Users would have to draw a plane surface before running the command and then select that?

Yes. Not ideal I understand but that’s generally how the “Get Geometry” one works.

I’ll have a think about it! It’s a working suggestion, which is always great

In talking with Steve, it does appear that we do have a RhinoGet.GetPlane method which might work for what you want… so it’s probably doable from our side. Is there a rush on your side to have this implemented ASAP? I can’t make any promises but I have added a new YT for this issue.

3 Likes

It’s not critical at all! But it could be very handy some day :slight_smile:. Thankyou so much @AndyPayne!

Just another idea if you could use it.
Taking 3 points using the GetPoint and then running those to make a plane defined by three points has been my work around. 1 for orgin, 1 for x and 1 for y. Same deal as running the cplane command in Rhino. :man_shrugging: I could be miss-understanding the topic.

4 Likes

That could work too! Great suggestion :blush:

1 Like

+1 for a Get Plane contextual component. We are using the workaround that Ryan described by converting a plane’s origin, x vector, and y vector to three points, then reconstructing the plane upon input inside the hops component, but that is not ideal. Some have already talked about writing our own Get Plane component, which is how I found this thread.

I do not think your youtrack link works, though I would be interested in tracking the progress of this.

Hi James -

You should be able to see that now.
-wim

1 Like

@James_D @csykes I have added a new contextual Get Plane component which should be available in the next stable 8.1 release (should be 2 weeks from now). I need to do a bit more testing, but I believe everything is in order. I will also need to release a new build of Hops because there was a minor change that was added to rhino.compute in order to support this new component. Still, everything should be available in about 2 weeks.

3 Likes

Oh awesome! How exciting :grin: