Using Python for manipulation of modifier values

Hi evrybody,

I’ve got a Problem:
I’ve a complex scene with many objects. Working in the scene some times makes it necessary to change the value of the subdivision surface modifier (number of subdivisions). But it’s a lot of work to select each object one by one and change the modifier value on every object at each time. Making this by hand doesn’t make any sens.

So I wanted to write a script for that…but it seems to be impossible to change the values in the modifiers with python :confused:. Adding a mod is no problem only value changing is impossible.

Maybe there is a way to make python manipulate mod values that I just don’t know?!?!

Does anybody know about such a way?


I think you can only do it before applying the modifier

If you just need the line to modify the number of subdivisions, it’s:

yourobjectname = "Cube" #for example
numberofsubdivisions = 3 #for example[yourobjectname].modifiers["Subsurf"].levels = numberofsubdivisions

You could use the built in Simplify check box under the Scene context.
Once activated, you can specify the maximum subdivision for all objects in the scene.

Thanks a lot to you guys!
@curlybrace44: This is a good advice especially because it reminded me of the fact, that the information of the data that’s behind a button or an entry is always shown when you hower the mouse arror above it. Now that I know which data to manipulate, I will try to find out how to set it on specifily selected objects!

@Atom: You brought me a fast an simple method for switching subdividions for working in the viewport while working on the mesh, that helps a lot!

Greetz and thanks

Using: Blender 2.62 (64bit)

Hi folks,

there is still a problem left (for me):
It’s easy to make the script putting a subsurf mod to the aktive object. But the problem is, that I want a script that puts a mod to all objects in the viewport that are selected.

For example:
You have objects A, B, C, D, E, F. You select the objects B, C and F. And now the script should put the mod to B, C and F.

This is what I did for that so far:
import bpy

selected = bpy.context.selected_objects

for all in selected:

Running that script with one object (B for instance) causes that object B get a mod (good so far). But when I select B, C and F together, the script puts the mod three times to the active object!
So the problem is, that every thing that happens refers to the aktive object and not to the selected ones. I need the script to turn all selected objects into the aktive one, one by one so that the mod is put to each of them (one by one).

Does anybody see a way to do that???

The op adds a mod to the active object.

for ob in context.selected_objects: = ob

You can also add using…)

I don’t know if it’s correct but when I use the bpy.ops class i just imagine doing the same thing in the blender GUI, and when you apply a modifier to selected objects the modifier is applied just to one of them which is the active object.

When the for cycle in your script runs the first time it assigns to the variable all the first object of the selected list and then it applies the modifier to the active object.

On the second cycle it assigns to the variable all the second object of the selected list and then it applies the modifier to the active object…which is the same as before.

Same thing the third time.

so you just need to make the object assigned each time to all the active object:

import bpy
selected = bpy.context.selected_objects
for all in selected: = all

I dont’ know if it’s the best way to do it, but should work

nvm. Didn’t refresh before reply

thanks to you’ll it finally works!