[Closed] Test multiple Objects for existing modifier and delete it
Hi
i´m trying to automate a process of looking through different objects if there is a modifier present and then delete it, if it is the right modfier.
I´m coming from Softimage and right now i am not really able to translate my scripting-knowledge to MAXScript…i hope you can help me somehow.
I know exactly what i want to do…but cant turn that into MAXScript.
I need a script to:
Get the current selected objects
traverse through them and look for the last modifier in stack of every single object
compare this modifier to the modifier i want to remove
remove the modifier from the objects stack, if it is present.
Can someone help me with that one?
Would appreciate that
Sure.
There are some details that might require clarification – you can compare a modifier by class, by name or by instance. In other words, you can check if the modifier is of class Bend, whether it is called “Bend” (the name is user-definable while the class is fixed), or if the Bend modifier on the object is an INSTANCE of another Bend modifier you have a handle of. Let’s assume you want to do the former and delete by class:
for o in selection where classof o.modifiers[1] == Bend do deleteModifier o 1
Keep in mind the modifiers in Max are numbered from TOP of the stack, thus the top modifier is ALWAYS number 1. If there is no modifier at all, o.modifiers[1] returns ‘undefined’ (the MAXScript value for Void) so it does not crash since ‘classof undefined’ is a valid class value (UndefinedClass).
You can replace the ‘Bend’ in the above example with the class name of the modifier you want to delete.
You can also replace the ‘selection’ with ‘objects’ to scan all scene objects instead of just the selection.
You can enclose the code in a MacroScript definition or just drag the code from the editor to a Toolbar to make a button. To make a MacroScript manually, add this:
MacroScript DeleteTopBend category:"DeracusScripts"
(
for o in selection where classof o.modifiers[1] == Bend do deleteModifier o 1
)
Evaluate, then go to Customize > Customize User Interface and search for the category, then drag the script to a toolbar or assign to a keyboard shortcut / menu / QuadMenu if you want.
Not exactly sure what you are after but here is a script that will delete all the modifiers in the selection that are turboSmooth modifiers
for obj in selection do
(
for m in obj.modifiers do
(
if classOf m==turboSmooth do deleteModifier obj m
)
)
Thanks to both of you. Really helped me out.
I have to take some time in the next days to get a grip on MAXScript. The Help looks like a great place to start and i think somewhere in the office is a MAXScript-DVD. Hope i come up to speed soon. There are quite a few differences to the way of scripting XSI as it is closer to JScript then VBScript (which seems to be the origin of MAXScript)
Java Script and Max script are similar in that they are very loose.
It will not take long, finding all the commands for a new language is usually the hardest part.
Just so you know, it is Bobo that keeps up the Max script help files these days and they are the best place to start. Do all the tutorials in them and then have a look at the Practical Examples, that will help a lot. Also strung all through the help files are practical and usable functions that you can just cut and paste.