PDA

View Full Version : modifier check help


ARTillery
03-30-2007, 10:17 AM
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 won’t work in the final version because the turbo smooth modifier doesn’t have to be the first in the stack but I just want to know why this doesn’t work.

The line $.modifiers[1] returns Turbosmooth:Turbosmooth so how come it returns false?

It didn’t select any objects when I wrote

select (for o in Geometry where try(o.modifiers[1] == turbosmooth)catch(false) collect o)

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)
)
macroScript polyOff category:"My Scripts"

(
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?

3- 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.

distract
03-30-2007, 11:00 AM
>>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)

>>"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.

i don´t know about the bones collection but it should be ok to check for o.baseobject == BoneGeometry

ARTillery
03-30-2007, 11:07 AM
classof, yes..that's what I was missing, thank you very much for the help.

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

ahem..mind if you elaborate a bit? :D

distract
03-30-2007, 11:26 AM
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

ARTillery
03-30-2007, 11:30 AM
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
)
)
)
)

distract
03-30-2007, 11:31 AM
sorry for bracketing, forgot the code tag...

CGTalk Moderation
03-30-2007, 11:31 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.