algorithmic modeling for Rhino
David & All,
I'm trying to bind the value of a text element (in either a wpf form or a windows form that I'm launching from my compiled c# component) to the value of an upstream parameter in grasshopper.
Does anyone have an example describing how to reliably bind to an upstream parameter?
Thank you,
Image is attached !
Tags:
Alright,
First of all your form must have a public function that allows changing the label - SetLabel(double slider_val)
Also, your component must have a pointer to the active WinForm/WPF instance.
I've attached an example of a GH component that i've written that does exactly what you need:
1. Loads a form when it's added to the GH window, the form contains a label
2. Registers to the input parameter (in my example it only supports the NumberSlider parameter)
3. Changes the form label to the current slider value
4. Updates the label every time the slider's value is changed
5. Supports various cases - disconnect/connect of multiple sliders, removed/added to document, etc.
Take the time to read my code and learn from it, i have a feeling / hoping you're not the copy-paste type
Thank you so much Hen,
I have had a quick look at the code u attached. so many new for me such as the override methods addedtodocument, removedfromdocuments I have never utilized them.
I have tried different approaches and made million mistakes last three days. I wouldn't figure it out myself.
I will look into detail first thing in the morning. Thank you
Hi Hen,
The code was very helpful, I have learned a bunch.
Especially I tried to understand about the your choice of the event handler that is registered to IGH_Param (slider Param) object. I debug the code, and I was wondering why the dragging(or changing the value of) the slider triggers the SolutionExpired event? Why registering ObjectChanged or AttributeChanged eventhandlers not preferred ? I kind of figured it out: Objectchanged is about the to IGH_param members (properties) and the attributes are about the component attributes (size color etc)! if I am not wrong. Number slider is solving a new solution each time when drag.
Thanks again, I will explore GH events a bit more.
Hi,
SolutionExpired occurs for multiple reasons such as compoment movement/drag and also whenever one of it's values is changed.
The other events are for view port display calls, attributes changed - they're irrelevant for our task.
The slider param does not supply an event that triggers ONLY on value changes, if it had it would've been great but it doesn't so i had to find the best possible option - SolutionExpired.
And yes the function will be called when the slider is dragged and even if it's values isn't changed but you can add a logical condition when the SolutionExpired delegate is called inside your component and save the previous value of the slider and check if the value did change and if it did - change the form's label. that is if you don't want unnecessary function calls.
It's not that big a deal - and i believe you can handle the false triggers when the slider is being dragged along the GH canvas.
Do you have anymore questions about the code or in general? did you fully understand it?
no, not at this moment. yes I fully understood.
Thank you so much for valuable information
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by