Advertisement
Guest User

Untitled

a guest
Nov 9th, 2020
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. import bpy
  2. from bpy.types import Panel, Operator, PropertyGroup
  3. from bpy.props import EnumProperty, PointerProperty
  4.  
  5.  
  6. class MyProperties(PropertyGroup):
  7.    
  8.     my_enum : EnumProperty(
  9.         name= "Enumerator / Dropdown",
  10.         description= "sample text",
  11.         items= [('OP1', "Add Cube", ""),
  12.                 ('OP2', "Add Sphere", ""),
  13.                 ('OP3', "Add Suzanne", "")
  14.         ]
  15.     )
  16.  
  17. class ADDONNAME_PT_main_panel(Panel):
  18.     bl_label = "Main Panel"
  19.     bl_idname = "ADDONNAME_PT_main_panel"
  20.     bl_space_type = 'VIEW_3D'
  21.     bl_region_type = 'UI'
  22.     bl_category = "New Tab"
  23.  
  24.     def draw(self, context):
  25.         layout = self.layout
  26.         scene = context.scene
  27.         mytool = scene.my_tool
  28.        
  29.        
  30.         layout.prop(mytool, "my_enum")
  31.         layout.operator("addonname.myop_operator")
  32.  
  33.  
  34.  
  35.  
  36.  
  37. class ADDONNAME_OT_my_op(Operator):
  38.     bl_label = "Add Object"
  39.     bl_idname = "addonname.myop_operator"
  40.    
  41.     def execute(self, context):
  42.         scene = context.scene
  43.         mytool = scene.my_tool
  44.        
  45.         return {'FINISHED'}
  46.    
  47.  
  48.  
  49.  
  50. classes = [MyProperties, ADDONNAME_PT_main_panel, ADDONNAME_OT_my_op]
  51.  
  52.  
  53. def register():
  54.     for cls in classes:
  55.         bpy.utils.register_class(cls)
  56.        
  57.     bpy.types.Scene.my_tool = PointerProperty(type= MyProperties)
  58.  
  59. def unregister():
  60.     for cls in classes:
  61.         bpy.utils.unregister_class(cls)
  62.     del bpy.types.Scene.my_tool
  63.  
  64.  
  65.  
  66. if __name__ == "__main__":
  67.     register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement