[Closed] Populating a listbox using SelectByName
Hi everyone
I’m still a newbie to Maxscript, and have yet to master the way the different elements talk to each other. I am trying to create a script that takes a list of objects and then renders them one at a time, hiding the others. I have the logic of what I want to do, but the syntax is tripping me up. My first hurdle is populating the listbox with the array returned by SelectByName. The best I could come up with is:
on pickbtn pressed do
(
lbx1.items=selectByName title:"Choose Objects to Render" buttonText:"Select" showHidden:true
)
The problem seems to be that the selectByName returns more information about the selected objects than simply their names, and the coordinate data, etc doesn’t translate to strings that the list can use. I’m not terribly surprised that this didn’t work , but I have very little idea what I’m doing. Any suggestions?
listBox.items requires an array of strings.
local objNames = for each in selection do collect each.name
listBox.items = objNames
hanks for the reply, Eek. I’m still not able to apply it properly, though. How do I get it to read what selectByName is returning?
Easier way to try these small bits of code is by using the listener. Either run the line to see what comes out, or assign it to a variable and then inspect the variable.
Okay, so for the first of my three test objects it’s pulling in:
$Box:Box01 @ [1.078167,-0.000002,40.431267]
Do I just need “Box01?” How do I put that into an array? do I just parse it out and overwrite it? Will that work with the listbox, or does it need more of this info to know which objects to select?
SelectByName returns an array of nodes (not names). You need to convert the selected nodes to an array of names, see eek’s post.
-Eric
I’ve tried implementing Eek’s code, but I get a “After collect, expected <factor>” error. I get the feeling there’s some very basic step I’m missing.
Try Taking the do out of his code:
local objNames = for each in selection collect each.name
-Eric
Sorry, Pixel, missed your second. It runs now, at least. Only thing is, objNames isn’t coming through as an array. It’s just taking the name of the last object in the list.
edit:whoops, nevermind. It was just onlky selecting whatever objects I had selected in the viewport already. Come to think of it, that’s almost exactly what I wanted to do anyway! I just didn’t know about that “Selection” part in Eek’s code. I’ll just have the app pull the selection straight from the workspace instead oif a list
Don’t feel bad it was actually posted after yours, but some how ended up in front of it on the thread.
Only thing is, objNames isn’t coming through as an array. It’s just taking the name of the last object in the list.
That is correct, you will want to use selectByName, then run the objNames collection on that selection. Or you could try and run it using an #selectionSetChanged callback so that it updates as your selection changes.
-Eric