Can RhinoPlugin take arguments?

I have created a Rhino plugin, I have done some research and couldn’t find a way to allow my plugin to take some arguments in the command line.

For example, I have created a plugin to draw a hexagon “DrawHex”

The plugin require the user to enter the length of the side i.e. “DrawHex(50)” will draw a Hex with each side has the length of 50mm.

Can this be done?

Yes this is possible. Don’t confuse the term plugin with command; a plugin can contain multiple commands. The commands, like DrawHex, can take arguments.
There are many examples, and many of them have user input

Thanks for your quick reply. I guess I didn’t make myself clear.

I want to use Rhino Script to call a Rhino Plugin command, where can I specific the size??

Basically I want to automate some process and to make use of my plugin command…

e.g. my code looks like this.

public class DrawHexCommand : Command
{

  public DrawHexCommand()
  {
     // Rhino only creates one instance of each command class defined in a
     // plug-in, so it is safe to store a refence in a static property.
     Instance = this;
  }

  ///<summary>The only instance of this command.</summary>
  public static DrawHexCommand Instance
  {
     get;
     private set;
  }

  ///<returns>The command name as it appears on the Rhino command line.</returns>
  public override string EnglishName
  {
     get { return "DrawHexCommand"; }
  }

  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  {
      // TO DO:
     return Result.Success;
  }

}

The following stuff, and much more, can be found in the examples I linked to earlier. I recommend you to go through the examples and learn to “speak Rhino code” :smile:

Command code:

private Result MakeMyDrawing(double length, RhinoDoc doc) 
{
// put code here to put a hexagon into the Rhino document
return Result.Success;
}
protected override Result RunCommand(RhinoDoc doc, RunMode mode0
{
    double length = 50.0;
    // RhinoGet.Get* methods are the most simple ways to get input
    // you can also use GetOption, GetPoint, GetObject, etc.
    Result res = RhinoGet.GetNumber("Give length", false, ref length);
    if (res != Result.Success) return res; // if canceled
    return MakeMyDrawing(length, doc);
}

Then in your RhinoScript you say:

_-DrawHexCommand 34.7 _Enter

to draw a hexagon with length 34.7

@menno The connection between “DrawHexagon” and “DrawHexCommand” isn’t clear. Or was it a slip-up?

Not a slip-up! Sorry for the confusion, I have updated the function name from DrawHexagon to MakeMyDrawing to reflect this.

You call the command in RhinoScript (or on the command line) with the EnglishName - in your code it is DrawHexCommand. When this command is executed, the command will call RunCommand(doc,mode). Then in this function, you can get values from the user (or script) and execute any other functions, like MakeMyDrawing.

I think you need to make a basic understanding of how the code works and how Rhino calls your code. It is the same from a script as from the command line.

Thanks menno.

My thinking is still stuck at those command line program where it takes arguments into the main function.

main( int argc, char *argv[] )

1 Like