loop issues with object class

loop issues with object class

Anonymous
Not applicable
330 Views
3 Replies
Message 1 of 4

loop issues with object class

Anonymous
Not applicable
Hey, I try to do this little script to delete every lights and cameras depending of the choice of the user :


rollout test "B71 Creative"
(
checkbox del_lit "Lights"
checkbox del_cam "Cameras"
button export_obj "delete"

on export_obj pressed do
(
if del_lit.state == true do
(
for obj in lights do
(
delete obj
)
)

if del_cam.state == true do
(
for obj in cameras do
(
delete obj
)
)

)
)

createDialog test 100 70


But the probleme is when a I check one of the checkbox I receive this error :

-- Error occurred in export_obj.pressed(); filename: D:\script\; position: 259; line: 14
-- Frame:
>> MAXScript Rollout Handler Exception:
-- Unknown system exception <<


I can't find where the problem come from.

And the weird thing when I execute directly this line it's works :

for obj in lights do
(
delete obj
)
for obj in cameras do
(
delete obj
)


Thanks
0 Likes
331 Views
3 Replies
Replies (3)
Message 2 of 4

stigatle
Enthusiast
Enthusiast
creat a array to hold the objects, then delete the objects in the array helps.



rollout test "B71 Creative"
(
checkbox del_lit "Lights"
checkbox del_cam "Cameras"
button export_obj "delete"

on export_obj pressed do
(
tempArray = #()
if del_lit.state == true do
(
for obj in lights do
(

append tempArray obj
)
)

if del_cam.state == true do
(
for obj in cameras do
(

append tempArray obj
)
)
delete tempArray
)
)

createDialog test 100 70
0 Likes
Message 3 of 4

Anonymous
Not applicable
Thanks very much It's work now
0 Likes
Message 4 of 4

Steve_Curley
Mentor
Mentor
Yes, but as both Lights and Cameras are built-in collections,

if del_lit.checked then
delete lights
if del_cam.checked then
delete lights

The point is, though, well made - collections are a kind of array, but they're likely to get modified in the background, so you're hitting an "empty" array location. All to do with the initial state of the array at the start of the looping procedure and it being changed in each iteration of the loop.
Another way to do this is to treat the collection as an array and work DOWN it, not UP.

if del_lit.checked then
for o = lights.count to 1 by -1 do
delete lights

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes