Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Reordering Modifiers

Reordering Modifiers

Anonymous
Not applicable
1,945 Views
7 Replies
Message 1 of 8

Reordering Modifiers

Anonymous
Not applicable
how can I use maxscript to reorganize the order of modifiers?, for example, making a certain class of modifiers allways be on top, or another class to allways be after an specific modifier.
0 Likes
1,946 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
how can I use maxscript to reorganize the order of modifiers?, for example, making a certain class of modifiers allways be on top, or another class to allways be after an specific modifier.


When you say order, you mean the STACK or the list of available modifiers?
Can you please post a step-by-step explanation of what you are trying to do and what should happen?
0 Likes
Message 3 of 8

Anonymous
Not applicable
Sorry for the ambiguity, I mean the stack; let's say that I have a hundred objects in my scene, and some have an UVW modifier before TurboSmooth and some have it after, or some have a point cache Modifier before an edit poly that has some points animated and after a Turbosmooth; is there a way to change the order so the point cache is on top of the edit poly and the TurboSmooth on top of all?, and is there a way to state this order (or pattern) for every object regardless of how many modifiers they have in the stack, (maybe by class?).
0 Likes
Message 4 of 8

Anonymous
Not applicable
Sorry for the ambiguity, I mean the stack; let's say that I have a hundred objects in my scene, and some have an UVW modifier before TurboSmooth and some have it after, or some have a point cache Modifier before an edit poly that has some points animated and after a Turbosmooth; is there a way to change the order so the point cache is on top of the edit poly and the TurboSmooth on top of all?, and is there a way to state this order (or pattern) for every object regardless of how many modifiers they have in the stack, (maybe by class?).


It is possible, but not as directly as you would like.
MAXScript can see the modifier stack as a list of modifiers, and you can get existing modifiers, delete modifiers by name or index, and add modifiers to the stack at any position (using a BEFORE: keyword where you can specify the location relative to an existing indexed modifier). In MAXScript, all modifiers on a stack are indexed from top to bottom, so the top modifier is always index 1 and the bottom has index equal to yourObject.modifiers.count.
So writing a script that figures out whether a TurboSmooth is on the right place and performing a scripted cut&paste to a new position IS possible. There can be complications when modifiers require sub-object selections to be passed to them, and pasting some gizmo-based deformers might work differently than in the UI, but in general the answer is yes.

The exact logic of the code would depend on the specific order you want, so writing a universal script that can do ALL possible reordering operations is tricky, but if you want the TurboSmooth to be on top or PointCache above Edit Poly, these can be expressed in dedicated functions.

If you need an example, let me know.
0 Likes
Message 5 of 8

Anonymous
Not applicable
thank you very much for your explanation, it was very clear, if you could give me an example of the dedicated function it would be great.
0 Likes
Message 6 of 8

Anonymous
Not applicable
Basically, you would query all modifiers on an object, per object make a temporary array of a list of the modifiers found. Then you would query the array to see if there is a Edit Poly / Point Cache / Turbosmooth modifier in the list, and the order in which they sit. If the Point Cache is after the Edit Poly, as you want it, do nothing, otherwise, access the actual modifier list, not the array, and change the order by moving it up in the list. If there is a Turbosmooth in the list, access the actual modifier list and place it at the top, based on the total number minus 1 of the modifier stack.

That's the basic logic, and you can look in the Maxscript help on accessing the modifier stack, accessing individual modifiers, creating temporary arrays, querying the location of items in the modifier, then moving the modifier in the modifier stack.

I don't know enough of the actual code, but I could likely write something like that... I just don't have time. Bobo can probably come up with something fairly quickly since he's a Master Maxscripter. 🙂
0 Likes
Message 7 of 8

Anonymous
Not applicable
thank you very much for your explanation, it was very clear, if you could give me an example of the dedicated function it would be great.


Here are two examples - the one moves all TurboSmooths to the top of the stack, the other moves all PointCaches to the bottom of the stack. Depending on where you want your modifiers to be, you might need different code, but these show the basic idea...


--loop through all objects
for o in objects do
(
--collect the index and actual modifier instance for every modifier in the current object that is a turbosmooth
theTSArray = for i = o.modifiers.count to 1 by -1 where classof o.modifiers == TurboSmooth collect #(i, o.modifiers)
for m in theTSArray do deleteModifier o m --delete all collected modifiers by index
for m in theTSArray do addModifier o m --add back all collected instances on top of the stack
)--end o loop

--loop through all objects
for o in objects do
(
--collect all modifiers in the current object
theMods = for m in o.modifiers collect m
--loop from top to bottom and if the modifier is a PointCache,
for m in theMods where classof m == PointCache do
(
addModifier o m before:theMods.count --instance it to the bottom of the stack
deleteModifier o m --and remove the original instance from where it was on the stack
)--resulting in all PointCache modifiers being moved to the bottom of the stack, but preserving the relative order
)--end o loop
Message 8 of 8

Anonymous
Not applicable
Thank you very much, this has been of great help
0 Likes