Advertisement
Guest User

ObjectAdder

a guest
Feb 24th, 2020
4,640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.44 KB | None | 0 0
  1. bl_info = {
  2.     "name": "Object Adder",
  3.     "author": "Darkfall",
  4.     "version": (1, 1),
  5.     "blender": (2, 80, 0),
  6.     "location": "View3D > Toolbar > Object Adder",
  7.     "description": "Adds objects and other functions",
  8.     "warning": "",
  9.     "wiki_url": "",
  10.     "category": "Add Mesh",
  11. }
  12.  
  13.  
  14.  
  15. import bpy
  16.  
  17.  
  18.  
  19.  
  20.     #This is the Main Panel (Parent of Panel A and B)
  21. class MainPanel(bpy.types.Panel):
  22.     bl_label = "Object Adder"
  23.     bl_idname = "VIEW_PT_MainPanel"
  24.     bl_space_type = 'VIEW_3D'
  25.     bl_region_type = 'UI'
  26.     bl_category = 'Object Adder'
  27.    
  28.     def draw(self, context):
  29.         layout = self.layout
  30.         layout.scale_y = 1.2
  31.        
  32.         row = layout.row()
  33.         row.label(text= "Add an object", icon= 'OBJECT_ORIGIN')
  34.         row = layout.row()
  35.         row.operator("wm.myop", icon= 'CUBE', text= "Cube")
  36.         row.operator("mesh.primitive_uv_sphere_add", icon= 'SPHERE', text= "Sphere")
  37.         row.operator("mesh.primitive_monkey_add", icon= 'MESH_MONKEY', text= "Suzanne")
  38.         row = layout.row()
  39.         row.operator("curve.primitive_bezier_curve_add", icon= 'CURVE_BEZCURVE', text= "Bezier Curve")
  40.         row.operator("curve.primitive_bezier_circle_add", icon= 'CURVE_BEZCIRCLE', text= "Bezier Circle")
  41.        
  42.        
  43.         row = layout.row()
  44.         row.operator("object.text_add", icon= 'FILE_FONT', text= "Add Font")
  45.         row = layout.row()
  46.        
  47.        
  48.        
  49.  
  50.  
  51.  
  52.     #This is Panel A - The Scale Sub Panel (Child of MainPanel)
  53. class PanelA(bpy.types.Panel):
  54.     bl_label = "Scale"
  55.     bl_idname = "VIEW_PT_PanelA"
  56.     bl_space_type = 'VIEW_3D'
  57.     bl_region_type = 'UI'
  58.     bl_category = 'Object Adder'
  59.     bl_parent_id = 'VIEW_PT_MainPanel'
  60.     bl_options = {'DEFAULT_CLOSED'}
  61.    
  62.     def draw(self, context):
  63.         layout = self.layout
  64.         obj = context.object
  65.        
  66.         row = layout.row()
  67.         row.label(text= "Select an option to scale your", icon= 'FONT_DATA')
  68.         row = layout.row()
  69.         row.label(text= "      object.")
  70.         row = layout.row()
  71.         row.operator("transform.resize")
  72.         row = layout.row()
  73.         layout.scale_y = 1.2
  74.        
  75.         col = layout.column()
  76.         col.prop(obj, "scale")
  77.        
  78.        
  79.        
  80.  
  81.  
  82.  
  83.     #This is Panel B - The Specials Sub Panel (Child of MainPanel)
  84. class PanelB(bpy.types.Panel):
  85.     bl_label = "Specials"
  86.     bl_idname = "VIEW_PT_PanelB"
  87.     bl_space_type = 'VIEW_3D'
  88.     bl_region_type = 'UI'
  89.     bl_category = 'Object Adder'
  90.     bl_parent_id = 'VIEW_PT_MainPanel'
  91.     bl_options = {'DEFAULT_CLOSED'}
  92.    
  93.     def draw(self, context):
  94.         layout = self.layout
  95.        
  96.         row = layout.row()
  97.         row.label(text= "Select a Special Option", icon= 'COLOR_BLUE')
  98.         row = layout.row()
  99.         row.operator("object.shade_smooth", icon= 'MOD_SMOOTH', text= "Set Smooth Shading")
  100.         row.operator("object.subdivision_set", icon= 'MOD_SUBSURF', text= "Add Subsurf")
  101.         row = layout.row()
  102.         row.operator("object.modifier_add", icon= 'MODIFIER')
  103.        
  104.  
  105.  
  106.  
  107.  
  108.  
  109. class WM_OT_myOp(bpy.types.Operator):
  110.     """Open the Add Cube Dialog box"""
  111.     bl_label = "Add Cube Dialog Box"
  112.     bl_idname = "wm.myop"
  113.    
  114.     text = bpy.props.StringProperty(name= "Enter Name", default= "")
  115.     scale = bpy.props.FloatVectorProperty(name= "Scale:", default= (1,1,1))
  116.    
  117.    
  118.    
  119.     def execute(self, context):
  120.        
  121.         t = self.text
  122.         s = self.scale
  123.        
  124.         bpy.ops.mesh.primitive_cube_add()
  125.         obj = bpy.context.object
  126.         obj.name = t
  127.         obj.scale[0] = s[0]
  128.         obj.scale[1] = s[1]
  129.         obj.scale[2] = s[2]
  130.        
  131.        
  132.         return {'FINISHED'}
  133.    
  134.     def invoke(self, context, event):
  135.        
  136.         return context.window_manager.invoke_props_dialog(self)
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.        
  144.        
  145.     #Here we are Registering the Classes        
  146. def register():
  147.     bpy.utils.register_class(MainPanel)
  148.     bpy.utils.register_class(PanelA)
  149.     bpy.utils.register_class(PanelB)
  150.     bpy.utils.register_class(WM_OT_myOp)
  151.    
  152.    
  153.  
  154.     #Here we are UnRegistering the Classes    
  155. def unregister():
  156.     bpy.utils.unregister_class(MainPanel)
  157.     bpy.utils.unregister_class(PanelA)
  158.     bpy.utils.unregister_class(PanelB)
  159.     bpy.utils.unregister_class(WM_OT_myOp)
  160.    
  161.     #This is required in order for the script to run in the text editor    
  162. if __name__ == "__main__":
  163.     register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement