delete children with object

delete children with object

bhnh
Advocate Advocate
1,113 Views
6 Replies
Message 1 of 7

delete children with object

bhnh
Advocate
Advocate
In a float script I'd like to stipulate that if an object is deleted its children will be deleted as well. I'm stuck as to how to put it together... can anyone point me in the right direction? Many thanks.
0 Likes
1,114 Views
6 Replies
Replies (6)
Message 2 of 7

Steve_Curley
Mentor
Mentor
(

fn DeleteThis Obj =
(
if Obj.Children.count != 0 do
(
for K = Obj.Children.count to 1 by -1 do
DeleteThis Obj.Children
)
Delete Obj
)

DeleteThis $Box02 -- your object goes here

)


Gotta love recursive functions 😄

Note that this will not only kill the kids, it will also cause the early demise of the grandkids, the great grandkids and so on 🙂

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

0 Likes
Message 3 of 7

Anonymous
Not applicable
Hey Bruce...

just a heads up...you may want to consider using isvalidnode as a test if you are
deleting things via scripts. This will trap the trying to reference a deleted object
error. I'm afraid to ask what you would be doing deleting objects via an animation
controller. Generally, script controllers punish you by spawning lots of fix me chat
windows.
0 Likes
Message 4 of 7

Steve_Curley
Mentor
Mentor
Quick question. What would happen if you deleted an object from within a script which was part of that same object?

Apart from world war 3, BSODs and a quick exit to the desktop ofc 😉

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

0 Likes
Message 5 of 7

bhnh
Advocate
Advocate
You da man, Steve. :coolgrin:

@SC - what I've got is button that creates a box and a hidden point acting as a script holder that's parented to to the box. The idea is that the user won't be aware that the point is even there. If a box or boxes created by the button are deleted, I don't want the orphaned points hanging around.
0 Likes
Message 6 of 7

Anonymous
Not applicable
You might look into a callback as an alternative. There is an example
that is similar to what you are trying to do.

Max may not crash outright...but for each script controller max pops up the
script editor window. I have a face rig setup that has 40 or so controllers,
when someone who doesn't have my lerp function installed loads one
of the face rig files they get dialog spam.
0 Likes
Message 7 of 7

Steve_Curley
Mentor
Mentor
We obviously need an anti-dialog-spam filter 😛

At least it doesn't crash horribly.

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

0 Likes