[Closed] When object deleted, delete children. Huh?
Aw man, you got my hopes up. I was hoping I could see how they went about achieving that effect, but they’re dll files ><
The source code for Max9 and Max2009 versions is included with the Max 8-2009 plugin. Here:
[ http://www.maxplugins.de/max8.php?search=delete protection&sort=Author]( http://www.maxplugins.de/max8.php?search=delete protection&sort=Author)
Hm. Unfortunately, even if there were something in there that could help me, I wouldn’t know how to use it. But thanks anyway!
So the Delete protection plugin does not work to protect your rig components from deletion? You tried it?
Protecting rig components from deletion is not what I am trying to do.
Ok... so if I understand correctly, you want to delete a set of nodes, if the user deletes one of the nodes in this set?
Then I think the Character Assembly can work for you... (you will only use this as an assembly to collect your nodes-- you can hide it, set icon size to 1, make it unselectable, whatever...)
[ol]
[li]Select all of the nodes in your scene you want to be under this “Delete All” operation, and then create a character assembly… this will add all these nodes as members to the Character Assembly.[/li][li]Create your script (callback or whatever…) to check if a deleted node is a member of this assembly. Maxscript command is: <node>.assemblyMember (will return true or false).[/li][li]If #2 is true, use Maxscript command: <character_assembly>.assemblyHeadOpen = false. This will LOCK the character assembly.[/li][li]Finally delete the character assembly using: delete <character_assembly>[/li][li]Everything is now deleted! Undo (max undo) and redo (max redo) to your heart’s content.[/li][/ol]
:hmm:
Not an elegant solution, but it should work… if this is all you’re trying to do (as I understand it).
Still haven’t looked at the character assembly stuff, but following up on this post:
http://forums.cgsociety.org/showpost.php?p=7680108&postcount=111
callbacks.removeScripts id:#undo
fn undo_Callback =
(
if (callbacks.notificationParam()) == "Post Delete" do with undo off max undo
)
callbacks.addScript #sceneUndo "undo_Callback()" id:#undo
Performs the extra undo when necessary. Unfortunately, using this also breaks the redo solution I had in place, and trying to use a similar solution for redo messes with object selections during scene redo in other situations.
A little more work and I’ve got this:
try
(
PostDelete_NodeEventCallback.enabled = off
PostDelete_NodeEventCallback = undefined
)
catch()
callbacks.removescripts id:#delete_same_class
callbacks.removeScripts id:#undo
callbacks.removeScripts id:#redo
global NodesForDeletion = #()
global objCount = objects.count
fn PostDelete_Callback event handles =
(
nodes = for node in NodesForDeletion where isvalidnode node collect node
NodesForDeletion = #()
if nodes.count > 0 do undo "Post Delete" on delete nodes
redrawViews()
)
fn preDeleteWholeClass =
(
if not PostDelete_NodeEventCallback.enabled do
NodesForDeletion = #()
if not theHold.Redoing() do
(
node = callbacks.notificationParam()
if isvalidnode node do
(
join NodesForDeletion (for n in (getclassinstances (classof node) astrackviewpick:on) where isvalidnode n.client and n != n.client collect n.client)
)
)
)
fn undo_Callback =
(
if (callbacks.notificationParam()) == "Post Delete" do with undo off (max undo)
)
fn redo_Callback =
(
if objects.count != objCount and (callbacks.notificationParam()) == "Create Selection Set" do
(
max redo
objCount = objects.count
)
)
PostDelete_NodeEventCallback = NodeEventCallback deleted:(with undo on (PostDelete_Callback))
callbacks.addscript #nodePreDelete "preDeleteWholeClass()" id:#delete_same_class
callbacks.addScript #sceneUndo "undo_Callback()" id:#undo
callbacks.addScript #sceneRedo "redo_Callback()" id:#redo
delete objects
with redraw off
(
for k=0 to 4 do box pos:[k*30,0,0] width:20 length:20 height:20
for k=0 to 4 do cylinder pos:[k*30,40,0] radius:10
for k=0 to 4 do sphere pos:[k*30,80,0] radius:10
)
There is one behavior I’d like to get rid of: If I copy one of the objects, or create a new object that is the same class, and then perform an undo on that create/copy action, it deletes all objects of that class.
This is not a result of any of the changes I have made, as it appears to take place even using the code from http://forums.cgsociety.org/showpost.php?p=7679251&postcount=106