1
$\begingroup$

To my knowledge I believe modifiers can moved up one step in the list through executing this line bpy.ops.object.modifier_move_up()

Is there anyway to move a modifier to the top of entire stack through python based on the modifier name or type ?

$\endgroup$
4
$\begingroup$

This can be done by some simple scripting. I assume obj is filled with the object with the modifier stack

def modifiers_by_name(obj, name):
    """ Find all modifiers with a specific name in obj """
    return [x for x in obj.modifiers if x.name == name]

def modifiers_by_type(obj, typename):
    """ Find all modifiers with a specific type in obj """
    return [x for x in obj.modifiers if x.type == typename]

# move all "Screw" modifiers to the top
for modifier in reversed(modifiers_by_type(obj, "SCREW")):
    # while modifier not on top
    while obj.modifiers.find(modifier.name) != 0:
        # move it one more to the top.
        bpy.ops.object.modifier_move_up(modifier=modifier.name)

Note I reversed the modifiers so the top "Screw" modifier will still be on the top after execution

|improve this answer|||||
$\endgroup$
  • $\begingroup$ rather than reversing the list and always moving mod to top, could move it until it has same index list and stack. (not a biggy on small lists). Nice answer. $\endgroup$ – batFINGER Jan 19 '18 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.