View Full Version : Collapsing the stack

3rd Dimentia
12 December 2007, 12:45 PM
Is there another way to collapse a stack including WSM's with maxscript? I can't use snapshot.


12 December 2007, 05:06 PM
I don't believe so.
Why can't you use the snapshot command?

newObj = snapshot oldObj =
delete oldObj

12 December 2007, 09:44 PM
collapsing the modifier stack?

select an object:

maxOps.CollapseNodeTo $ 1 true

Is that what you need?

3rd Dimentia
12 December 2007, 01:09 AM
Adam:Over the years I've had many editable polys that have become corrupt for whatever reason. HERE ( is an example of a mesh that snapshot doesn't seem to work very well on. The script I'm working on rebuilds editable polys with the option to rebuild smooth groups, material ID's, any UV's that are in use and vertex colours along with reseting transforms and copying materials. If the object has modifiers on it, I want the script to make a copy, collapse it and convert it to an editable poly if it's not already. Then do the poly rebuild based on this object.

Moondoggie:I tried CollapseNodeTo the other day and it didn't seem to want to collapse WSM's. If I have a mesh that has a bend spacewarp applied the command works when I use it in the listener, but when it's part of my script it seems to ignore the WSM.
Oh hang on a sec. I just figured out that it's NOT the collapse line that's doing that, it's when I copy the object before collapsing it. It doesn't take the WSM's across to the copy before it's collapsed. I'm looking into using clonenodes to do the copy.

Thanks for your suggestions guys,



12 December 2007, 03:09 AM
Always welcome

3rd Dimentia
12 December 2007, 04:49 AM
Oh this is driving me insane...... I'm now trying to use maxops.clonenodes to make a copy cause the normal copy function did not copy WSM's. Then I'm collapsing it with maxOps.CollapseNodeTo. But I just can't get these functions to play nice.
if I run the following code on an object that has OSM's and WSM's it will clone the object correctly with an offset of 100 in x. But it will not collapse anything.
BUT if I run the last line of code afterwards in another script or in the listener, it works how I thought it should to start with.

maxops.clonenodes $ offset:[100,0,0] newNodes:&test
b = test[1]
select b
maxOps.CollapseNodeTo $ 1 true

If I use the CollapseNode function in the script instead of CollapseNodeTo it collapses everything besides the WSM's.

Can anyone point me in the right direction? I'm running in circles at the moment.

I know I don't need to do the "select" line in the code, but that was just to help me when I was trying to run the collapse line in the listener after the fact. The last line of the code works the same whether I run it on b directly, or select b and run it on $

12 December 2007, 12:36 PM
Hey, I can't try this myself right now but you might be able to use:
convertTo $ Editable_Poly

3rd Dimentia
12 December 2007, 03:08 PM
Hi Rivendale, thanks for the suggestion but sadly doing this still doesn't take WSM's into consideration. It collapses everything except WSM's which it just leaves on the top of the stack as it was.

12 December 2007, 06:03 PM
If I get this right you justwant to collapse everything to a poly right?
I've created a box, applied a bend modifier and collapsed it through these methods which all worked:

converttopoly $
convertto $ editable_poly
maxops.collapsenodeto $ 1 true -- this collapsed it to a mesh

So I am not sure what is happening within your script...

3rd Dimentia
12 December 2007, 12:18 AM
Hi Anton, I have 2 issues that I'm trying to solve and they both have to do with world space modifiers/spacewarp bindings.
The first issue is that just doing a "copy" of an object, doesn't make a duplicate with the WSM's. So I've been trying to use maxops.clonenodes. But when I use this, the maxops.collapsenodeto doesn't work when executed in the same script, but will do if I run the line seperately or just in the listener. Yes it's weird.

The first 2 methods you list also do not collapse Worldspace Modifiers and Spacewarp Bindings.

The last one works, but not in a script after I've done a maxops.clonenodes to make the copy in the first place. (which is needed to copy the object with WSM's intact) And if I run the maxops.clone nodes and then do the maxops.collapsenodeto either in the listener or a totally seperate script, it works. But not when it's run in the same script.

Try runing this bit of code on an object that has modifiders and a spacewarp binding and you'll understand the problem I'm having. Then when it doesn't collapse, copy and run the last line in a listener seperately and you'll see that it works that way. It's really got me stumped.

maxops.clonenodes $ offset:[100,0,0] newNodes:&test
b = test[1]
select b
maxOps.CollapseNodeTo $ 1 true

12 December 2007, 02:35 AM
Ok, seeing as collapsing isn't working, what you might try it to get the instance of the modifier and copy the modifier over to your new object.

GetClassInstances() -- might check this out for doing what I'm saying globally

toCopy = $.modifiers[#WSMMOD] -- Copy it directly

addmodifer newObj toCopy

Maybe maybe?

3rd Dimentia
12 December 2007, 07:01 AM
Moondoggie, I think I know what you are getting at. I just added a section to loop thru the modifiers on the old object from bottom up (so it gets added in the right order) and if it's a WSM, then copy it to the new object.

for j = oldpolys[i].modifiers.count to 1 by -1 do
if superclassof oldpolys[i].modifiers[j] == SpacewarpModifier then
WSMcopy = copy oldpolys[i].modifiers[j]
addmodifier oldpoly WSMcopy

This worked great to copy the WSMs to the copied obect. BUT yet again, the maxops.collapsenodeto failed to collapse the WSM's into the copied object. And yet again it works if I run the command in the listener after the script has done object copy. Grrr.

I'm on max9 and I've had someone else on a mail list trying to help me with this issue and it seems that max 2008 doesn't have a problem when collapsing WSM's with maxops.collapsenodeto. So I might just have to wait til I'm on 2008 til I get this functionality to work in my script. Thanks so much for your time and help though.

CGTalk Moderation
12 December 2007, 07:01 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.