I would like to move a modifier (which I have already identified) to the bottom of the list of existing modifiers. Unfortunately it does not work and I don't get why...? However, if the object is active, it moves perfectly to the bottom:
#ob = my object, not necessarily it must be selected, it is found by a function
#smooth = #my modifier (found through a function)
for m in ob.modifiers:
bpy.ops.object.modifier_move_down(modifier = smooth.name)
This only works if the active object is ob
. Do I have to override the context? There is a similar question to this but I have no idea how to apply this in my case.
It seems that I have solved my problem by overriding the context members:
for m in ob.modifiers:
c = {}
c["object"] = c["active_object"] = ob
bpy.ops.object.modifier_move_down(c ,modifier = smooth.name)
Any thoughts? Is there a better way of doing that?