# How to specify number of cuts for subdivision modifier in python

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?

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

self.layout.operator("object.subdivision_set", text ="Add subdivision", icon="MOD_SUBSURF").level=4

• I understand. But I need to call this modifier with a button. So I have to use self.layout.operator. – Lenny White May 22 '19 at 11:46