1
$\begingroup$

I'm working on a custom panel in Blender. I can add a subdivision modifier with python like this:

subsurfMod = self.layout.operator("object.modifier_add", text ="Add subdivision", icon="MOD_SUBSURF")
subsurfMod.type='SUBSURF'

However I want to also specify the number of cuts. Something like this doesn't work:

subsurfMod.levels='3'

What do I have to use instead?

$\endgroup$
2
$\begingroup$

There is an operator that sets subdivision level for an object and adds the Subsurf modifier if it does not exist:

bpy.ops.object.subdivision_set(level=4)

You can call it with a button like any other operator:

self.layout.operator("object.subdivision_set", text ="Add subdivision", icon="MOD_SUBSURF").level=4
$\endgroup$
  • $\begingroup$ I understand. But I need to call this modifier with a button. So I have to use self.layout.operator. $\endgroup$ – Lenny White May 22 '19 at 11:46
  • $\begingroup$ No problem there. You can use it like any other operator. See the updated answer. $\endgroup$ – Martynas Žiemys May 22 '19 at 12:33

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.