Sdk Extend Rhino Script
Last changed: -204.177.179.96

.
Developer.NET
VersionRhino 4
SummaryRhino 4 plug-ins can now add new scripting methods to RhinoScript

Rhino 4 plug-ins can extend the RhinoScript with new objects and methods to permit users to create elaborate scripts for plug-ins. The rhino plug-in class has a virtual function called GetPlugInObjectInterface which plug-ins can override and return a COM enabled class. In .NET creating a COM enabled class is as easy as adding a ComVisible attribute to a class.

VB.NET

1. Create a ComVisible class

By adding the ComVisible attribute to a class, all of the public functions inside of the class are accessible to COM (ie RhinoScript)

  <System.Runtime.InteropServices.ComVisible(True)> _
  Public Class MyScriptClass
    Public Sub Print()
      RhUtil.RhinoApp.Print("Hello from my VB.NET plug-in!!" + vbCrLf)
    End Sub


    Public Sub MakePoint(ByVal x As Double, ByVal y As Double, ByVal z As Double)
      Dim pt As New On3dPoint(x, y, z)
      RhUtil.RhinoApp.ActiveDoc.AddPointObject(pt)
    End Sub
  End Class

2. Override GetPlugInObjectInterface and return the com class

  'inside of your MRhinoPlugIn derived class
  Public Overrides Function GetPlugInObjectInterface(ByRef iid As System.Guid) As Object
    Return New MyScriptClass()
  End Function

Read below on how to use your class in RhinoScript

C# (Rhino 4)

1. Create a ComVisible class

By adding the ComVisible attribute to a class, all of the public functions inside of the class are accessible to COM (ie RhinoScript)

  [System.Runtime.InteropServices.ComVisible(true)]
  public class MyScriptClass
  {
    public void Print()
    {
      RhUtil.RhinoApp().Print("Hello from my C# plug-in!\n");
    }


    public void MakePoint(double x, double y, double z)
    {
      On3dPoint pt = new On3dPoint(x, y, z);
      RhUtil.RhinoApp().ActiveDoc().AddPointObject(pt);
    }
  };

2. Override GetPlugInObjectInterface and return the com class

  public override object GetPlugInObjectInterface(ref System.Guid iid)
  {
    return new MyScriptClass();
  }

Use the plug-in script functionality

Inside of a RhinoScript routine get a hold of your plug-in's script class and have fun!

The following is some sample RhinoScript. Assuming that your plug-in is named WikiSamples

  Dim customobj
  On Error Resume Next
  Set customobj = Rhino.GetPlugInObject("WikiSamples")
  If Err Then
    MsgBox Err.Description
  Else
    customobj.Print
    customobj.MakePoint 1,2,3
    Rhino.Redraw
  End If