[Closed] check for modifier
Hello, I’m very new at maxscript so I’m sure this is a really basic question. Is there a way to have maxscript check for a certain kind of modifier on the current selection and then return a value based on whether or not it finds that modifier?
I’m trying to make a script that will change the iterations on a meshsmooth (if it finds one) or add a meshsmooth (if it doesn’t find one) but I can’t figure out how to have it check if one is there.
Thanks!
This will return an array of all objects in the selection that do have at least one meshsmooth modifier:
haveTheMod = for o in selection where
(for m in o.modifiers where classof m == meshsmooth collect m).count > 0 collect o
If you want to add one if there is none, you could say:
for o in selection where
(for m in o.modifiers where classof m == meshsmooth collect m).count == 0 do
addModifier o (meshselect())
If you want to change the iterations, you should be careful when there is more than one of these modifiers on the same stack. You could probably check whether there is exactly one modifier first, or always affect the first modifier encountered even if there are more…
This will change EVERY meshsmooth in the selected objects:
for o in selection do
for m in o.modifiers where classof m == meshsmooth do
m.iterations = 2
This will change the first meshsmooth modifier encountered in each object:
for o in selection do
for m in o.modifiers where classof m == meshsmooth do
(m.iterations = 2; exit)
I would also highly suggest (shameless plug ahead) the CG-Academy DVD “MAXScript for the masses” which is full of exactly this stuff…
if (ClassOf $.modifiers[1]) == meshsmooth then
(
$.meshsmooth.iterations = 6
)
else
(
addmodifier $ (meshsmooth())
)
sorry it is kinda late here is something that should work I know there is a better way
-Baker
Hey! Thanks for the quick reply!
So I’m running into a problem:
If I run it with a meshsmooth already on the object, then it works fine. If I run it without a meshsmooth on there, it gives this error:
-- Error occurred in anonymous codeblock
-- Frame:
-- Unknown property: "meshsmooth" in $Box:Box01 @ [0.000000,0.000000,0.000000]
I tried evaluating just [validModifier $ meshsmooth] and it returns True no matter I have a meshsmooth on my selection or not.
I think I remember reading that the [validModifier $ meshsmooth] function checks if that is a valid modifier inside max, not on the current selection. (I could be wrong though)
Thanks for the help, and sorry if this is just me being a newbie.
ok I upadated what I did but all this does is check if the first element in the MAXModifierArray is a meshsmooth modifier so if there is anything else in the stack it will return false given the meshsmooth is anywhere other than the first modifier added.
Like I said above there is a much better way but I am extremely sleepy and somewhat new to maxScript.
I tried evaluating just [validModifier $ meshsmooth] and it returns True no matter I have a meshsmooth on my selection or not.
the reason for that is I read the ref doc wrong what that does is this
Tests whether a particular modifier or modifier class may be added the given <node> or to all of the objects in the objectset or group. Returns true if so, false if not.
-Baker