Why is Pie empty when no object in layer Everything works perfect as long as the layer has an object, otherwise the Pie menu will be empty. Is that because I have a camera command in the pie and no object is present that could be used for the camera?

I get the following error:


  mesh = context.active_object.data AttributeError: 'NoneType' object
  has no attribute 'data'




So if yes then I am curious if this is a doable Pie menu when an object has to be present for the Pie menu to work. At least the normal view commands like fullscreen or so should work and be displayed:


Pie Menu Code:

class View(Menu):
    bl_idname = "pie.view"
    bl_label = "View"

    def draw(self, context):
        layout = self.layout

        mesh = context.active_object.data

        pie = layout.menu_pie()
        #4 - LEFT        
        pie.operator("view3d.view_all", text="View All", icon="VIEWZOOM")
        #6 - RIGHT
        pie.operator("view3d.view_selected", text="View Selected", icon="BORDERMOVE")
        #2 - BOTTOM
        pie.operator("screen.screen_full_area", text="Full Screen",icon='FULLSCREEN_ENTER')
        #8 - TOP
        pie.operator("view3d.viewnumpad", text="View Top", icon="TRIA_UP").type='TOP'
        #7 - TOP - LEFT 
        pie.operator("view3D.object_as_camera", text="Set As Active Camera", icon="OUTLINER_DATA_CAMERA")
        #9 - TOP - RIGHT
        pie.operator("view3d.viewnumpad", text="View Camera", icon="OUTLINER_DATA_CAMERA").type='CAMERA'
        #1 - BOTTOM - LEFT
        pie.operator("view3d.viewnumpad", text="View Front", icon="TRIA_LEFT").type='LEFT'
        #3 - BOTTOM - RIGHT
        pie.operator("view3d.viewnumpad", text="View Right", icon="TRIA_RIGHT").type='RIGHT'


Pie View KeyConfig

km = wm.keyconfigs.addon.keymaps.new(name = '3D View Generic', space_type = 'VIEW_3D')
kmi = km.keymap_items.new('wm.call_menu_pie', 'SPACE', 'PRESS', shift=True)
kmi.properties.name = "pie.view"
Replace: 

mesh = context.active_object.data


With:

if context.active_object : 
    mesh = context.active_object.data


By Chebhou