Skip to content

Instantly share code, notes, and snippets.

@satishgoda
Last active December 10, 2015 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satishgoda/4394720 to your computer and use it in GitHub Desktop.
Save satishgoda/4394720 to your computer and use it in GitHub Desktop.
SCREEN_OT_toggle_grid.py : Blender 2.65a Python Operator : Toggles the Grid display in all 3D Views for the current screen"
# http://learningblender3dsoftware.blogspot.in/2012/12/learning-about-operators-2-screen.html
import bpy
def main(context):
screen = context.screen
for area in screen.areas:
if area.type == 'VIEW_3D':
active_space = area.spaces[0]
attrs = ['show_floor', 'show_axis_x', 'show_axis_y', 'show_axis_z']
for attr, toggle in map(lambda attr: (attr, getattr(active_space, attr)), attrs):
setattr(active_space, attr, not toggle)
class SCREEN_OT_toggle_grid(bpy.types.Operator):
"""Toggles the Grid display in all 3D Views for the current screen"""
bl_idname = "screen.toggle_grid"
bl_label = "Screen Toggle Grid"
bl_options = {'REGISTER'}
def execute(self, context):
main(context)
return {'FINISHED'}
def register():
bpy.utils.register_class(SCREEN_OT_toggle_grid)
def unregister():
bpy.utils.unregister_class(SCREEN_OT_toggle_grid)
if __name__ == "__main__":
register()
# test call
bpy.ops.screen.toggle_grid()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment