2

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.

someonewithpc
  • 12,381
  • 6
  • 55
  • 89
Chickenator
  • 1,803
  • 5
  • 22
  • 33

1 Answers1

5

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

mml
  • 443
  • 2
  • 9
Chebhou
  • 19,533
  • 51
  • 98