And elements to MultiListBox with pickbutton and button

And elements to MultiListBox with pickbutton and button

holycause
Contributor Contributor
345 Views
3 Replies
Message 1 of 4

And elements to MultiListBox with pickbutton and button

holycause
Contributor
Contributor
hi all,

I've a question about how to add some elements to a Multilistbox.

I ve an interface like the RBCollection one.

3 buttons, one Pick, one Add et and one Delete.

I had no problems to add some objects with the button Add.



obj = selectbyname title:"Select Bones" filter: bone_filt obj:true single:false
BonesIndex = obj
bonesindex as array
lbx01.items=for i in bonesindex collect i.name as string



but for the pickbutton, i can't find the answer... :S

BTW, how do we append an object to an array, it's alway ask me for a value
0 Likes
346 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Not sure what the problem is. The RBCollection uses a regular Pick button with a SINGLE pick. If you want to do multiple picks using the Pick button, you will have to use a regular button and in its hander you can call pickObjects count:#multiple to pick multiple objects. Right-clicking finishes the picking.

Your code above is rather funny - the result of selectByName single:false is ALWAYS an array. There is no obvious reason to assign obj to BonesIndex. The line 'bonesIndex as array' does nothing because AS ARRAY does not operate inline on the variable and the resulting array (which was an array even before that) is not assigned to anything. Similarly, 'i.name as string' is redundant because i.name is ALWAYS a string anyway.

Thus, you could say (WARNING, PARTIAL CODE, FILL IN THE BLANKS!)


(
local bonesIndex = #() --pre-declare the array somewhere in the beginning of the script

--...add your filter functions etc. here

rollout BonesRollout "Bones"
(
button btn_add "Add"
on btn_add pressed do
(
obj = selectByName title:"Select Bones" filter:bone_flt single:false --returns an array or undefined if canceled
if obj != undefined do --if not canceled
(
join bonesIndex obj --add all objects from obj to bonesIndex
lbx01.items = for i in bonesIndex collect i.name --collect the names to show
)--end if
)--end on


--For the pick button, you can append to the bonesIndex array
--(assuming it was pre-defined as an empty array when the script was started)

pickbutton pck_button "Pick" filter:bone_flt
on pck_button picked obj do
(
if isValidNode obj do --if a valid node was picked, equivalent to 'if obj != undefined do'...
(
append bonesIndex obj --append the single object to the existing array
lbx01.items = for i in bonesIndex collect i.name --update the list items
)--end if
)--end on

)--end rollout

--... add your dialog code here
)--end script


Note that your filter function could not only make sure the class of the object is a Bone, but also make sure that the object passed to it is NOT on the bonesIndex list yet. Otherwise, the above code would allow you to pick the same object several times, which is a bad idea. Thus, your filter function could look like

fn bone_flt  theObject = theObject.inode.boneEnable and findItem bonesIndex theObject == 0


Obviously, the function should be defined AFTER the bonesIndex array has been declared, either in the same or in a deeper scope.
0 Likes
Message 3 of 4

holycause
Contributor
Contributor
Hi Bobo
Thx for your answers.

I'm going to check all this.

🙂

BTW are you going to do a new cgworshop?
0 Likes
Message 4 of 4

Anonymous
Not applicable

BTW are you going to do a new cgworshop?


I don't think there is enough interest, but if they would ask me, I would probably do it.
0 Likes