Guest User

rhubarb pie

a guest
Sep 5th, 2016
12
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. #  This program is free software; you can redistribute it and/or
  4. #  modify it under the terms of the GNU General Public License
  5. #  as published by the Free Software Foundation; either version 2
  6. #  of the License, or (at your option) any later version.
  7. #
  8. #  This program is distributed in the hope that it will be useful,
  9. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. #  GNU General Public License for more details.
  12. #
  13. #  You should have received a copy of the GNU General Public License
  14. #  along with this program; if not, write to the Free Software Foundation,
  15. #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18.  
  19. # <pep8 compliant>
  20.  
  21. bl_info = {
  22.     "name": "Rhubarb pie",
  23.     "author": "Hadrien Brissaud",
  24.     "version": (0, 1),
  25.     "blender": (2, 77),
  26.     "description": "Enable rhubarb pie",
  27.     "category": "User Interface",
  28. }
  29.  
  30. import bpy
  31. from bpy.types import Menu, Operator
  32. from bpy.props import EnumProperty
  33.  
  34. class multiselect(bpy.types.Operator):
  35.     bl_idname = "multi.select"
  36.     bl_label = "multi.select"
  37.     bl_options = {'REGISTER', 'UNDO'}
  38.  
  39.     def execute(self, context):
  40.         layout = self.layout  
  41.         if bpy.context.object.mode != "EDIT":
  42.             bpy.ops.object.mode_set(mode="EDIT")
  43.             bpy.context.tool_settings.mesh_select_mode = (True, True, True)
  44.         if bpy.context.object.mode == "EDIT":
  45.             bpy.context.tool_settings.mesh_select_mode = (True, True, True)
  46.             return {'FINISHED'}
  47.  
  48. class add_mirror(bpy.types.Operator):  
  49.     bl_idname = "add.mirror"
  50.     bl_label = "Add mirror"
  51.     bl_options = {'REGISTER', 'UNDO'}
  52.  
  53.     def execute(self, context):
  54.         bpy.ops.object.modifier_add(type='MIRROR')
  55.         bpy.context.object.modifiers["Mirror"].use_clip = True
  56.         return {'FINISHED'}
  57.  
  58. class VIEW3D_PIE_object_mode(Menu):
  59.     bl_label = "Mode"
  60.  
  61.     def draw(self, context):
  62.         layout = self.layout
  63.  
  64.         pie = layout.menu_pie()
  65.         pie.operator_enum("OBJECT_OT_mode_set", "mode")
  66.  
  67. class VIEW3D_PIE_view_more(Menu):
  68.     bl_label = "More"
  69.  
  70.     def draw(self, context):
  71.         layout = self.layout
  72.  
  73.         pie = layout.menu_pie()
  74.         pie.operator("VIEW3D_OT_view_persportho", text="Persp/Ortho", icon='RESTRICT_VIEW_OFF')
  75.         pie.operator("VIEW3D_OT_camera_to_view")
  76.         pie.operator("VIEW3D_OT_view_selected")
  77.         pie.operator("VIEW3D_OT_view_all")
  78.         pie.operator("VIEW3D_OT_localview")
  79.         pie.operator("SCREEN_OT_region_quadview")
  80.  
  81. class VIEW3D_PIE_view(Menu):
  82.     bl_label = "View"
  83.  
  84.     def draw(self, context):
  85.         layout = self.layout
  86.  
  87.         pie = layout.menu_pie()
  88.         pie.operator_enum("VIEW3D_OT_viewnumpad", "type")
  89.         pie.operator("wm.call_menu_pie", text="More", icon='PLUS').name = "VIEW3D_PIE_view_more"
  90.  
  91.  
  92. class VIEW3D_PIE_shade(Menu):
  93.     bl_label = "Shade"
  94.  
  95.     def draw(self, context):
  96.         layout = self.layout
  97.  
  98.         pie = layout.menu_pie()
  99.         pie.prop(context.space_data, "viewport_shade", expand=True)
  100.  
  101.         if context.active_object:
  102.             if(context.mode == 'EDIT_MESH'):
  103.                 pie.operator("MESH_OT_faces_shade_smooth")
  104.                 pie.operator("MESH_OT_faces_shade_flat")
  105.             else:
  106.                 pie.operator("OBJECT_OT_shade_smooth")
  107.                 pie.operator("OBJECT_OT_shade_flat")
  108.  
  109. class VIEW3D_manipulator_set(Operator):
  110.     bl_label = "Set Manipulator"
  111.     bl_idname = "view3d.manipulator_set"
  112.  
  113.     type = EnumProperty(
  114.             name="Type",
  115.             items=(('TRANSLATE', "Translate", "Use the manipulator for movement transformations"),
  116.                    ('ROTATE', "Rotate", "Use the manipulator for rotation transformations"),
  117.                    ('SCALE', "Scale", "Use the manipulator for scale transformations"),
  118.                    ),
  119.             )
  120.  
  121.     def execute(self, context):
  122.         # show manipulator if user selects an option
  123.         context.space_data.show_manipulator = True
  124.  
  125.         context.space_data.transform_manipulators = {self.type}
  126.  
  127.         return {'FINISHED'}
  128.        
  129. class VIEW3D_PIE_orientation(Menu):
  130.     bl_label = "Orientation"
  131.  
  132.     def draw(self, context):
  133.         layout = self.layout
  134.         ob = context.object
  135.        
  136.         pie = layout.menu_pie()
  137.        
  138.         pie.prop(context.space_data, "transform_orientation", expand=True)
  139.  
  140. class VIEW3D_PIE_pivot(Menu):
  141.     bl_label = "Pivot"
  142.  
  143.     def draw(self, context):
  144.         layout = self.layout
  145.  
  146.         pie = layout.menu_pie()
  147.         pie.prop(context.space_data, "pivot_point", expand=True)
  148.         if context.active_object.mode == 'OBJECT':
  149.             pie.prop(context.space_data, "use_pivot_point_align", text="Center points")
  150.  
  151. class VIEW3D_PIE_snap_target(Menu):
  152.     bl_label = "Snap target"
  153.  
  154.     def draw(self, context):
  155.         layout = self.layout
  156.  
  157.         pie = layout.menu_pie()
  158.         pie.prop(context.scene.tool_settings, "snap_target", expand=True)
  159.         pie.prop(context.scene.tool_settings, "use_snap_align_rotation", icon='SNAP_NORMAL', text="Align to target")
  160.         pie.prop(context.scene.tool_settings, "use_snap_grid_absolute", icon='SNAP_GRID', text="Absolute grid snap")
  161.  
  162. class VIEW3D_PIE_snap_element(Menu):
  163.     bl_label = "Snap element"
  164.  
  165.     def draw(self, context):
  166.         layout = self.layout
  167.  
  168.         pie = layout.menu_pie()
  169.         pie.prop(context.scene.tool_settings, "snap_element", expand=True)
  170.  
  171. class VIEW3D_PIE_manip(Menu):
  172.     bl_label = "Manip"
  173.  
  174.     def draw(self, context):
  175.         layout = self.layout
  176.  
  177.         pie = layout.menu_pie()
  178.        
  179.         pie.operator("view3d.manipulator_set", icon='MAN_TRANS', text="Translate").type = 'TRANSLATE'
  180.         pie.operator("view3d.manipulator_set", icon='MAN_ROT', text="Rotate").type = 'ROTATE'
  181.         pie.operator("view3d.manipulator_set", icon='MAN_SCALE', text="Scale").type = 'SCALE'
  182.         pie.prop(context.space_data, "show_manipulator")
  183.         pie.operator("wm.call_menu_pie", text="Orientation", icon='OUTLINER_OB_EMPTY').name = "VIEW3D_PIE_orientation"
  184.         pie.operator("wm.call_menu_pie", text="Pivot", icon='CURSOR').name = "VIEW3D_PIE_pivot"
  185.         pie.operator("wm.call_menu_pie", text="Snap element", icon='SNAP_SURFACE').name = "VIEW3D_PIE_snap_element"
  186.         pie.operator("wm.call_menu_pie", text="Snap target", icon='SNAP_INCREMENT').name = "VIEW3D_PIE_snap_target"
  187.  
  188. class VIEW3D_PIE_merge_more(Menu):
  189.     bl_label = "Merge"
  190.  
  191.     def draw(self, context):
  192.         layout = self.layout
  193.         ob = context.object
  194.        
  195.         pie = layout.menu_pie()
  196.        
  197.         pie.operator_enum("MESH_OT_merge", "type")
  198.         pie.operator("mesh.remove_doubles", text="Remove doubles")
  199.        
  200. class VIEW3D_PIE_delete(Menu):
  201.     bl_label = "Delete"
  202.    
  203.     def draw(self, context):
  204.         layout = self.layout
  205.         ob = context.object
  206.        
  207.         pie = layout.menu_pie()
  208.  
  209.         if tuple (bpy.context.tool_settings.mesh_select_mode) == (True, False, False):
  210.             pie.operator("mesh.delete", text="Delete faces").type = 'FACE'
  211.             pie.operator("mesh.dissolve_verts", text="Dissolve vertices")
  212.             pie.operator("mesh.delete_edgeloop", text="Delete edgeloop").use_face_split = False
  213.             pie.operator("mesh.delete", text="Delete vertices").type = 'VERT'
  214.        
  215.         elif tuple (bpy.context.tool_settings.mesh_select_mode) == (False, True, False):
  216.             pie.operator("mesh.delete", text="Delete faces").type = 'FACE'
  217.             pie.operator("mesh.dissolve_edges", text="Dissolve edges").use_verts = True
  218.             pie.operator("mesh.delete_edgeloop", text="Delete edgeloop").use_face_split = False
  219.             pie.operator("mesh.delete", text="Delete edges").type = 'EDGE'
  220.  
  221.         elif tuple (bpy.context.tool_settings.mesh_select_mode) == (False, False, True):
  222.             pie.operator("mesh.delete", text="Delete faces").type = 'FACE'
  223.             pie.operator("mesh.dissolve_faces", text="Dissolve faces")
  224.             pie.operator("mesh.delete", text="Delete only faces").type = 'ONLY_FACE'
  225.             pie.operator("mesh.delete", text="Delete only edges and faces").type = 'EDGE_FACE'
  226.  
  227. # définir ce qu'il se passe dans les trois conditions suivantes :
  228.  
  229.         elif tuple (bpy.context.tool_settings.mesh_select_mode) == (True, True, False):
  230.             pie.operator("mesh.delete", text="Delete faces").type = 'FACE'
  231.             pie.operator("mesh.dissolve_verts", text="Dissolve vertices")
  232.             pie.operator("mesh.delete_edgeloop", text="Delete edgeloop").use_face_split = False
  233.             pie.operator("mesh.delete", text="Delete vertices").type = 'VERT'
  234.  
  235.         elif tuple (bpy.context.tool_settings.mesh_select_mode) == (True, False, True):
  236.             pie.operator("mesh.delete", text="Delete faces").type = 'FACE'
  237.             pie.operator("mesh.dissolve_verts", text="Dissolve vertices")
  238.             pie.operator("mesh.delete_edgeloop", text="Delete edgeloop").use_face_split = False
  239.             pie.operator("mesh.delete", text="Delete vertices").type = 'VERT'
  240.  
  241.         elif tuple (bpy.context.tool_settings.mesh_select_mode) == (False, True, True):
  242.             pie.operator("mesh.delete", text="Delete faces").type = 'FACE'
  243.             pie.operator("mesh.dissolve_verts", text="Dissolve vertices")
  244.             pie.operator("mesh.delete_edgeloop", text="Delete edgeloop").use_face_split = False
  245.             pie.operator("mesh.delete", text="Delete vertices").type = 'VERT'
  246.  
  247.         elif tuple (bpy.context.tool_settings.mesh_select_mode) == (True, True, True):
  248.             pie.operator_enum("MESH_OT_delete", "type")
  249.  
  250. class VIEW3D_PIE_separate_more(Menu):
  251.     bl_label = "Separate"
  252.    
  253.     def draw(self, context):
  254.         layout = self.layout
  255.         ob = context.object
  256.        
  257.         pie = layout.menu_pie()
  258.        
  259.         pie.operator_enum("mesh.separate", "type")
  260.  
  261. class VIEW3D_PIE_select_more(Menu):
  262.     bl_label = "Select"
  263.    
  264.     def draw(self, context):
  265.         layout = self.layout
  266.         ob = context.object
  267.        
  268.         pie = layout.menu_pie()
  269.        
  270.         pie.operator("mesh.select_less", text="Contract", icon='FULLSCREEN_EXIT')
  271.         pie.operator("mesh.select_more", text="Expand", icon='FULLSCREEN_ENTER')
  272.         pie.operator("mesh.select_linked", text="Linked")
  273.         pie.operator("mesh.select_all", text="Invert").action = 'INVERT'
  274.         pie.operator("mesh.region_to_loop", text="Boundary loop")
  275.         pie.operator("mesh.loop_to_region", text="Inner-region")
  276.         pie.operator("mesh.select_nth", text="Checker deselect")
  277.         pie.operator("mesh.select_random", text="Random")
  278.  
  279. class VIEW3D_PIE_selection_mode(Menu):
  280.     bl_label = "Selection mode"
  281.    
  282.     def draw(self, context):
  283.         layout = self.layout
  284.         ob = context.object
  285.        
  286.         pie = layout.menu_pie()
  287.        
  288.         pie.operator("view3d.select_circle", text="Circle select")
  289.         pie.operator("view3d.select_border", text="Box select")
  290.  
  291. class VIEW3D_PIE_proportional_mesh(Menu):
  292.     bl_label = "Proportional edit"
  293.  
  294.     def draw(self, context):
  295.         layout = self.layout
  296.         ob = context.object
  297.        
  298.         pie = layout.menu_pie()
  299.        
  300.         pie.prop(context.scene.tool_settings, "proportional_edit", expand=True)
  301.  
  302. class VIEW3D_PIE_mesh(Menu):
  303.     bl_label = "Mesh"
  304.  
  305.     def draw(self, context):
  306.         layout = self.layout
  307.        
  308.         pie = layout.menu_pie()
  309.        
  310.         pie.operator("mesh.select_mode", text="Vertex", icon='VERTEXSEL').type = 'VERT'
  311.         pie.operator("mesh.select_mode", text="Edge", icon='EDGESEL').type = 'EDGE'
  312.         pie.operator("mesh.select_mode", text="Face", icon='FACESEL').type = 'FACE'
  313.         pie.operator("wm.call_menu_pie", text="Select...", icon='EDIT').name = "VIEW3D_PIE_select_more"
  314.         pie.operator("multi.select", text="Multi", icon='LOOPSEL')
  315.         pie.operator("screen.redo_last", text="Last operator", icon='SHORTDISPLAY')
  316.         pie.operator("wm.call_menu_pie", text="Proportional edit", icon='PROP_CON').name = "VIEW3D_PIE_proportional_mesh"
  317.         pie.operator("view3d.snap_cursor_to_selected", text="Cursor to selection", icon='CURSOR')
  318.  
  319.  
  320. class VIEW3D_PIE_mesh_extrude(Menu):
  321.     bl_label = "Extrude"
  322.  
  323.     def draw(self, context):
  324.         layout = self.layout
  325.  
  326.         pie = layout.menu_pie()
  327.        
  328.         op1 = pie.operator(mesh.extrude_region_move(MESH_OT_extrude_region={"mirror":False}, TRANSFORM_OT_translate={"constraint_axis":(False, False, True), "constraint_orientation":'NORMAL'}), text="Extrude straight")
  329.         op1
  330.        
  331.         '''
  332.        extrude_normal_average_op = pie.operator("mesh.extrude_region_move", "transform_translate", text="Extrude straight")
  333.        extrude_normal_average_op.constraint_axis=(False, False, True)
  334.        extrude_normal_average_op.constraint_orientation='NORMAL'
  335.        
  336.        extrude_free_op = pie.operator("mesh.extrude_region_move", text="Extrude free")
  337.        extrude_free_op.constraint_axis=(False, False, False)
  338.        extrude_free_op.constraint_orientation='GLOBAL'
  339.        
  340.        extrude_along_normals_evenly_op = pie.operator("mesh.extrude_region_shrink_fatten", text="Extrude along normals evenly")
  341.        extrude_along_normals_evenly_op.use_even_offset=True
  342.        
  343.        extrude_along_normals_op = pie.operator("mesh.extrude_region_shrink_fatten", text="Extrude along normals")
  344.        extrude_along_normals_op.use_even_offset=False
  345.        
  346.        pie.operator("mesh.extrude_faces_move", text="Extrude individual")
  347.        
  348.        pie.operator("mesh.extrude_vertices_move", text="Extrude vertices")
  349.        pie.operator("mesh.extrude_edges_move", text="Extrude edges")
  350.        '''
  351.  
  352. class VIEW3D_PIE_mesh_tools_more(Menu):
  353.     bl_label = "More tools"
  354.  
  355.     def draw(self, context):
  356.         layout = self.layout
  357.         ob =  context.object
  358.  
  359.         pie = layout.menu_pie()
  360.  
  361.         pie.operator("mesh.symmetrize", text="Symmetrize")
  362.         pie.operator("mesh.bridge_edge_loops", text="Bridge")
  363.         pie.operator("wm.call_menu_pie", text="Separate...").name = "VIEW3D_PIE_separate_more"
  364.         pie.operator("mesh.bisect", text="Bisect")
  365.         pie.operator("mesh.convex_hull", text="Convex hull")
  366.         pie.operator("mesh.intersect", text="Intersect")
  367.         pie.operator("mesh.offset_edge_loops_slide", text="Offset edge loops")
  368.         pie.operator("mesh.fill_grid", text="Grid fill")
  369.  
  370. class VIEW3D_PIE_mesh_tools(Menu):
  371.     bl_label = "Mesh tools"
  372.    
  373.     def draw(self, context):
  374.         layout = self.layout
  375.         ob = context.object
  376.  
  377.         pie = layout.menu_pie()
  378.  
  379.         pie.operator("mesh.loopcut_slide", text="Loopcut")
  380.         pie.operator("mesh.knife_tool", text="Knife")
  381.         if tuple (bpy.context.tool_settings.mesh_select_mode) == (True, False, False):
  382.             bevel_op = pie.operator("mesh.bevel", text="Bevel")
  383.             bevel_op.segments=2
  384.             bevel_op.vertex_only=True
  385.         else:
  386.             pie.operator("mesh.bevel", text="Bevel").segments=2
  387.         pie.operator("wm.call_menu_pie", text="Merge...", icon='AUTOMERGE_ON').name = "VIEW3D_PIE_merge_more"
  388.         pie.operator("mesh.vert_connect", text="Connect")
  389.         pie.operator("mesh.vertices_smooth", text="Smooth")
  390.         pie.operator("mesh.intersect_boolean", text="Boolean")
  391.         pie.operator("mesh.inset", text="Inset")
  392.  
  393. class VIEW3D_PIE_object(Menu):
  394.     bl_label = "Object"
  395.  
  396.     def draw(self, context):
  397.         layout = self.layout
  398.         ob = context.object
  399.         scene = context.scene
  400.        
  401.         pie = layout.menu_pie()
  402.        
  403.         pie.operator("group.objects_add_active", text="Add to active group", icon='ZOOMIN')
  404.         pie.operator("group.objects_remove", text="Remove from group", icon='ZOOMOUT')
  405.         pie.operator("object.join", text="Join", icon ='ROTATECENTER')
  406.         pie.operator("object.select_linked", text="Select by data", icon='MESH_DATA').type='OBDATA'
  407.         pie.operator("add.mirror", text="Add mirror", icon='MOD_MIRROR')
  408.         pie.operator("screen.redo_last", text="Last operator", icon='SHORTDISPLAY')
  409.         pie.prop(scene.tool_settings, "use_proportional_edit_objects", text="Proportional edit")
  410.         pie.operator("view3d.snap_cursor_to_selected", text="Cursor to selection", icon='CURSOR')
  411.  
  412. class VIEW3D_PIE_origin(Menu):
  413.     bl_label = "Set origin"
  414.    
  415.     def draw(self, context):
  416.         layout = self.layout
  417.         ob = context.object
  418.        
  419.         pie = layout.menu_pie()
  420.        
  421.         pie.operator("object.origin_set", text="Geometry to origin").type='GEOMETRY_ORIGIN'
  422.         pie.operator("object.origin_set", text="Origin to geometry").type='ORIGIN_GEOMETRY'
  423.         pie.operator("object.origin_set", text="Origin to center of mass").type='ORIGIN_CENTER_OF_MASS'
  424.         pie.operator("object.origin_set", text="Origin to cursor").type='ORIGIN_CURSOR'
  425.  
  426. class VIEW3D_PIE_proportional_falloff(Menu):
  427.     bl_label = "Falloff"
  428.    
  429.     def draw(self, context):
  430.         layout = self.layout
  431.         ob = context.object
  432.        
  433.         pie = layout.menu_pie()
  434.        
  435.         pie.prop(context.scene.tool_settings, "proportional_edit_falloff", expand=True)
  436.  
  437.  
  438. addon_keymaps = []
  439.  
  440. classes = (
  441.     VIEW3D_manipulator_set,
  442.     VIEW3D_PIE_object_mode,
  443.     VIEW3D_PIE_view,
  444.     VIEW3D_PIE_view_more,
  445.     VIEW3D_PIE_shade,
  446.     VIEW3D_PIE_orientation,
  447.     VIEW3D_PIE_pivot,
  448.     VIEW3D_PIE_snap_target,
  449.     VIEW3D_PIE_snap_element,
  450.     VIEW3D_PIE_manip,
  451.     VIEW3D_PIE_merge_more,
  452.     VIEW3D_PIE_delete,
  453.     VIEW3D_PIE_select_more,
  454.     VIEW3D_PIE_selection_mode,
  455.     VIEW3D_PIE_separate_more,
  456.     VIEW3D_PIE_proportional_mesh,
  457.     VIEW3D_PIE_mesh,
  458.     VIEW3D_PIE_mesh_extrude,
  459.     VIEW3D_PIE_mesh_tools,
  460.     VIEW3D_PIE_mesh_tools_more,
  461.     VIEW3D_PIE_object,
  462.     VIEW3D_PIE_origin,
  463.     VIEW3D_PIE_proportional_falloff,
  464.     add_mirror,
  465.     multiselect,
  466.     )
  467.  
  468. def register():
  469.     for cls in classes:
  470.         bpy.utils.register_class(cls)
  471.  
  472.     wm = bpy.context.window_manager
  473.  
  474.  
  475. def unregister():
  476.     for cls in classes:
  477.         bpy.utils.unregister_class(cls)
  478.  
  479.     wm = bpy.context.window_manager
  480.  
  481.     if wm.keyconfigs.addon:
  482.         for km in addon_keymaps:
  483.             for kmi in km.keymap_items:
  484.                 km.keymap_items.remove(kmi)
  485.  
  486.             wm.keyconfigs.addon.keymaps.remove(km)
  487.  
  488.     addon_keymaps.clear()
RAW Paste Data