Grasshopper

algorithmic modeling for Rhino

Hi there, 

Does anyone know how to add input/output parameters from C# script components?

I know how to do it in Visual Studio. The reason I am asking is that I want to share user object components on GitHub only by sharing their code. I know all manual options, only looking for a fully scripted solution. 

This is how far I have reached:

Component.Params.Input[0].NickName = "TextIN";
Component.Params.Input[0].Access = GH_ParamAccess.list;
Component.Params.Input[0].Description = "This is to test how to share grasshopper 

The last problem to solve is that I cannot specify the data type. 

Any help is very much appreciated. 

Views: 3240

Replies to This Discussion

Hi,

You can do as follows:

    Grasshopper.Kernel.Parameters.Param_ScriptVariable param = new Grasshopper.Kernel.Parameters.Param_ScriptVariable();
    param.TypeHint = new Grasshopper.Kernel.Parameters.Hints.GH_BooleanHint_CS();
    param.NickName = "addparam";
    this.Component.Params.RegisterInputParam(param, this.Component.Params.Input.Count);

By the way,Param_ScriptVariable is only allowed for script components.

Panda.

Yup, also always be sure to call Component.Params.OnParametersChanged() when you're done dicking with the parameters outside of normal channels.

Hi David, 

The complete story is that I want to share user component objects only as their inner scripts on GitHub, for a relatively large group of students to collaborate. Long story short, the goal is to let a user bring a C# script component on GH canvas, paste the script from GitHub and then the right inputs should appear with descriptions and TypeHints. Currently it works with a hiccup:

Grasshopper.Kernel.Parameters.Param_ScriptVariable param0 = new Grasshopper.Kernel.Parameters.Param_ScriptVariable();
param0.Access = GH_ParamAccess.list;
param0.TypeHint = new Grasshopper.Kernel.Parameters.Hints.GH_CurveHint();
param0.NickName = "InC";
param0.Description = "Input curves to explode";
this.Component.Name = "GrevillePoints";
this.Component.NickName = "G_EditPoints";
if(!(this.Component.Params.Input.Exists(lambda => lambda.NickName == "InC")))
{
this.Component.Params.RegisterInputParam(param0, 0);
}
this.Component.Params.OnParametersChanged();
bool HasRunMoreThanOnce = (this.Component.RunCount > 0);
if(HasRunMoreThanOnce && this.Component.Params.Input.Exists(lambda => lambda.NickName == "InC"))
{
Point3dList[] CGVertices = new Point3dList[InC.Count];
for(int i = 0;i < InC.Count;i++)
{
Curve iCrv = InC[i];
NurbsCurve NC = iCrv.ToNurbsCurve();
CGVertices[i] = NC.GrevillePoints();
}
A = CGVertices;
}

The main part that actually requires the input curves cannot run because the component must be closed once so that the input gets actually added. At the moment, I can comment out that part, let it run once to create the input and then run the whole thing. Is there a way to postpone running the second part after the component has run at least once?

Any other way to set up a fully text-based collaboration workflow?

 

Is sharing all that additional bookkeeping code really easier than sharing the components themselves?

The first problem you'll get is that you're not supposed to run code that modifies the topology of the graph (adding/removing wires, adding/removing inputs or outputs, changing parameter options like flatten/graft, enabling/disabling components, etc. etc.) within the solution.

The correct way to do it is to trigger that code from user interface events such as mouse clicks, or to handle the SolutionStart event on the relevant GH_Document and make the modifications there. This is difficult, maybe even impossible to do from a Script component because it doesn't get compiled until after the solution has started.

I assume you're looking for a solution within Rhino5? As in, there's nothing I can do to the Rhino6 wip that will help you short term?

Sharing everything as scripts is most preferable because of its maximum readability for outsiders (e.g. those without GH installed). We'd like to streamline code reviews and tutorial writing, collecting best codes, etc. This would be all simplified by sharing textual code on GitHub. Of course there is always the option of sharing the GHA builder package as a Visual Studio project. However, this is not an option here because I'm working with a group of beginners. Besides, the ease of working with scripting components in terms of frequent editing would be gone with VS projects.

Let me describe it in another way: 

Component.Params.Input[0].NickName = "TextIN";
Component.Params.Input[0].Access = GH_ParamAccess.list;
Component.Params.Input[0].Description = "This is to test how to share..."

This works just fine; except for the fact that I could not fine a way to add a "TypeHint" because the Type property was read only

I understand why changing the topology of the components graph could be problematic. But cannot see the danger in changing the name and type hint of a parameter

Yes, it is about Rhino5, for the following 8 weeks so that we could exchange codes with students easily in both directions. 

Hi Panda, 

Thanks a lot for this hint; however, after adding a parameter like this it is not possible to connect it to a data source (the magnet-like snapping on GH canvas does not allow wires to be connected to the registered/created parameter). Is something else needed to activate the registered input?

This is what I'm trying:

Grasshopper.Kernel.Parameters.Param_ScriptVariable param0 = new Grasshopper.Kernel.Parameters.Param_ScriptVariable();
param0.Access = GH_ParamAccess.list;
param0.TypeHint = new Grasshopper.Kernel.Parameters.Hints.GH_CurveHint();
param0.NickName = "InC";
param0.Description = "Input curves to explode";
//this.Component.Params.Input[0] = param0;//this way did not work either

this.Component.Params.RegisterInputParam(param0, 0);

Hi,

It works fine!

Yes, but there is still a problem; has to be run twice to get it to work. I'll write above to David the whole story. Thanks very much for helping me out. 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service