PDA

View Full Version : listbox items access


loran
10-03-2009, 06:09 PM
hey all.
I want to access individual items from a listbox so they do a specific operation one by one.

check out my test

"for o in fragments.items do" seems to be wrong :/


rollout booM "b o o M "
(
group "Fragments"
(
Button addsel " add selected"
Button resetlist " reset the list"
MultiListBox fragments "Fragments" --items:(for o in selection collect o.name)
)
Button test " Test"
on resetlist pressed do
(fragments.items = #())

on addsel pressed do
(fragments.items = #()
for obj in selection do
(
fragments.items = append(fragments.items) (obj.name)
)
)
on test pressed do
(
(for o in fragments.items do
(rotate o (eulerangles (random 2 -2) (random 2 -2) (random 2 -2)))
)
))

createDialog booM

SoLiTuDe
10-03-2009, 07:46 PM
hey all.
I want to access individual items from a listbox so they do a specific operation one by one.

check out my test

"for o in fragments.items do" seems to be wrong :/

Here's how I would do it... keep in mind I didn't test this. Just going on the fly here.


rollout booM "b o o M "
(

group "Fragments"
(
Button addsel " add selected"
Button resetlist " reset the list"
MultiListBox fragments "Fragments" --items:(for o in selection collect o.name)
)

Button test " Test"

local fragobjs = #()

on booM open do --sets stuff when the rollout opens
(
fragobjs = selection as array
fragments.items = (for o in fragobjs collect o.name)
)

on resetlist pressed do
(fragments.items = #())

on addsel pressed do --reset list basically
(
fragobjs = selection as array
fragments.items = (for o in fragobjs collect o.name)
)

on test pressed do
(
for o in fragobjs do --fragments.items is just an array of strings, not objects!
(rotate o (eulerangles (random 2 -2) (random 2 -2) (random 2 -2)))
)

)

createDialog booM

MarcoBrunetta
10-03-2009, 10:14 PM
"for o in fragments.items do" seems to be wrong :/

It is, your problem is that the items array in the multilistbox does not hold the actual scene items but an array of string names (the one you created in "for o in selection collect o.name"). When you try to rotate the string the script obviously throws an error. The most direct solution is to have a local variable in the rollout that holds the items themselves, that can be referenced using the multilistbox; which is basically what SoLiTuDe coded up for you.

CGTalk Moderation
10-03-2009, 10:14 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.