View Full Version : delete children with parent
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.
04-01-2008, 09:07 PM
If you are talking about the user deleting it while check out
Callbacks in the help file.. specifically #nodePreDelete
If the script it self is deleting the parent node then loop through the .children of an object and delete them, before deleting the parent.
if NodeToDelete.children !=0 then
for i=NodeToDelete.children.count to 1 by -1 do
Thanks, Keith. 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.
04-02-2008, 12:40 AM
In that case I would put a unique tag on the point object, via SetPropBuffer or SetAppData, and then have a persistant general callback on the delete function that checks for a child with that tag and delete it as well.
fn CheckToDelChild =
tnDeletedObj = callbacks.notificationParam()
if tnDeletedObj.childern.count > 0 then
-- loop through kids and check for attribute.
Callbacks.addscript #nodePreDelete "CheckToDelChild()" id:#CB_DelChildren
I wrote that with out max available.. but it should get you going in the right direction...
04-02-2008, 06:41 AM
Whenever I try to delete a whole rig using the preDelete call back, MAX crashes. Here's a test I just tried: (sorry it doesn't paste properly)
fn deleteRig =
theObj = callbacks.notificationParam()
if (isProperty theObj #rigInfo) == true do
if (isProperty theObj.rigInfo #character) == true do
theChar = theObj.rigInfo.character
delObjs = #()
for o in objects where (isProperty o #rigInfo) == true AND o != theObj do
if (isProperty o.rigInfo #character) == true do
if o.rigInfo.character == theChar do append delObjs o
if delObjs.count > 0 do
for o = delObjs.count to 1 by -1 do
if delObjs[o] != undefined do
if (isDeleted delObjs[o]) != true do
callBacks.addScript #nodePreDelete "deleteRig()" id:#preDelete
So it checks to see anything that belongs to that rig, appends the objects into an array then tries to delete it. I know the code is right, since I've been replacing 'delete delObjs[o]' with stuff like 'hide delObjs[o]' and it'll hide it no problem. I even did another quick test by getting rid of all this code and trying to delete $box01 from the scene, but it crashes too. So what gives??
04-02-2008, 02:08 PM
might just not be fond of you deleting nodes while in the process of deleting another node?
Try just storing the nodes to be deleted in an array in nodePreDelete, then actually delete them in nodePostDelete?
04-02-2008, 05:14 PM
I'm pretty sure I tried that a week ago. I'll give it another try just incase.
04-03-2008, 06:41 AM
So I tried deleting the nodes in a postDelete call back, and here's the results.
It does actually go through and delete everything, but there's a catch. As soon as you undo, it crashes. This is only the case if you try to delete more than one object of the rig, so you're still able to undo it if you only deleted one node. A clearUndoBuffer() can be used if a rig does get deleted, but then you would have to reopen the file. I also remembering trying a hold/fetch method, but it's very deadly with large scenes.
I appreciate the energy you've been putting into this, guys. In this particular case there would be only one child per object.
04-03-2008, 08:55 AM
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.
vBulletin v3.0.5, Copyright ©2000-2014, Jelsoft Enterprises Ltd.