Grasshopper

algorithmic modeling for Rhino

Hi All,

 

I was wondering (and couldn't really find a direct answer on the forum) whether it is possible to dynamically control the number of input parameters. Let's say if a small component with only one input, receives and input, a second input appears, and so on...

I would like to develop a component which has this functionality (mainly from a user friendliness perspective).

Thanks for your suggestions.

 

Joost

Views: 1653

Replies to This Discussion

Hi Joost,

 

it is possible to modify the number of parameters (input and output), as long as you're not modifying during a solution. You'll also have to make sure that you (de)serialize correctly. It's not exactly trivial stuff.

 

I attached a crude attempt. It won't copy/paste/save/open correctly. If this is roughly what you're looking for I'll add that code as well.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

...aaaaand the attachment.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

 

Attachments:

Hi David,

 

this seems to be exactly what I mean. I'll try to implement it using C#, see how far I get.

 

Thanks!

The open-source GhPython component also contains a IGH_VarParamComponent implementation in C#. You can read it and download if from here.

I hope this might also help,

- Giulio
______________
giulio@mcneel.com
McNeel Europe

I'm ditching IGH_VarParamComponent as we speak. It will remain in the SDK but it will be marked Obsolete. I'm exposing a new interface (IGH_VariableParameterComponent, confusing? how so?) that is supposed to provide a much better UI as well as an easier implementation.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

That's fine. I'll update GhPython when IGH_VariableParameterComponent is generally available. Or if you feel like trying the new interface out, go ahead :)

- Giulio
_______________
giulio@mcneel.com
McNeel Europe

I'm struggling with the evenhandlers (AddHandler in vb). Could you have a look at the uploaded code? And perhaps add some instructions on how to deserialize correctly.

 

Thanks.

 

Joost

Attachments:

I havn't recreated the solution, but if the signature of Param_ObjectChanged is correct, which seems like, this is what line 61 can look like:

pManager[0].ObjectChanged += Param_ObjectChanged;

You can reference methods with their name and without parentheses, or build the delegate with an explicit constructor but still without parentheses.

The longer syntax for line line 120 is then:

param.ObjectChanged += new IGH_DocumentObject.ObjectChangedEventHandler
(Param_ObjectChanged);

that can also be:

param.ObjectChanged += Param_ObjectChanged;

- Giulio
_______________
giulio@mcneel.com
McNeel Europe

Great, thanks! It works...

Do you think it's also possible to make it work the other way around, as in: removal of a parameter results in less input parameters?

 

Probably David can help, I think that the code might need some finishing. He said above: "If this is roughly what you're looking for I'll add that code as well".

Thanks,

- Giulio
_______________
giulio@mcneel.com
McNeel Europe

Hello,

 

I just wrote the code to dynamically remove a parameter (when the wire is disconnected) and it works fine, however, I am not quite sure how to delete the Handler :( 

 

So if I want to un-register the input parameter at 'index', does the following code remove that handler?

 

Params.Input[index].ObjectChanged -= InputParam_ObjectChanged; //this is the name of my handler

 

Below is the screenshot of the handler definition, the first half is pretty much what David wrote, below that is my code (click to enlarge)!

Hi David,

 

I have  a follow-up question which holds relation to this thread. So far I managed to create a component which dynamically expands or shrinks according to the amount of inputparameters.

Now, the follow-up question:

Is it possible to create a component with one initial parameter (say an integer), and set the extra input parameters according to this initial input?

 

The answer might be contained in your previous reply:

'it is possible to modify the number of parameters (input and output), as long as you're not modifying during a solution.'

But I'm not sure.

 

Thanks.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service