[Closed] How to Delete a Specific Modifier in The Stack
Hi guys;
I am an old MEL user and I have been studying MaxScript for a while. So this is a newbie question.
Here is my simple code in MaxScript:
for obj in $ do
(
addModifier obj (turbosmooth iterations:2)
addModifier obj (twist angle:60)
obj.lengthsegs=4
obj.heightsegs=4
obj.widthsegs=4
)
for obj in $ do
(
obj.modifiers[#turbosmooth].iterations=2
)
for obj in $ do
(
deleteModifier obj 1
deleteModifier obj 1
)
--------------------------------------------------------------------------------
This script is just for learning purposes. So do not try to select the whole code and press numeric enter button…
As you can see, the last for loop deletes the modifiers of the selected objects…
But I want this code to delete the modifier That I indicate.
“deleteModifier obj 1” allows me to delete the modifier regardless of What it is.
I just want this code to delete just the twist modifier, for example.
I checked the documentation but I could find nothing .
Best Regards;
Ozan
obj = selection[1]
deleteClasses = #(turbosmooth, bend, xform)
for i = obj.modifiers.count to 1 by -1 where findItem deleteClasses (classof obj.modifiers[i]) != 0 do deleteModifier obj.modifiers[i]
It wil itterate over the modifier stack, top to bottom (important because the length of the modifier stack changes when you delete an item!) and deletes the modifiers of a type defined in deleteClasses.
I’m not behind max now, but i’m pretty sure this will work, the logic is sound at least
-Johan
Johan
Thank you so much . To be honest; as an old MAYA user, the logic of MaxScript still so confusing for me. Your reply would be very usefull for an intermadiate MaxScripter.
Maybe I should ask that after I finish the whole concept of MaxScripting.
I will try to solve your script though.
Best Regards;
Ozan
Hi Ozan,
I don’t know if there is a concept of maxscript to be honest. Sure you have base types like string, integer or classes like turbosmooth, bend etc. But other then that there’s “just functions”. You take a variable and pass it to a function to do something. Offcourse there are the standard statements like if/for do/while etc.
So if we take a look at my code
obj = selection[1]
selection is basicly a array that contains the current selection, so to be sure I have a single node from the selection I use selection[1]
deleteClasses = #(turbosmooth, bend, xform)
These are the classnames of the type of modifier I want to delete. If you look in the helpfile under turbosmooth for example you see Constructor : TurboSmooth, that’s the classname, so if you want to filter on classes look in the helpfile under the desired object type and see what the constructor is named like.
for i = obj.modifiers.count to 1 by -1
here I do a simple for loop but it’s counting backwards from modifier.count to 1
why: If you delete a modifier while looping over the modifier stack you effectively change the modifier count. Going from bottom to top that poses a problem, but the other way around is no problem.
where findItem deleteClasses (classof obj.modifiers[i]) != 0 do
this is a conditional statement, here we use the findItem fuction that looks into an array (deleteClasses, we defined earlier) to see if the classname of the currentmodifier (classof obj.modifiers[i]) is found in the array that has our chosen classnames. If the result of that does not equal zero, it means he has found something so we can safely say :
deleteModifier obj.modifiers[i]
Where we delete the modifier on that particular index.
Maxscript in general is easy, not a very difficult syntax, the difficulty is in finding and knowing where to look for a certain function or possibility.
Hope it helps a bit,
goodluck in your maxscript journey!
-Johan
Ooo Johan I do not know What to say! This has totaly been a masterclass for me.
You almost explained more than everything That I needed.
I will be keeping on learning MaxScript even though I will be using Maya and MEL for my rigging duties. Do not get me wrong but If I had to compare MaxScript with MEL, It would be similar to comparing a Ferrari and Honda Civic. Both of these cars let you get somewhere. But as you can guess, driving a Ferrari something very different, easy, more helpfull and logical. ( like MEL )
Maybe I am wrong, maybe I think in that way because I am a newbie for MaxScript. Anyway, I would prefer to use MEL.
I realy want to thank you so much again.
Best Regards;
Ozan
I think it’s a bit like comparing apples and pears, more like Ferrari’s and Lamborghini’s (if you want to make friends here don’t call max a noisy honda civic )
Sure MEL has certain strengths max doesn’t have and vice verse, but I dare say that most scripts in max take a lot less lines then MEL. (but I don’t know MEL too well).
for c in cameras do c.fov = 35
for example, very short notation. MEL uses (from what I know about it more the setProperty and a bunch of cryptic parameters). Both have there merits, but is it not typical Maya has a good Python implementation besides MEL, every languages has strengths and weaknesses.
Also have a look at what Bobo (you’ll hear that name more often once you get into mxs) did here a while ago.
Cheers,
-Johan
Yes man You are right . I did not want to humiliate this script. Please for give me If one of you get me wrong. I might have used a wrong example as well. Bag my pardon …
The document you sent me is just perfect. I’ll be so helpfull for me to get used to with MaxScript.
Thanks a lot Johan. You have been so helpfull so far .
Best Regards;
Ozan