Advertisement
Guest User

Untitled

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