I'm trying to achieve this:
I select all objects with the same type of modifier (Armature) and want to "click" Apply on all of them. I searched different scripts on here and badly put together this one:
import bpy
sel = bpy.context.selected_objects
for ob in sel:
for i, mod in enumerate(ob.modifiers):
if mod.type == 'ARMATURE':
bpy.context.scene.objects.active = ob
for x in range(0, i):
bpy.ops.object.modifier_apply(modifier=mod.name)
It will work for some of the selected objects then Blender will say "Python Script fail". It's obvious I don't know what I'm doing, but why is it failing after working at first? Thanks
EDIT: I found something that does exactly what I was trying to do. A user from Blender Artists named VincentG created an addon called "Massive Editor" from here. I selected all objects, typed Armature in the custom field and all objects that had that specific modifier applied. The script may be old, but it worked great. Thanks Vincent!
For the sake of learning though, I'd still want to know what went wrong...
UPDATE: While searching around I found this answer here and tried it out to see if it would work for me:
import bpy
sel = bpy.context.selected_objects
act = bpy.context.active_object
for obj in sel:
if obj != act:
bpy.context.scene.objects.active = obj #sets the obj accessible to bpy.ops
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Mirror")
bpy.context.scene.objects.active = act
It almost does what I would like but every time it would only apply to all selected objects except the active one.
Ctrl
C
followed byM
with all the objects selected in object mode. Strictly speaking, this is used to convert meta balls, curves or text to meshes, but it also applies all modifiers, and it works just fine even when the selected objects are already meshes. $\endgroup$Info: Applied modifier was not first,...(This was said 4 times) ...line 9 (Which was bpy.ops.object.modifier_apply(modifier=mod.name)) ...UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte Error: Python script fail, look in the console for now...
The second method just does nothing and console seems to just pause. $\endgroup$