Grasshopper

algorithmic modeling for Rhino

Hello, everyone, i am a fresh here, who was working on c# programming. What I want to know is how to change the slider value in a GH component progammed by myself. I saw David said GH_RhinoScriptInterface could do this. But it didn't work to me. Does anyone know how to deal with this?
Thank u so much.
My codes are following.

Views: 1430

Attachments:

Replies to This Discussion

I have used slider.Slider.Value to set the value. I think there are two disadvantages. First, once the value is changed ,the slider could not be dragged anymore. Second, to each "slider", I need to use a "expireSolution" method, and this method would spend a lot of time if I program an algorithm (like GA or something). I remembered what David said in a topic that  "setSliderValue" in GH_RhinoScriptInterface class could "runsolver()" after all of sliders were reset. 

A part of my codes are following. Does anyone know how to use  "setSliderValue" in GH_RhinoScriptInterface in GH component programming.

IGH_Param tempPara = this.Params.Input[0].Sources[0];
if (tempPara.GetType() == typeof(Grasshopper.Kernel.Special.GH_NumberSlider))
{
slider = tempPara as Grasshopper.Kernel.Special.GH_NumberSlider;
decimal max = slider.Slider.Maximum;
decimal min = slider.Slider.Minimum;
//change the value of slider
tempfile = this.OnPingDocument();
if (tempfile == null) { return ; }
//myInterface.OpenDocument(this.OnPingDocument().ToString() + ".gh");
//myInterface.SetSliderValue(slider.InstanceGuid.ToString(), 8);
DA.SetData(0, max);
DA.SetData(1, min);
slider.Slider.Value = 8;
slider.ExpireSolution(true);
//tempfile.NewSolution(true);
//MessageBox.Show(slider.InstanceGuid.ToString());
}

uh.... I achieved my goal by the method "ExpireSolution" of NumberSlider. And I used a thick to solve the undraggable phenomen caused by constant recalculation. A "check" is used to judge. But another disadvantage still exists. The method "ExpireSolution" of NumberSlider would slow down the calculation. I tried to used the method "ExpireSolution" and "NewSolution"of GH_Document like following, but failed.

.......change slider values

GH_Document tempFile = this.OnPingDocument();

tempFile.ExpireSoluti();// or tempFile.NewSolution(true);
.............

BTW, I remembered David said in a topic that Runslover() and setSliderValue could be used to avoid unnecessary calculation caused by one slider (image that I have a lot of sliders) . I am very interested in how to use that. I tried, but still failed too.

I don't know why these methods don't work. If you know the reason why, please tell me. I would be very appreciate you for this. An example would be best. ^_^

Thank you.

I used Double click to active the component. You could change the SolveInstance(IGH_DataAccess DA) method to test other setting slider value methods.

Attachments:

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