Error Attempt to access deleted scene object Maxscript

Hello : I have item in array, and when max cannot find these items in scene it gives me error (error below). I want to create simple script that looks for these items in array and if it find it then delete it and it it doesn't then don't do anything. Or maybe Messaagebox "No items found in ALL_Call"

Global Lit = (Vraylight Name: "Test Light"
Global Bx = (box length:462.647 width:412.084 height:414.003 pos:[135.56,686.408,0])
Local ALL_Call = #(Lit, Bx)
	if ALL_Call.count == 2 do (delete ALL_Call)

Error : Runtime error: Attempt to access deleted scene object

Hope you guys can help.

Thanks

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

...

fn clearDeadNodes array = 
(
	if array.count != 0 do (for i = array.count to 1 by -1 where not isValidNode array[i] do deleteItem array i)
	array
)

Let say we have this case

--create 10 boxes and store these in array
boxArray = for i = 1 to 10 collect Box pos:[((i-1)*30),0,0]
--delete 3 boxes from scene
delete #($Box003,$Box005,$Box007)
-- still "boxArray" contains 10 items
-- now use my function to clean this array
clearDeadNodes boxArray

bga

xathletic01x's picture

Thanks! This is helpful.

Thanks! This is helpful.

Here is more for what i am looking for. Currently I have a btn with function that adds Light and Box.

Global Lit = (Vraylight Name: "Test Light"
Global Bx = (box length:462.647 width:412.084 height:414.003 pos:[135.56,686.408,0])

If i keep clicking the button it keeps adding new light and Box to the scene. I want to first tell it to delete if there is something in ALL_Call Array and then add the new one. But i get an Error "Attempting to access deleted scene object".

Local ALL_Call = #(Lit, Bx)
if ALL_Call.count != undefined do (delete ALL_Call)

If there is ALL_Call array it work perfectly because it first deletes the ALL_Call array and then adds new one. But for the first time when i click it it doesn't work.

Thank you for all the help!

Cheers

barigazy's picture

...

You are doing all wrong.
First of all why do U constantley declaring lit, bx and all_call variables?
Second ALL_Call.count can't be undefined but number. Anyway...
Use simply

ALL_Call = #(
   Vraylight name:"Test Light", \
   box length:462.647 width:412.084 height:414.003 pos:[135.56,686.408,0]
)
-- check if array nodes exists and delete these and clear ei. free array
if ALL_Call != 0 do (delete ALL_Call ; free ALL_Call)
 

bga

xathletic01x's picture

Thank you! I don't know why

Thank you! I don't know why I was over complicating this.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.