Extending RhinoCompute Server with plugins

Hi,
Does RhinoCompute Server allow Rhino plugins/commands to be executed?

Say for example, that I currently have a circle packing algorithm script/plugin/command, that returns the solution of packed random circles.

I would like to be able trigger this from various applications such as a web page and console applications ideally without having to rewrite the algorithm in other languages

Thanks,

Found this via other topic by @enmerk4r:

There are three different ways to do this

  1. Use the grasshopper endpoint as described in the post you found
  2. Pass a python script along with a dictionary of data for the script to process
  3. Extend the compute server with your own custom functions defined in a plug-in

(1) and (2) are available on compute.rhino3d.com. (3) would require you to host your own instance of compute.

For python (2), the process is very similar in concept to how GhPython works, You would pass a script and a dictionary to compute. Compute would set variables in the script to matching keys in the dictionary. You also pass a list of variable names for values to extract and return.

For item (3), your plug-in can register a set of functions that become new endpoints. Compute handles the serialization.

Item (3) seems like what we’d like to experiment with.
How would you go about registering new endpoints and make them accessible?
The Rhino Plugin VS Template does not seem to have anything related to compute endpoint, am I missing something ?

There is a function in the V7 RhinoCommon named

Rhino.Runtime.HostUtils.RegisterComputeEndPoint(string, Type)

The idea is that you would define a static class in your plugin and then register that class with compute when the plugin is first loaded. For example

static class MyCustomComputeFunctions
{
  public static double Add(double, x, double y, double z) { return x+y+z; }

  public static double AdjustedArea(Curve curve, double adjuster)
  {
    var amp = Rhino.Geometry.AreaMassProperties.Compute(curve);
    return amp.Area * adjuster;
  }
}

In your plugin’s OnLoad function you would add

protected override LoadReturnCode OnLoad(ref string errorMessage)
{
  Rhino.Runtime.HostUtils.RegisterComputeEndPoint("Rhino.CustomEndPoint", typeof(MyCustomComputeFunctions));

  return base.OnLoad(ref errorMessage);
}

You will need to install your plug-in in Rhino for your custom compute server.

Once this is complete, you should be able to go to your custom compute /sdk endpoint and see the new functions listed at the bottom of the page.