Skip to content

corbane/Ghx

Repository files navigation

A Roslyn Script component for Grasshopper

!!! EXPERIMENTAL

Features

  • Auto compile a csx files
  • Auto update inputs/outputs
  • Live debugging with vscode/omnisharp (The debugger does not reload Rhino and Grasshopper at each compilation, just save the source file)

scrennshot

Requirements

For live debugging:

Currently / Known Issues

  • Currently is not supported on MacOS (but it's possible)
  • Not tested with Data Tree access
  • Derived types are not implemented (eg. class CustomMesh : Mesh {})
  • If the name of the field (eg. myVar) change (->MyVar) the grah links are lost

Install / Use

After installing vscode and compiling the sources, you must have the component under the Math tab.

At first, you have an empty component

Select Source... in the component pop-up menu or double-click on the component. A dialog box appear then select a Roslyn script (*.csx) or enter a new name.

You must see two files in the target directory

  • libs.csx
  • <the name you have typed>.csx

libs.csx defines the assembly references that the script needs, like RhinoCommon.dll

The second is the script that start with #lod "./libs.csx"

This is an example of script:

#load "./libs.csx"

using Rhino.Geometry;

[Input ("The NickName", "A description of the input")]
var plane;

[Input ("Min")]
double min;

[Input ("Max")]
double max = max > 0 ? max : 1.0; // Define a default value

var interval = new Interval (min, max);

[Output ("B", "Define an output")]
var box = new Box (plane, interval, interval, interval);

For debugging, select Debug... in the component pop-up menu or double-click on the component again.

Visual Studio Code must start and load your script.

When using for the first time, only one extension must be installed.

If you have a previous installation of vscode, do not cry! Your extensions is not lost. The component launches a special instance of vscode.

Install the c# extension in this instance. you lust have two extensions enabled:

The Rhino Code plugin is in this repository under the editor folder.

now, define a breakpoint and press F5 or F4.

If the Rhino process is not found, a selection box asks you to select it.

The F4 key is an auto reload shortcut. it stops the debugger, waits for a delay for compilation of the source (for example: 1s) and automatically restarts the debugger.

About

Debugging Roslyn script inside Grasshopper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published