Grasshopper

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: 1261

Comment

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

Comment by Sebastian Białkowski on January 10, 2020 at 2:14pm

Hey Thierry,

Just place c# componet on the circle above FiletoScript  or VS2GH component (VS2GH  is the new version of FiletoScript uploade bellow)

Comment by Sebastian Białkowski on January 10, 2020 at 2:11pm

Hey. I know it is very old topic, but I've updated this component by adding Custom Usings (in previous version, custom Usings where gone with each component update.)

So now just decorate your code by:

// <Custom using>

Your usings...

// </Custom using>

// <Custom code>

Your code...

// </Custom code>

// <Custom additional code>

Your extra code...

// </Custom additional code>

Here is VS project: VS2GH.7z

Best.

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

Hi,

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?

Thank 

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

After a bit of digging...

1)

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

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

2)

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=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' in a byte array. Type B originates from 'ScriptComponents, Version=1.0.0.0, 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);

3)

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

Hi,

  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 ?

  Regards,

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 

http://www.grasshopper3d.com/group/milkbox/forum/topics/file-to-scr...

(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

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service