C# script for Grasshopper that automatically creates an IronPython2

I’m trying to write a
C_question.gh (8.1 KB)
component, parses Python code to extract inputs/outputs, renames or adds the necessary parameters, and injects the code into the component.

The main issues I’m facing are:

  1. The code is not being written into the IronPython2 component.
  2. When I rename the inputs and outputs, I lose the ability to automatically set their parameter types (e.g. number, int, integer, etc.).

Is there a way to achieve this while preserving or restoring the parameter types?

some quick thoughts:

  1. try to move this line way later in your routine, after all that “editing” to your pyComp. may explain why code isn’t written to the actual component instance.
GrasshopperDocument.AddObject(pyComp, false);
  1. is it because you instantiate it as a generic object input here?
var param = new Grasshopper.Kernel.Parameters.Param_GenericObject();