Rhino.Scripting 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Rhino.Scripting --version 0.2.0
NuGet\Install-Package Rhino.Scripting -Version 0.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rhino.Scripting" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rhino.Scripting --version 0.2.0
#r "nuget: Rhino.Scripting, 0.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Rhino.Scripting as a Cake Addin
#addin nuget:?package=Rhino.Scripting&version=0.2.0

// Install Rhino.Scripting as a Cake Tool
#tool nuget:?package=Rhino.Scripting&version=0.2.0

Rhino.Scripting

logo

Rhino.Scripting is an implementation of the RhinoScript syntax in and for F# (and C#).
It enables the use of RhinoScript in F# and all the great coding experience that come with F# and C#, like:

  • automatic code completion while typing
  • automatic error checking and highlighting in the background
  • type info on mouse over
  • type certainty even without type annotation (type inference)

What is RhinoScript ?

RhinoScript provides application scripting for the Rhino3D CAD app.
RhinoScript has more than 900 functions to control all kind of aspects of automating Rhino3D.
It was originally implemented in 2002 in VBScript.
Extensive Documentation on the original VBScript based version is available here.

In 2010 all functions from RhinoScript where reimplemented in IronPython (Python running on .NET).
This allowed the use of a modern, rich and dynamically typed programming language with a huge standard library and also access to all function of the underlying .NET Framework as well as the RhinoCommon SDK.

What is this repro?

This repro has all RhinoScript functions reimplemented in F#
It is literally a translation of the open source Ironpython rhinoscriptsyntax implementation to F#.

Get started

The recommended scripting use case is via the RhinoCode Editor.
However you can use this library just as well in compiled F#, C# or VB.net projects. Or even in Grasshopper C# VB.net scripting components.

First reference the assemblies. In an F# or C# scripting editor do

#r "nuget: Rhino.Scripting"

The main class of this library is called Rhino.Scripting it has all ~900 functions as static methods. In F# you can create a shortcut like this:

type rs = Rhino.Scripting  // type abbreviation  (alias) for RhinoScriptSyntax

then use any of the RhinoScript functions like you would in Python or VBScript.
The CoerceXXXX functions will help you create types if you are too lazy to fully specify them.

let pl = rs.CoercePlane(0 , 80 , 0) // makes World XY plane at point
rs.AddText("Hello, Seff", pl, height = 50.)

How about the dynamic types and optional parameters from VBScript and Python?

Many RhinoScript function take variable types of input parameters. This is implemented with method overloads. Many RhinoScript function have optional parameters. These are also implemented as optional method parameters.

Example

for example rs.ObjectLayer can be called in several ways:

rs.ObjectLayer(guid) to get the layer of one object, returns a string
rs.ObjectLayer(guid, string) to set the layer of one object (fails if layer does not exist), no return value
rs.ObjectLayer(guid, string, createLayerIfMissing = true ) to set the layer of one object, and create the layer if it does not exist yet, no return value
rs.ObjectLayer(list of guids, string) to set the layer of several objects (fails if layer does not exist), no return value
rs.ObjectLayer(list of guids, string, createLayerIfMissing = true ) to set the layer of several objects, and create the layer if it does not exist yet , no return value

these are implemented with 3 overloads and Optional and DefaultParameterValue parameters:

    ///<summary>Returns the full layer name of an object.
    /// parent layers are separated by <c>::</c>.</summary>
    ///<param name="objectId">(Guid) The identifier of the object</param>
    ///<returns>(string) The object's current layer.</returns>
    static member ObjectLayer(objectId:Guid) : string = //GET
        let obj = Scripting.CoerceRhinoObject(objectId)
        let index = obj.Attributes.LayerIndex
        State.Doc.Layers.[index].FullPath

    ///<summary>Modifies the layer of an object , optionally creates layer if it does not exist yet.</summary>
    ///<param name="objectId">(Guid) The identifier of the object</param>
    ///<param name="layer">(string) Name of an existing layer</param>
    ///<param name="createLayerIfMissing">(bool) Optional, Default Value: <c>false</c> Set true to create Layer if it does not exist yet.</param>
    ///<param name="allowAllUnicode">(bool) Optional, Allow Ambiguous Unicode characters too </param>
    ///<param name="collapseParents">(bool) Optional, Collapse parent layers in Layer UI </param>
    ///<returns>(unit) void, nothing.</returns>
    static member ObjectLayer( objectId:Guid
                             , layer:string
                             ,[<OPT;DEF(false)>]createLayerIfMissing:bool
                             ,[<OPT;DEF(false:bool)>]allowAllUnicode:bool
                             ,[<OPT;DEF(false:bool)>]collapseParents:bool) : unit = //SET
        let obj = Scripting.CoerceRhinoObject(objectId)
        let layerIndex = 
            if createLayerIfMissing then  UtilLayer.getOrCreateLayer(layer, UtilLayer.randomLayerColor, UtilLayer.ByParent, UtilLayer.ByParent, allowAllUnicode,collapseParents).Index
            else                          Scripting.CoerceLayer(layer).Index
        obj.Attributes.LayerIndex <- layerIndex
        if not <| obj.CommitChanges() then RhinoScriptingException.Raise "Rhino.Scripting.ObjectLayer: Setting it failed for layer '%s' on: %s " layer (Nice.str objectId)
        State.Doc.Views.Redraw()

    ///<summary>Modifies the layer of multiple objects, optionally creates layer if it does not exist yet.</summary>
    ///<param name="objectIds">(Guid seq) The identifiers of the objects</param>
    ///<param name="layer">(string) Name of an existing layer</param>
    ///<param name="createLayerIfMissing">(bool) Optional, Default Value: <c>false</c> Set true to create Layer if it does not exist yet.</param>
    ///<param name="allowUnicode">(bool) Optional, Allow Ambiguous Unicode characters too </param>
    ///<param name="collapseParents">(bool) Optional, Collapse parent layers in Layer UI </param>
    ///<returns>(unit) void, nothing.</returns>
    static member ObjectLayer( objectIds:Guid seq
                             , layer:string
                             , [<OPT;DEF(false)>]createLayerIfMissing:bool
                             , [<OPT;DEF(false:bool)>]allowUnicode:bool
                             , [<OPT;DEF(false:bool)>]collapseParents:bool) : unit = //MULTISET
        let layerIndex = 
            if createLayerIfMissing then  UtilLayer.getOrCreateLayer(layer, UtilLayer.randomLayerColor, UtilLayer.ByParent, UtilLayer.ByParent, allowUnicode, collapseParents).Index
            else                          Scripting.CoerceLayer(layer).Index
        for objectId in objectIds do
            let obj = Scripting.CoerceRhinoObject(objectId)
            obj.Attributes.LayerIndex <- layerIndex
            if not <| obj.CommitChanges() then RhinoScriptingException.Raise "Rhino.Scripting.ObjectLayer: Setting it failed for layer '%s' and '%s' of %d objects"  layer (Nice.str objectId) (Seq.length objectIds)
        State.Doc.Views.Redraw()

Contributing

Contributions are welcome even for small things like typos. If you have problems with this library please submit an issue.

Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.7.0 179 9/10/2023
0.6.2 175 7/9/2023
0.6.1 156 6/18/2023
0.6.0 160 5/7/2023
0.5.1 275 2/20/2023
0.5.0 239 2/18/2023
0.4.0 273 1/21/2023
0.3.0 320 12/3/2022
0.2.0 311 11/25/2022

First release