3
$\begingroup$

I have a modifier that I want to put at the top of the modifier stack.

How can I do this in python?

$\endgroup$

1 Answer 1

5
$\begingroup$

Suppose you have two modifiers like this:

enter image description here

Note that the second modifier is named "Subsurf". You can move it up like this:

bpy.ops.object.modifier_move_up(modifier="Subsurf")

You may need to set the active object first, as described in this answer:

my_object = bpy.context.scene.objects['Cube']
bpy.context.scene.objects.active = my_object

If your modifier is in an unknown position in the stack, you can use a loop like this to bring it to the top:

while my_object.modifiers[0].name != "Subsurf":
    bpy.ops.object.modifier_move_up(modifier="Subsurf")
$\endgroup$
2
  • $\begingroup$ But what if I have an unknown number of modifiers? $\endgroup$
    – Omar Emara
    Commented Feb 11, 2016 at 6:28
  • $\begingroup$ @OmarAhmad I edited my post to answer this question. $\endgroup$ Commented Feb 11, 2016 at 7:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .