Linking elements of an existing GH file with an existing Visual Studio C# Solution

visualstudio
ui
grasshopper

#1

Hello All,

I am quite new to Grasshopper and newer to Visual Studio and I think the problem I am facing is quite rudimentary but I would really appreciate any help.

I have developed a GH (Rhino WIP) code that builds a 3D model of an octagonal prism using parametric dimensions and later unrolls it to reveal the shape of individual faces of the model. I have also developed an Visual Studio C# solution as the GUI for this GH code.
So, I would please like to know how to link the Sliders (WPF Controls) in VS C# to the Numbers Sliders in GH in order to facilitate the dimensional inputs for the model and how to extract the resultant projections of the model from the Rhino viewport into a window in the VS C# code.

I hope my questions are clear.

Thanks and Cheers!
Aravind K S


(Dale Fugier) #2

@Aravind_K_S, I’ve moved your question to the “Grasshopper Developer” category.


#3

@dale Thank you very much.


(David Rutten) #4

I have no experience with WPF, but I imagine you have events that are raised whenever a WPF slider changes. You must handle these events and from the handler change the slider object in Grasshopper.

Slider are of the type Grasshopper.Kernel.Special.GH_NumberSlider and there’s various ways in which you can set their value. I recommend using the TickCount and TickValue properties. TickCount tells you how many distinct states a slider has, and TickValue is basically the index of the appropriate state. However if you want to assign actual numeric values that’s possible as well via SetSliderValue(decimal) method.

Using these methods, the slider (and all objects that depend on it) will expire, however they will not automatically recalculate. When you are finished modifying all the sliders you want to modify, you will have to trigger a new solution. Probably best to do so by calling NewSolution() or ScheduleSolution() on the GH_Document which contains the sliders.