Write Rhino Commands in Grasshopper


Is it possible to have this constantly running?
I have a curve, I divide it, the player is still running, so I can modify the curve and see the division points readapting?

The logic contained in the grasshopper definition runs as a regular Rhino command. Operations that you typically can do inside of a command should be possible.

Hey Jeff, I thought we put some subobject edge support into GH. I’ll need to research this a bit more.

1 Like

hi @stevebaer,

How about record history?
Can I have record history on a grasshopper definition?

Hmm… that is a tough one. I’ll have to think about it. Technically this is not currently possible, but I can imagine a way to make this work.

1 Like

something like having a record history component in gh that picks the object guid… but i might be wrong.

hey Steve,

For what I’m doing now, I was able to use geometry then find the edges that way… it wouldn’t work in all situations since it only makes sense for this particular model but I’m sure other models could be made to work similarly.

If it’s not already possible to subobject select nor close to being possible then don’t sweat it… a request for the back burner.

Hi @stevebaer , sorry if this was asked already, but is there a way to simulate the behavior of commands like fillet edge?
So not necessarily a one way execution where user jumps from one input requirement to the next.
Rather have the user select some geometry as the main input required by the definition, then switch to a different command line context, where all the renaming inputs are visible and you can select and tweak as many times before committing to anything.

I posted similar question/request yesterday and updated today Referencing and manipulating objects, clicking on subobjects

Not currently. I’m trying to imagine how to set up a definition that would allow for this and am having trouble being “creative” today. If you have any ideas on how you think this could work, I’m all ears.

@stevebaer Attached is a simple example for what I had in mind.
I think using groups could help, where you define lets say “sub-contexts” for the running command.
Each would remain persistent till the user chooses to proceed to the next context if any.
Setting this up, it made me think that also having the option to set defaults for “Get Number” might be useful.
The other key thing for this to work would be, if one of the components has “At most: unlimited”, in the edit prompt the name of that component would be prefixed by Add, allowing the user to add more. I guess in that case internally, per context, you would maintain a string,datatree dictionary, and you should be able to append elements to them and re-inject them to the definition…

I guess also another thing needs to be agreed on, which is, like grasshopper, you should expect that any set data will just be served to you flattened and your definition should always handle different data matching cases.

GhRhCommands.gh (18.4 KB)

1 Like

Hi everyone,

I was wondering, if I could start the Grasshopper Player within a command directly, without having to script the command line.

The reason for that is, that I want to integrate the Grasshopper Scripting capabilities into an already existing c# based workflow.

Here is an example of what I mean:

using System.Collections.Generic;
using Rhino;
using Rhino.DocObjects;
using Rhino.Commands;
using Rhino.Geometry;

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
            //Get Polyline
            if (Rhino.Input.RhinoGet.GetPolyline(out Polyline polyline) != Result.Success)
                RhinoApp.WriteLine("No Polyline selected - aborting");
                return Result.Cancel;

            //Get Breps
            if (Rhino.Input.RhinoGet.GetOneObject("Get Brep", false, ObjectType.Brep, out ObjRef objRef) != Result.Success)
                RhinoApp.WriteLine("No Bres selected - aborting");
                return Result.Cancel;

            //Get Brep
            Brep inputBrep = objRef.Brep();

            //Enter Threshold in which GH Script is not executed
            double threshold = 150;

            List<Brep> breps = new List<Brep>();
            foreach (Point3d point in polyline)
                Point3d closestPt = inputBrep.ClosestPoint(point);
                double distance = point.DistanceTo(closestPt);

                if (distance < threshold)
                    string ghFilePath = @"C:\Users\Martin.Manegold\Desktop\GH_Player_example.gh";

                    //RUN GH PLAYER SOMEHOW
                    // This would be the contextBake output of GH Player:
                    Brep playerOutputSphere = new Sphere(point, distance).ToBrep();                      



            //Work with the output.
            //Get next serial name from database
            //Delete unwanted Geometry

            //Set Colors, Layers, etc.
            ObjectAttributes attGreen = new ObjectAttributes();
            attGreen.ColorSource = ObjectColorSource.ColorFromObject;
            attGreen.ObjectColor = System.Drawing.Color.Green;

            ObjectAttributes attRed = new ObjectAttributes();
            attGreen.ColorSource = ObjectColorSource.ColorFromObject;
            attGreen.ObjectColor = System.Drawing.Color.Red;            

            double thresholdArea = 10000;

            foreach (Brep brep in breps)
                AreaMassProperties amp = AreaMassProperties.Compute(brep);
                if (amp.Area > thresholdArea)                
                    doc.Objects.AddBrep(brep, attGreen);                
                    doc.Objects.AddBrep(brep, attRed);

            return Result.Success;

As I understand, this would be theoretically be possible through Rhino Compute, but this seems like using a sledge-hammer to crack a nut.


GH_Player_example.gh (10.5 KB)

Hi Martin,
I added your request to the wish list at https://mcneel.myjetbrains.com/youtrack/issue/RH-61306

1 Like

Hi Steve,

the release target for the SDK support was set to 8.x. But in the comment in YouTrack, you wrote this would be possible already using “GetPluginObject on the grasshopper plug-in”

Can you provide an example/hint on how this would work with GetPluginObject?


Don’t pay attention to how I set release targets. I’m trying to keep my 7.x list at a minimum number right now as we deal with high priority issues that always tend to pop up right after a major release.

Writing an example of using GetPlugInObject would take almost as much time as writing the functionality into RhinoCommon and I know that what I write would stop working in a service release as I tend to change those functions which are not part of our SDK.

Would it be possible to get a get-file/get-location object that would trigger rhino to open the locate file dialog and then spit out the location of that file as a string? Right now I’m just using the get string and copy pasting in the address after finding it in explorer which is a bit laborious.

Not sure what you’re trying to accomplish, but how about:

import rhinoscriptsyntax as rs
filename = rs.OpenFileName()


Thanks that works nicely I haven’t messed around with rhinosyntax lib much so I didn’t know if the grasshopper player would do stuff like that or if it required the specific get blocks. I still think it would be nice to just have this as a default block as I think using grasshopper player scripts to act on external files before bringing them into rhino or doing some sort of validation test of a set of models will be decently common use for this feature and this kind of thing just speeds up workflow.

Added to the wishlist at https://mcneel.myjetbrains.com/youtrack/issue/RH-61663

I probably won’t be able to get to this anytime soon so the python technique is a good recommended approach for now.

A post was split to a new topic: Run Rhino Commands from Grasshopper