Grasshopper

algorithmic modeling for Rhino

Dear GHA developers. As you may have noticed the preferred gui for variable parameters has changed in 0.8.0060. The old gui is still available, but has been marked Obsolete and will soon no longer be visible in Visual Studio autocomplete.

 

If you have a GH_Component class that implements IGH_VarParamComponent and you wish to switch over to the new gui, please do the following:

 

  1. Make a duplicate of the class and give it a different ComponentId
  2. Rename the original class to xxxx_Legacy or something and change the exposure to Hidden. This will for all intents and purposes hide the old component while still allowing Grasshopper to deserialize it from files.
  3. In the duplicate class, remove the implementation of IGH_VarParamComponent and instead implement IGH_VariableParameterComponent. Never implement both in a single component!
  4. The new interface should be easier to implement (details below) than the old one and it will provide the Zooming User Interface rather than the pop-up menu interface.

 

Methods to implement for IGH_VariableParameterComponent:

  1. CanInsertParameter. This method is called when Grasshopper needs to know whether or not it is allowed to insert a parameter at the given location. This method is called a lot (potentially) so make it spiffy. If you return True, a ZUI insert icon will be visible at high zoom levels.
  2. CanRemoveParameter. This method is called when Grasshopper needs to know whether or not it is allowed to remove the parameter at the given location. This method is called a lot (potentially) so make it spiffy. If you return True, a ZUI delete icon will be visible at high zoom levels.
  3. CreateParameter. If a new parameter is about to be inserted, this method will be called to instantiate it. You must return a valid IGH_Param instance or insertion will abort. Typically it's enough to: return new Param_Integer();
  4. DestroyParameter. If an existing parameter is about to be destroyed this method will be called. This is your last chance to stop deletion (though ideally if you didn't want it to be deleted you should have returned false from inside CanRemoveParameter). You don't actually have to do anything in DestroyParameter() except return true, it's just there to inform you.
  5. VariableParameterMaintenance. Again, you don't have to do anything here, but it's a great spot to make sure everything is hunky-dory. If for example your parameters must adhere to a specific naming scheme, or they have to be Optional, or their access needs to be List or.... this would be the best place to put that code. VariableParameterMaintenance() will be called every time a change is made to variable parameters and also when the component is deserialized.

 

I'll try and write a topic for this in the SDK documentation as soon as possible but until then, feel free to ask any questions about this here.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Views: 8672

Replies to This Discussion

Hi David,

thanks for the great improvement. I have two small questions:

- Is it possible to access the current parameter list from for example inside a CanRemoveParameter()? (To enforce a certain amount of parameters for example?)

- What kind of values can GH_ParameterSide side have? (How to determine which side we're on?)

Thanks a bunch!

Yes, all code running inside a GH_Component derived class has access to the current parameters. You can use the Params property to examine and change the input and output parameters of a component. For example, let's say the user is allowed to remove any input parameter, but only while we have at least 3 inputs left. I.e., we do not allow the component to have less than two inputs. In that case the implementation of CanRemoveParameter would look as follows:

The GH_ParameterSide enumeration only has Input and Output.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Ok, great! Thanks a bunch.

Would it be easy to force a component to expire after a label has been changed? Calling this.expireSolution(true); from the VariableParameterMaintanance method does not seem to do the trick.

The Params object has 3 events which you can register that will inform you when parameters change:

ParameterNickNameChanged(ByVal sender As Object, ByVal e As GH_ParamServerEventArgs)

ParameterSourcesChanged(ByVal sender As Object, ByVal e As GH_ParamServerEventArgs)

ParameterChanged(ByVal sender As Object, ByVal e As GH_ParamServerEventArgs)

The first two are only used for specific events (nicknames and sources respectively), the third one is always raised (even when one of the specific ones is raised first).

You can register handlers for these events in the component constructor if you want.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

A quick bug report:

Params.ParameterNickNameChanged does not fire unless I hit return after renaming the parameter.  If I simply click on the canvas and allow the pop-up to loose focus, the parameter nickname is changed, but the Params.ParameterNickNameChanged event does not fire.  I can send over sample code if you'd like.

Apologies if this is not the proper venue for bug reports.

-Kyle

Got it. Thanks.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi David.

Could you please share a bit of code demonstrating how to register handlers to this events in a component constructor??

I am trying to trigger some behavior when the nickname of a component changes, then I wrote this behavior on the VariableParameterMaintenance() method, but apparently it is not running when the Nickname is changed.

Thanks

Manuel

Hey David - would it be possible to provide some examples of complete component classes that effectively implement this behavior? I am struggling to properly implement it in my own code. I'm especially interested in the behavior of the Sort component, among others, which automatically adds corresponding output parameters when new input parameters are included. 

I copied the variable parameter logic of the Sort component into a separate text file (attached). Let me know if you need more.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

Thanks a bunch!! I will study this in detail.

After finished a standard component, I'm trying to make a simple Variable Component in C#, and can't figure out what to return in method:

CreateParameter().

In your code (VB) you return a new Param_GenericObject() but I can't find where the IGH_Params are in C# (neither in the sdk documentation).

I can't also find Param_Integer(), like you said in OP.

I know I'm missing something but I don't know what.

I think I managed to figure that out, and the component runs, but when I press '+' in Grasshopper nothing happens.

I'm attaching the code of the component. When I found a solution I'll post the corrected one in order to keep it as a simple c# example of this kind of components.

Hope someone can help :)

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service