Notifications
Clear all

[Closed] Toggle modifier script help

Hi all,

Just a simple script to toggle off my turbosmooth modifiers


If (getClassInstances turbosmooth).enabled=false

Then (getClassInstances turbosmooth).enabled=true

Else (getClassInstances turbosmooth).enabled=false

It doesn’t seem to spit back an error… am I able to use the getclassinstances as an If test like that?

Thanks

4 Replies

You need to use a for loop to go through every item in the array collection of turbosmooths that getclassinstances generates. You can then just tell it to be ‘not’ its current value to switch it on and off with the same line of code.

for o in (getclassinstances Turbosmooth) do o.enabled = not o.enabled

Your script can’t work because (getclassinstances Turbosmooth) defines an array, which doesn’t have the parameter “enabled” only the objects inside the array do. So Dave’s script is the way to go

One more note, though. You used just a single equal sign in your if comparison instead of the double equal sign ==. This will set the parameter instead of comparing it which is probably not what you want…

 lo1

Syntax issues aside, what would you expect it to return if only some of them are enabled?

What I usually do for this problem is check if any of them are enabled, then set all of them to off, otherwise turn them all on

ts = getClassInstances turboSmooth
ts.enabled = (for t in ts where t.enabled collect ok).count == 0

Thanks guys,

Thats a big help. Yeah I was looking at it more of a setting, didn’t realise that was an array, I had found that bit of code.

And thanks Lo, good point, what if some modifiers were not on.

Much appreciated!