Advertisement
Guest User

Untitled

a guest
Aug 17th, 2020
3,984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.89 KB | None | 0 0
  1. import bpy
  2.  
  3.  
  4.  
  5.  
  6.  
  7. class MyProperties(bpy.types.PropertyGroup):
  8.    
  9.     my_string : bpy.props.StringProperty(name= "Enter Text")
  10.    
  11.     my_float_vector : bpy.props.FloatVectorProperty(name= "Scale", soft_min= 0, soft_max= 1000, default= (1,1,1))
  12.    
  13.     my_enum : bpy.props.EnumProperty(
  14.         name= "Enumerator / Dropdown",
  15.         description= "sample text",
  16.         items= [('OP1', "Add Cube", ""),
  17.                 ('OP2', "Add Sphere", ""),
  18.                 ('OP3', "Add Suzanne", "")
  19.         ]
  20.     )
  21.  
  22.  
  23.  
  24.  
  25.  
  26. class ADDONNAME_PT_main_panel(bpy.types.Panel):
  27.     bl_label = "Main Panel"
  28.     bl_idname = "ADDONNAME_PT_main_panel"
  29.     bl_space_type = 'VIEW_3D'
  30.     bl_region_type = 'UI'
  31.     bl_category = "New Tab"
  32.  
  33.     def draw(self, context):
  34.         layout = self.layout
  35.         scene = context.scene
  36.         mytool = scene.my_tool
  37.        
  38.         layout.prop(mytool, "my_string")
  39.         layout.prop(mytool, "my_float_vector")
  40.         layout.prop(mytool, "my_enum")
  41.  
  42.         layout.operator("addonname.myop_operator")
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. class ADDONNAME_OT_my_op(bpy.types.Operator):
  50.     bl_label = "Add Object"
  51.     bl_idname = "addonname.myop_operator"
  52.    
  53.    
  54.    
  55.     def execute(self, context):
  56.         scene = context.scene
  57.         mytool = scene.my_tool
  58.        
  59.         if mytool.my_enum == 'OP1':
  60.             bpy.ops.mesh.primitive_cube_add()
  61.             bpy.context.object.name = mytool.my_string
  62.             bpy.context.object.scale[0] = mytool.my_float_vector[0]
  63.             bpy.context.object.scale[1] = mytool.my_float_vector[1]
  64.             bpy.context.object.scale[2] = mytool.my_float_vector[2]
  65.  
  66.  
  67.            
  68.            
  69.         if mytool.my_enum == 'OP2':
  70.             bpy.ops.mesh.primitive_uv_sphere_add()
  71.             bpy.context.object.name = mytool.my_string
  72.             bpy.context.object.scale[0] = mytool.my_float_vector[0]
  73.             bpy.context.object.scale[1] = mytool.my_float_vector[1]
  74.             bpy.context.object.scale[2] = mytool.my_float_vector[2]
  75.            
  76.        
  77.        
  78.        
  79.         if mytool.my_enum == 'OP3':
  80.             bpy.ops.mesh.primitive_monkey_add()
  81.             bpy.context.object.name = mytool.my_string
  82.             bpy.context.object.scale[0] = mytool.my_float_vector[0]
  83.             bpy.context.object.scale[1] = mytool.my_float_vector[1]
  84.             bpy.context.object.scale[2] = mytool.my_float_vector[2]
  85.            
  86.        
  87.        
  88.         return {'FINISHED'}
  89.    
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. classes = [MyProperties, ADDONNAME_PT_main_panel, ADDONNAME_OT_my_op]
  100.  
  101.  
  102.  
  103. def register():
  104.     for cls in classes:
  105.         bpy.utils.register_class(cls)
  106.        
  107.         bpy.types.Scene.my_tool = bpy.props.PointerProperty(type= MyProperties)
  108.  
  109. def unregister():
  110.     for cls in classes:
  111.         bpy.utils.unregister_class(cls)
  112.         del bpy.types.Scene.my_tool
  113.  
  114.  
  115.  
  116. if __name__ == "__main__":
  117.     register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement