2
$\begingroup$

I need to check if the modifier.name for example "Subdivison" on the top of the modifiers stack

if modifier.name position == 0:
  print('Modifier "Subdivison" at the beginning of the stack')
else:
  print('Modifier "Subdivison" somewhere in the stack')

something like this

$\endgroup$
4
  • $\begingroup$ Hi, @APEC.. could you repost your solution as an answer, and accept it, so folks know not to try again, and others know where to find it in future? Thanks $\endgroup$
    – Robin Betts
    Aug 3, 2021 at 11:36
  • $\begingroup$ @RobinBetts: not apecs fault, i copied the solution in it ;) $\endgroup$
    – Chris
    Aug 3, 2021 at 11:38
  • 2
    $\begingroup$ I ask Chris to make a post and edit my original message. And then I accept it as a solution. Sorry for inconvenience. $\endgroup$
    – APEC
    Aug 3, 2021 at 11:38
  • 2
    $\begingroup$ Cheers, all, for whatever it is you're up to :D $\endgroup$
    – Robin Betts
    Aug 3, 2021 at 11:39

1 Answer 1

3
$\begingroup$

check this out:

The modifiers are just sorted in an array where the first is on position 0, the second on position 1 and so on.

import bpy
  
for o in bpy.context.scene.objects:
    if o.type == 'MESH':
        if o.modifiers:
            if o.modifiers[0].type == "SOLIDIFY":
                print("solidify modifier is on top for", o.name)

shorter version for python shorties.... ;)

tops = [o for o in bpy.context.scene.objects 
    if o.type == 'MESH' and o.modifiers 
    and o.modifiers[0].type == "SOLIDIFY"]

for o in tops:
    print("solidify modifier is on top for", o.name)
$\endgroup$
19
  • $\begingroup$ What if name contain *.001. *.002 so with if "Subdivison" in modifier.name. For example I apply a modifier and I need if it on the top then print: 1, if somewhere in the stack, then print: 2 $\endgroup$
    – APEC
    Aug 3, 2021 at 11:40
  • 1
    $\begingroup$ if you apply a modifier, it will be deleted from the array and i cannot be on top anymore. $\endgroup$
    – Chris
    Aug 3, 2021 at 11:41
  • $\begingroup$ @APEC: i am not sure what you mean, can you give a bit more explained example? what name? objects name? modifiers name? i don't understand, sorry. $\endgroup$
    – Chris
    Aug 3, 2021 at 11:43
  • 2
    $\begingroup$ Hmmmm... :) $\endgroup$
    – Robin Betts
    Aug 3, 2021 at 11:45
  • 1
    $\begingroup$ never mind, all fine! Thank you! $\endgroup$
    – APEC
    Aug 3, 2021 at 11:48

You must log in to answer this question.

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