Grasshopper

algorithmic modeling for Rhino

HI all!, i was write this in a grasshopper script to change the slider value

var input = Component.Params.Input[0].Sources[0];
var slider = (Grasshopper.Kernel.Special.GH_NumberSlider) input;

if(slider != null)
{
slider.SetSliderValue((decimal) y);
}

but i want to put it in a Plug-In but i can´t..., i written

protected override void SolveInstance(IGH_DataAccess DA)
{
Grasshopper.Kernel.Special.GH_NumberSlider input = new Grasshopper.Kernel.Special.GH_NumberSlider();
decimal num=0;
DA.GetData(0, ref input);
DA.GetData(1, ref num);
var slider = (Grasshopper.Kernel.Special.GH_NumberSlider)input;
if (slider != null)
{
slider.SetSliderValue((decimal) num);
DA.GetData(0, ref slider);
}
}

i tried to put "DA.SetData (0, slider);" but i can´t change the slider value

thanks all

Views: 1184

Replies to This Discussion

You already got it right, Just need to put the code inside the SolveInstance method:

using Grasshopper.Kernel.Special;

protected override void SolveInstance(IGH_DataAccess DA)

{
    GH_Slider ghSlider = Params.Input[0].Sources[0] as GH_Slider;

    ghSlider.SetSliderValue(someNumber);
}

Notice how you can access Params directly without having to say Component.Params, as when you are writing code inside the SolveInstance method you are already inside the Component object and hence can access its Params property directly. While the code you wrote in the C# Script Code Editor is not in the actual Component object, and hence you need to prefix Params with Component in that case.

Hi Long Nguyen!, thansk for your reply. i have a doubt, in the SolveInstance it's ok i understand this. but in "RegisterInputParams(GH_InputParamManager pManager)" i wrote  "pManager.AddNumberParameter("number", "num", "desc", GH_ParamAccess.item);" and "pManager.AddParameter(param);". with the firs option  sayme:"Solution exception: Object reference not set to an instance of an object", and the second option don´t load the comand. why?

Can you share the file?

yes of course. in te .rar file i put a gh with an example in C# script code editor and the proyect 

Attachments:
Hi Long Nguyen, recently  can fix the mistake.  reemplaze the line  "GH_Slider ghSlider = Params.Input[0].Sources[0] as GH_Slider;" for "GH_NumberSlider ghSlider = Params.Input[0].Sources[0] as GH_NumberSlider;" now it's works!, thanks very much for your help.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service