[Closed] modifier check help
Hi all,
I’m trying to do 2 scripts that perform a similar function, first one would select only bones in the scene and turn any editpoly modifiers on them on and off, the seconed would select any object who had a turbosmooth modifier and turn it on and off.
I'm new to max script so I need a much help here, however I'll start by a simple question and I'll see how to go, this is also an exercise to train me on the use of Max script.
the questions are:
1- Why does the line $.modifiers[1].turbosmooth == turbosmooth return false although the object has a turbosmooth modifier on?
Obviously this wont work in the final version because the turbo smooth modifier doesnt have to be the first in the stack but I just want to know why this doesnt work.
The line $.modifiers[1] returns Turbosmooth:Turbosmooth so how come it returns false?
It didnt select any objects when I wrote
select[font=Lucida Console] (for o in Geometry where try(o.modifiers[1] == turbosmooth)catch(false) collect o)
[/font] [font="]
[/font] [font=Verdana]so I had to check it out.
2- I managed to finally make the right script for this, or so I believe it goes like this
macroScript polyOn category:"My Scripts"
(
for o in objects where try (o.turbosmooth.enabled == false) catch (false) do (o.turbosmooth.enabled = true)
)
[/font][font=Verdana]macroScript polyOff category:"My Scripts"[/font][font=Verdana]
([/font]
[font=Verdana]for o in objects where try (o.turbosmooth.enabled == false) catch (false) do (o.turbosmooth.enabled = true)
)
my question is, is there a better way to do this?
[/font] 3- [font=Verdana]is there an object collection for bones or do I have to check if the base object is bone all the time?
thanks in advance[font="].[/font][/font]
>>Why does the line $.modifiers[1].turbosmooth == turbosmooth return false
do a check on the class: classof $.modifiers[1] == turbosmooth
so you could do:
select (for o in Geometry where try(classof o.modifiers[1] == turbosmooth)catch(false) collect o)
[font=Verdana]>>“is there a better way to do this”
if it solves your problem… i would check for the class and the modifierclasses and if they are != undefined because it´s more clean i guess, but i admit i use try/catch like you did if i´m just trying to solve something quickly in production and if it works.
[/font]
i don´t know about the bones collection but it should be ok to check for o.baseobject == BoneGeometry
classof, yes…that’s what I was missing, thank you very much for the help.
ahem…mind if you elaborate a bit?
[/font]
fn turboCtrl state =
(
for obj in geometry do
(
for modif in obj.modifiers do
(
if (classof modif == turbosmooth) do
(
modif.enabled = state
)
)
)
)
execute that once and then turn everything on and off using:
turboCtrl off
turboCtrl on
thank you very much, that really helped
Here’s the final script, if it may help anybody
/*
Title: ARTillery utilities
Version : 0.1
Author : Ahmad Adel
email: ahmad3adel@gmail.com
Date : March 30, 2007
**********************
ToDo: assign better names and icons and whatnot
Bugs:
Max ver: 9x
*/
macroscript
SetTurboOn category:"ARTillery"
(
setTurbo true
)
macroscript
SetTurboOff category:"ARTillery"
(
setTurbo False
)
macroscript
BonePolyOn category:"ARTillery"
(
BonePoly True
)
macroscript
BonePolyOff category:"ARTillery"
(
BonePoly False
)
fn BonePoly state=
(
BoneObjects = #()
BoneObjects = for o in Objects where (classof o.baseObject == BoneGeometry) collect o
--collects all bone objects in an array
for i=1 to BoneObjects.count do
--iterate through the bone objects in the array
(
for modif in Boneobjects[i].modifiers do
--iterate through the modifiers in the bones
(
if (classof modif == Edit_poly) then
--checks if the modifier is edit Poly
(
modif.enabled = state
--change the modifier state
)
)
)
)
fn SetTurbo state =
(
for o in objects do
--iterate through scene objects
(
for modif in o.modifiers do
--iterate through object modifiers
(
if (classof modif == turbosmooth) then
--check if the object current modifier is Turbo Smooth
(
modif.enabled = state
--change the modifier state
)
)
)
)