Notifications
Clear all

[Closed] Prevent object cloning ?

Hi all,

                   I have a helper that attaches itself to an object. I don’t want to the user to be able to clone it for various reasons. Is there a way to achieve this ? 

                   Even by hooking on the preNodesCloned callback, there is no way to cancel the operation from what i’ve found


                                         Thanks !
3 Replies

you may use #postNodesCloned callback which returns 3 element array (first element is an array of the original nodes, the second element is an array of the cloned nodes, and the third element is a name value of #copy, #instance, or #reference, reflecting the clone type)

then if the returning 1st element is your helper object then immidiatly delete your cloned nodes from second element (which contains cloned nodes.)

I don’t think you can stop cloning after calling the #preNodescloned callback.

Hum, the copy still happens even if I do

fn test =
(
t = callbacks.notificationParam()
t[1] = #()
t[2] = #()
t[3] = #()
)

callbacks.addScript #postNodesCloned “test ()” id:#testHelper

Hi kittykun, bkravi idea is to allow cloning, because you cannot stop 3ds max to do it, but to set a callback that deletes the clones as soon as they’re created.
callbacks.notificationParam() returns an array of arrays you can use to find what nodes have been creted after a clone operation to delete them.

Following code creates a callback broadcasted after every clone operation that call a function which deletes every new object, as listed in second array from callbacks.notificationParam().

function preventCloning =
(
    local aClonedNodes = (callbacks.notificationParam())[2]
    for theNode in aClonedNodes do delete theNode
)

-- evaluate this to add the callback
callbacks.addScript #postNodesCloned "preventCloning()" id:#cbClonePreventer

-- evaluate this to remove the callback
callbacks.removeScripts id:#cbClonePreventer
  • Enrico