4
$\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$

2 Answers 2

8
$\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

$\endgroup$
0
5
$\begingroup$

I use this script

import bpy
sel_obj = bpy.context.selected_objects
for obj in sel_obj:
    bpy.context.view_layer.objects.active = obj
    bpy.ops.object.modifier_move_to_index(modifier="Armature", index=0)

Link to the docs : bpy.ops.object.modifier_move_to_index

$\endgroup$

You must log in to answer this question.

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