algorithmic modeling for Rhino
Ok! Let' see if I'm missing something obvious here.
I have these scripts where I used to control the inputs of my components (primarily ones that had to do with case subroutines)so I don't have to retype everything from scratch. So when a value list component is connected to an input , the value items are automatically generated. this code (see attached) worked for me in 0.9.0014 but now is not (0.9.0056).
Specifically the value list component outputs the correct value when changing this from the drop-down list, but the preview of the component itself doesn't seem to update.
I tried to redraw the canvas but again it doesn't seem to comply nor I think this is the appropriate solution.
Can anyone replicate this?
Best
M.
Tags:
Just popping this up to the top of the discussion list. In case someone missed it :)
Hi Marios,
I think you must re-set the selected item of the list , but doing this inside your script would cause a recursive loop.
Here's another approach that works "only" when list mode is set to dropdown.
private void RunScript(List<int> Distribution, ref object A)
{
foreach (IGH_Param source in Component.Params.Input[0].Sources)
{
if (source is Grasshopper.Kernel.Special.GH_ValueList)
{
Grasshopper.Kernel.Special.GH_ValueList nvlist
= source as Grasshopper.Kernel.Special.GH_ValueList;
Grasshopper.Kernel.Special.GH_ValueListItem selectedItem
= nvlist.FirstSelectedItem;
List<Grasshopper.Kernel.Special.GH_ValueListItem> _list =
RefList.FindAll(new Predicate<Grasshopper.Kernel.Special.GH_ValueListItem>
((x) => {return selectedItem.Name != x.Name;}));
nvlist.ListItems.Clear();
nvlist.NickName = "Distribution";
nvlist.ListItems.AddRange(_list);
if(_list.Count < RefList.Count)
{
nvlist.ListItems.Insert(0,
new Grasshopper.Kernel.Special.GH_ValueListItem(selectedItem.Name,
selectedItem.Expression));
}
}
A = Distribution;
}
}
public List<Grasshopper.Kernel.Special.GH_ValueListItem> RefList
= new List<Grasshopper.Kernel.Special.GH_ValueListItem>();
public override void BeforeRunScript()
{
RefList.Clear();
RefList.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Linear", "0"));
RefList.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Parabolic", "1"));
RefList.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Sinodial", "2"));
RefList.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Noise", "3"));
RefList.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("SinC", "4"));
RefList.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Hyperbolic", "5"));
RefList.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("SqrtRoot", "6"));
RefList.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Power^3", "7"));
RefList.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("RandomRadial", "8"));
RefList.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Crossines", "9"));
RefList.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Cosine^2", "10"));
}
You also have to press F5 after connecting the list to the script comp.
Hi,
Thank you for your time in answering this.
My question was originally meant for the replication of the issue in between the two different versions. In the meanwhile I am also looking into a solution with the New BeforeRunScript (old DAiteration) but I have still no luck in finding.
In the attached you use a nice trick which overrides the value list's component default behaviour by constantly changing the first value. My problem mainly lies with the non refresh(the f5 you mention) of the valuelist comp and when you connect multiple inputs in your case as well the components attributes are flying all over the canvas. Mainly sticking to the start of the working canvas. So again this is not a proper solution rather than a clever hack.
Once again thank you so much for your help.
By the way did you replicate the working definition for 090014?
I guess I have to wait for an answer from David on that..
Best,
M.
Hi Marios,
I tried both files with v.0056 and I have the same issue. I think that clearing and redefining the list sets the first item of the list as the selected item. I noticed that both of the attached scripts 0056&0014 return to linear distribution (0 as result) after modifying the list and then pressing F5 (at least on my PC with v0056 installed). I am not sure if it's a display issue or the way GH_ValueList works after modifying ListItems. On the other hand, finding and then re-setting the selected item will expire sources' solution and will cause recursion so you must use a condition(as you describe next) inside your script to avoid that.
I hope someone else can give further info.
It seems to be a display issue at least when the values are defined in a scripted manner.
Well, thanks again for your input..
M.
Just in case anyone follows this discussion in the future I managed to resolve this issue by adding a conditional according to the length of the input sources.
So when a new value list is connected this and only this one gets updated to the preferable valuelist items.
That kept the other inputs intact and performing as expected, no need to be inside the beforeRunscript sub, can be inside the solverinstance as well.
Still haven't found a way to refresh the component itself though OnDisplayExpired() doesn't seem to do the job in this case.
Best,
M.
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