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$ Aug 3 '21 at 11:36
  • $\begingroup$ @RobinBetts: not apecs fault, i copied the solution in it ;) $\endgroup$
    – Chris
    Aug 3 '21 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 '21 at 11:38
  • 2
    $\begingroup$ Cheers, all, for whatever it is you're up to :D $\endgroup$ Aug 3 '21 at 11:39
2
$\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 '21 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 '21 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 '21 at 11:43
  • 2
    $\begingroup$ Hmmmm... :) $\endgroup$ Aug 3 '21 at 11:45
  • 1
    $\begingroup$ never mind, all fine! Thank you! $\endgroup$
    – APEC
    Aug 3 '21 at 11:48

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.