2
$\begingroup$

I want to do it so that when they press a button a window comes up which says 'Subdivision Level' and then an input where whoever's using it can put in a number which changes how much subdivision to add.

Here's the code:

import bpy

class customMenu(bpy.types.Menu):
    bl_label = "Useful Menu"
    bl_idname = "view3D.custom_menu"

    def draw(self, context):
        layout = self.layout

        layout.operator("bpy.ops.object.subdivision_set(level=1")
        layout.operator("object.duplicate_move")

def register():
    bpy.utils.register_class(customMenu)
    #bpy.ops.wm.call_menu(name=customMenu.bl_idname)

def unregister():
    bpy.utils.unregister_class(customMenu)

if __name__ == "__main__":
    register()

I know how to do everything else I'm just confused about how to make something which allows people to put in inputs/make a slider/make a check box in blender python.

I don't mind if as an answer you just put the code on how to make these input types or if you link a wiki article or something. I'm just having problems finding the right website and I'm pretty sure it can be done.

Here's a link to the blender tutorial that I currently want the input for. So that when I click something on the mini-menu, another mini-menu-thing will open asking how much levels you want and if you want it simple or catmull-clark etc.

I'm sorry if it's obvious but I couldn't find an answer anywhere.

$\endgroup$
4
  • $\begingroup$ you are creating an addon right ? $\endgroup$
    – Chebhou
    May 23, 2015 at 20:37
  • $\begingroup$ @Chebhou not sure to be honest. I'm following a tutorial (I'll edit the question so it has a link to it) i think I'm just creating a little menu thing, like the ones where you press shift-a. $\endgroup$ May 23, 2015 at 20:38
  • $\begingroup$ possible duplicate of How to call invoke_popup? $\endgroup$
    – p2or
    May 26, 2015 at 8:58
  • $\begingroup$ also related: blender.stackexchange.com/questions/23974/… $\endgroup$
    – p2or
    May 26, 2015 at 8:59

1 Answer 1

5
$\begingroup$

You can create an operator which will show a menu when called , this is the Simple Operator example edited to fit this case :

enter image description here

  • Run the script to rigster the operator
  • press Space and type Simple Object Operator

import bpy
from bpy.props import IntProperty

def main(self, context):
    bpy.ops.object.subdivision_set(level=self.level)

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}
    
    level = IntProperty(default = 1, min = 0, max = 10)
    
    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):
        main(self, context)
        return {'FINISHED'}
    
    def invoke(self, context, event):
        wm = context.window_manager
        return wm.invoke_props_dialog(self)

def register():
    bpy.utils.register_class(SimpleOperator)

def unregister():
    bpy.utils.unregister_class(SimpleOperator)

if __name__ == "__main__":
    register()

For 2.8~

import bpy
from bpy.props import IntProperty

def main(self, context):
    bpy.ops.object.subdivision_set(level=self.level)

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}

    level : IntProperty(default = 1, min = 0, max = 10)

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):
        main(self, context)
        return {'FINISHED'}

    def invoke(self, context, event):
        wm = context.window_manager
        return wm.invoke_props_dialog(self)

def register():
    bpy.utils.register_class(SimpleOperator)

def unregister():
    bpy.utils.unregister_class(SimpleOperator)

if __name__ == "__main__":
    register()
$\endgroup$
3
  • $\begingroup$ I'll check it tomorrow. Sorry I can't do it today $\endgroup$ May 23, 2015 at 21:24
  • $\begingroup$ Wait where are you supposed to put this? I'll edit my finished code into the question so you can see. $\endgroup$ May 24, 2015 at 6:29
  • $\begingroup$ @Chickenator sorry this was for the operator but you are creating a menu I think it does not support this $\endgroup$
    – Chebhou
    May 24, 2015 at 11:09

You must log in to answer this question.

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