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")

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


What do I have to use instead?


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


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
  • $\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.