OK, shameless plug;
Over time I’ve been extending my little C# to VS code generator (from Grasshopper’ C# ScriptComponent) to VS code, and I thought I might share it with this generous community which has shared so much with me.
The published version is compiled but I have a GH ScriptComponent version in which I do all my actual enhancements (due to the quick response in GH) and then I sync the exported source with the VS version using a DIFF tool.
(the original code generator I converted to VS by connecting a copy of “itself” as a source component… but today the component itself contains templates and code layouts which - if “reflecting upon itself” - gets a bit complex to preserve through the code generation process).
I’m considering making the component open source (that is, the C# script component version contains the “original” source) but only after some heavy code refactoring so the sources can be shared without too much shame.
Limitations: Some bits are still missing, like the code template for DataTree inputs (for the
DA.SetDataTree(int, value); syntax) with proper generic type casts etc, so if anyone has a well working syntax for this I’d be quick to add it.
I also had a bit of a problem to preserve skip sequences in text, like “
\n” and “
\t” etc. It works for some strings but not for all of them, depending on if they’re plain text feed via an Input or part of the source code itself (Anyway, for this reason I simply replace any such skip chars with a forward slash instead, so a little bit of “manual post-processing” in VS may be required for this).
There’s a video clip* on Vimeo demonstrating a simple use case.
Attached is also a better code generation example (gh definition) which converts my special
XorSliders ScriptComponent into VS code (requires the updated CS2VS plugin version 188.8.131.52) (Edit: replaced after bugfix):
* The clip was recorded running the Codegen component in debug mode from VS, so please disregard the display of error catching caught in the VS IDE, the compiled component will of course turn red instead).