Advertisement
Guest User

Show Wireframe

a guest
Jun 16th, 2019
106
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.  
  4. class ShowWirerame(bpy.types.Operator):
  5.     bl_idname = "show_wireframe.operator"
  6.     bl_label = "Show wireframe"
  7.     bl_options = {'REGISTER', 'UNDO'}
  8.  
  9.     @classmethod
  10.     def poll(cls, context):
  11.         return context.active_object is not None
  12.  
  13.     def execute(self, context):
  14.         active_object = context.active_object  # Store active object
  15.  
  16.         for obj in context.selected_objects:
  17.             context.view_layer.objects.active = obj
  18.             obj.show_wire = True
  19.             obj.show_all_edges = True
  20.         context.view_layer.objects.active = active_object  # Restore active object
  21.         return {'FINISHED'}
  22.  
  23.  
  24. class HideWirerame(bpy.types.Operator):
  25.     bl_idname = "hide_wireframe.operator"
  26.     bl_label = "Hide Wirerame"
  27.     bl_options = {'REGISTER', 'UNDO'}
  28.  
  29.     @classmethod
  30.     def poll(cls, context):
  31.         return context.active_object is not None
  32.  
  33.     def execute(self, context):
  34.         active_object = context.active_object  # Store active object
  35.  
  36.         for obj in context.selected_objects:
  37.             context.view_layer.objects.active = obj
  38.             obj.show_wire = False
  39.             obj.show_all_edges = False
  40.         context.view_layer.objects.active = active_object  # Restore active object
  41.         return {'FINISHED'}
  42.  
  43.  
  44. class VIEW3D_PT_ShowWirerame(bpy.types.Panel):
  45.     bl_label = "Show Wirerame"
  46.     bl_category = "Show Wirerame"
  47.     bl_space_type = 'VIEW_3D'
  48.     bl_region_type = 'UI'
  49.  
  50.     def draw(self, context):
  51.         layout = self.layout
  52.  
  53.         layout.operator("show_wireframe.operator")
  54.         layout.operator("hide_wireframe.operator")
  55.  
  56.  
  57. def register():
  58.     bpy.utils.register_class(VIEW3D_PT_ShowWirerame)
  59.     bpy.utils.register_class(ShowWirerame)
  60.     bpy.utils.register_class(HideWirerame)
  61.  
  62.  
  63. def unregister():
  64.     bpy.utils.unregister_class(VIEW3D_PT_ShowWirerame)
  65.     bpy.utils.unregister_class(ShowWirerame)
  66.     bpy.utils.unregister_class(HideWirerame)
  67.  
  68.  
  69. if __name__ == "__main__":
  70.     register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement