XM Magdalena 3D print, GGeorgy (3D)
LC #42 Pipers Alley

View Full Version : Remove multilisbox selections

06-06-2008, 11:34 AM

I was wondering how my multilistbox selection. I'm using a button to do it.

I tried this:

deleteItem pNamearr ParentRollout.parentLbx.selection
ParentRollout.parentLbx.items = pNamearr

but i've got this error message:

MAXScript Rollout Handler Exception: -- Runtime error: array index must be positive number, got: #{5..11}

I tried this:

res = parentRollout.parentLbx.selection
for elem in res do
deleteItem pNamearr elem

but got this error:

>> MAXScript Rollout Handler Exception: -- Runtime error: array index out of bounds: 7 <<

now i'm lost :S

btw, how is it possible to put 2 fn in one?

i would like to use this 2 fonctions for a SelectByName filter:

fn ShapeSelectionLimit = shape_filt obj = isKindOf obj shape
fn filterUnique obj = findItem pNameArr obj.name == 0

06-06-2008, 12:08 PM
btw, how is it possible to put 2 fn in one?

I odn't think so, I tried the exact same thing the other day, and only one function was created. Easiest thinfg is to use 2 intermediate functions that call the main function.

For multilistboxes, the selection is a bit-array (NOT an index) in your case elements 5 to 11 are selected, so you would need to loop BACKWARDS through your array (from 11 to 5), calling deleteItem on it, then re-apply the items to the multilistbox.

If you don't go backwards, you count up from 5 to 11, but by the time you're halfway through deleting items (5, 6, 7, 8), you've already shortened the array below, say 8, so iterations 8 and above would fail, as you can't delete element 8, 9, 10, or 11 as the array is already too short.

Make sense?


06-11-2008, 01:52 PM
thx for your answer.

i m going to try it ;)

06-23-2008, 03:28 PM
I'm back again :P
I just continue my script and fund the answer about how to use 2 functions in 1

the original functions are:

fn PathfilterUnique obj = findItem PathNameArr obj.name == 0
fn ShapeSelectionLimit = shape_filt obj = isKindOf obj shape

and the answer is:

fn PathfilterUnique obj = ((findItem PathNameArr obj.name == 0) and ( isKindOf obj shape))

about the question; how to delete my Mlb selection; a friend fund this;

on parentDelBtn pressed do
while index > 0 do
temp = parentRollout.parentLbx.items
if parentRollout.parentLbx.selection[index] == true then
deleteItem temp index
parentRollout.parentLbx.items = temp


I hope it can help some people.

06-23-2008, 04:04 PM
Here's another way that's a little more optimized

-- list is the multiListBox

on bt_remove pressed do
items = (list.items as array)
for o = (list.items as array).count to 1 by -1 where ( findItem (list.selection as array) o ) != 0 do deleteItem items o
list.items = items

06-23-2008, 04:29 PM
thx for your answer Jason ^^

06-23-2008, 05:21 PM
Sorry for replying way after the fact :)

06-23-2008, 05:39 PM
Or even shorter ;)
list.items = for i = 1 to list.items.count where not list.selection[i] collect list.items[i]

06-23-2008, 05:57 PM
bedankt Martijn

06-23-2008, 06:15 PM
Oh snapple!

06-23-2008, 06:59 PM
Oh snapple!

list.items = for i in (-list.selection) collect list.items[i]


06-23-2008, 07:13 PM

echt bedankt

06-23-2008, 08:10 PM
Haha nice one Richard. Should have thought of that
Idea for the next mxs challenge? Write a script that does ... with as little code as possible

06-23-2008, 08:13 PM
Oh snapple!
Google > define:snapple > Soft drinks ??? :D

06-23-2008, 09:18 PM
I've been actually in a Fanta mood lately, but saying 'Oh Fanta' doesn't roll off the toungue!

CGTalk Moderation
06-23-2008, 09:18 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.