algorithmic modeling for Rhino

I copied Arend's idea of using a text file to embed code into a scripting component. This way you can use Visual Studio or any other alternative as the editor.

It works real-time, the scripting component is run every time the file is saved. The code is also stored inside the component, so if you want to send the file to someone else, you just need to send the .gh. They don't need the text file or any additional plugin.

I haven't tested it much yet.

Things not working:
- You have to type the input arguments manually if you want intellisense for them.
- If you want to add assemblies you have to do it both in the scripting component and VS and manually add the using line.

Views: 1188


You need to be a member of Grasshopper to add comments!

Join Grasshopper

Comment by Thierry Baudart on January 21, 2017 at 12:41pm


This is exactly what I'm looking for but I don't understand how to make the link between FiletoScript component and the C# script component. Could you help me?


Comment by Jean-Francois L on June 9, 2015 at 12:13pm

After a bit of digging...


"Index was outside the bounds of the array." Means you did not put

"// <Custom code>" and "// <Custom code>"... As mentioned... ;(


I got : 1. Solution exception:[A]ScriptComponents.Component_CSNET_Script cannot be cast to [B]ScriptComponents.Component_CSNET_Script. Type A originates from 'ScriptComponents, Version=, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' in a byte array. Type B originates from 'ScriptComponents, Version=, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' in a byte array.

Type casting seemed to bother about versions I guess.

So I used dynamic conversion (Net 4.0) :

  var ghc = Grasshopper.Instances.ActiveCanvas.Document.FindComponent(point);
  dynamic scriptComponent = Convert.ChangeType(ghc, ghc.GetType());

instead of:

  var scriptComponent = (Component_CSNET_Script)Grasshopper.Instances.ActiveCanvas.Document.FindComponent(point);


ScriptComponent found in Script.gha from Grasshopper. Not really used since it dynamically casted. But might be useful for auto-completion.

Hope this could help someone.

Comment by Jean-Francois L on June 8, 2015 at 4:36pm


  I'm really interested to use your filetoscript component.

  But I can't make it running.

  I get "1. Index was outside the bounds of the array."... From Grasshopper.

  Secondly, I try to build the source and can't find where you got "ScriptComponent library".

  VS can't find it. Is it from a Grasshopper DLL ?


Comment by Vicente Soler on September 2, 2014 at 3:08am

Hi Arend,

Did you post any code for doing something similar that I might have missed?

I didn't write anything to export back the code when new inputs are created in the scripting component.

I'm not sure if it's worth it, you'd still have to close the file in VS and open it again, as it currently is you just have to copy paste one line of code after adding the inputs.

Comment by Arend on September 2, 2014 at 1:35am

nice! Very elegant refactor. The part of exporting new parameters is out as far as I understand?

// scriptComponent.SourceCodeChanged(new Grasshopper.GUI.Script.GH_ScriptEditor(Grasshopper.GUI.Script.GH_ScriptLanguage.CS));

Comment by Suryansh Chandra on September 1, 2014 at 12:23pm

super nice!

Comment by Mateusz Zwierzycki on September 1, 2014 at 8:24am

Ok, so now it works with both C# and VB. Please find the .gha here

(you have to be a member of the Milkbox group)

Comment by tzl on September 1, 2014 at 7:48am

Thank you for your detailed solution

Comment by Vicente Soler on September 1, 2014 at 5:16am

I forgot to add, if you want to build the .gha you need to add the script.gha reference in the plugin project.

Visual Studio won't allow you to reference files other than .dll. To work a round this you can copy/rename the file as a .dll, add the reference, close the project, open the .csproj file in a text editor and rename script.dll to script.gha. Remember to set copy local as false.

tzl: The .gha file is linked in a comment bellow.

Comment by David Stasiuk on September 1, 2014 at 3:49am

Yes! Thanks for sharing.





  • Add Photos
  • View All

© 2019   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service