Can modifiers be computed and applied from the command line?

For heavy modifiers, the time it takes to compute can range between a few seconds to half an hour or longer.

Can modifiers be added, computed, and applied from the command line with some sort of indicator of progress?

Running from the command line would be useful for running blender GUI-less without a WM to save memory.
It would also be ideal to have some idea of how far along the modifier is.

• From you question its not clear if you want to create and apply the modifiers from the command-line, or just apply existing modifiers. If the modifier takses half an hour to compute I would guess you didnt set this up from the UI. – ideasman42 Sep 15 '13 at 22:42
• In my particular case I can set it up from the UI, as it only takes that much computation time with high settings (so I can disable visibility before setting it) But if it's possible, it would be good to add the modifier from the command line as well. – gandalf3 Sep 16 '13 at 0:52
• could you update your question then? For a good answer these details are important. – ideasman42 Sep 16 '13 at 3:37

You'd have to use bpy.ops.object.modifier_apply, e.g.

import bpy

for obj in bpy.context.scene.objects:
bpy.context.scene.objects.active = obj
count = 1
length = len(obj.modifiers)
while obj.modifiers:
name = obj.modifiers[0].name
print("%s: Applying %s (%d/%d)" % (obj, name, count, length))
bpy.ops.object.modifier_apply(modifier=name)
count += 1
print("All done.")


For info on how to to run the above, see here.

• Thanks. This works pretty well, but I was thinking of and indicator of progress per modifier. As mentioned by ideasman42, It seems this is not possible at the moment. – gandalf3 Sep 16 '13 at 23:17

You can apply modifiers from the command line using a script, but there is no progress for each modifier.

Note that modifiers that take half an hour is not the kind of work-flow Blender is optimized for. If you are processing very high polygon meshes you may want to consider some tool like MeshLab to get them into a more usable detail level for blender to work with.