Here you go:
www.lumonix.net/DeleteProtection_MXS.zip
The zip contains a text file that explains how to use it in Maxscript, it should be pretty straight forward.
The zip contains compiled plugins for 3dsmax 8, 9, 2008 and 2009.
The source code is also in the zip, in case you want to compile it in the future.
Take care,
brilliant – this is a helpful thread. Kees – in your help file you mention about going through the selected objects backwards when deleting, Is there a reason for doing this via script?
It depends on how you walk the array.
If you do:
for i=1 to selection.count do
(
delete selection[i]
)
then your ‘selection.count’ keeps on shrinking and you’ll eventually get an error.
By deleting backwards you’ll avoid the problem.
If you loop like so:
for each in selection do
(
)
then its fine too.
It was just a small reminder I put in there too avoid getting emails saying ‘it doesn’t work’
Take care,
Thanks Kees. It works great. The only thing I would mention for others using this is that it has the same issue I found with the callbacks, in that if you try to undo the delete Max will crash (you have to hit undo a few times before it will crash). So I add a query box telling the user that this an undoable operation and make sure they really want to do it, and then I add a ‘clearUndoBuffer()’ command at the end to make sure they really can’t undo it and crash the program.
James,
You delete the object through maxscript, then undo and then it crashes?
I’m not sure that the two are related in that case…
All the MXS extension does is prevent the delete message from going any further in max.
You may want to look in ‘theHold’ options in maxscript to better control the undo process.
I’ve not had a problem myself when deleting objects this way, though in my case the deleting happened in c++.
The process being the same though:
- Catch the delete button being pressed via the MXS extension
- open undo buffer
- delete objects (via MXS or SDK)
- close undo buffer.
If that doesn’t work, I wouldn’t mind seeing a repro case of it to see why.
The repro case if very easy. Run the following code, delete the teapot using the Delete button, hold down Ctrl-Z until Max crashes. It happens in both 8, 2008 and 2009, that I’ve tested.
global deleteProtectFunc
function deleteProtectFunc = (delete selection)
setDeleteProtection true
t = teapot()
select t
Hi James,
The code you send does not crash for me.
But no matter, you are not using the undo buffer:
global deleteProtectFunc
function deleteProtectFunc = (undo "delete" on (delete selection))
setDeleteProtection true
t = teapot size:4
select t