A ScriptCodeGenerator_CS2VS connected to a C# ScriptComponent output generates a Visual Studio version of the ScriptComponent.
The component has been developed gradually over time according to my own needs and it produces VS C# code in a style I find useful.
The code generation is based mostly on code templates, of which the default templates are hardcoded. The generator also supports customized code templates which can be feed into the corresponding inputs via text panels. Templates that can be customized:
- InparamTemplate (for registering parameters)
Also properties like Namespace, Uses clauses, Classname and Superclass names etc., can be specified. The component and its inputs and outputs has description text (on mouse over) describing in more detail their respective use. See also a video clip with a simple script example (Vimeo : Vimeo - ScriptCodegen_CS2V for Grasshopper )
DIFF friendly code: The generated code is optionally written direclty to disk, and the code layout is adapted to support using DIFF tools to keep source code in two-way sync between VS and the ScriptComponent. The layout indends to keep the DIFF as "clean" as possible, with differences only at the top and the bottom of the file (and only a few rows in the middle).
The code generator is by no means 100% robust at this stage, but in most cases it will do what you would expect, and it's a benefit to have 95% boilerplate code autogenerated for you, including convenient property setters and getters for the params.
An image below shows an example of the code format of a getter (screenshot from this CodeGeneration component, which itself is aguto-generated from a ScriptComponent by a copy of itself!)
Limitations: Well, many, but most notably the component does not yet have any code templates for DataTrees.
Open source: The plan is to refactor the code and when it doesn't look to ugly, make the component open source. The component will continue to evolve according to my own needs in my own pace, unless someone drops me a mail with ideas about how to improve the component or otherwise contribute to the development
// R1.8.1 Fix: Default values now added to Inports
// R1.8.1 Fix: Missing Mesh type now supported a Param type + default values.
// R1.8.1 Enhancement: Better (warning) messages. Optional msg header added (e.g. "hint" etc).
// R1.8.1 Enhancement: Now also wrapping Output Param names in "nameof(NickName)"
// R1.8.0 Templates replaced with real skip chars
// R184.108.40.206b - Main Tab (Category) and Tab Section (Sub Category) added to Component Description.
// m_VersionInfo now entirely replaced. Inserted as hardcoded.
// Print calls now directed to dummy method + warning.