Files
test/scripts/templates_py/ui_asset_shelf.py
Julian Eisel e57726594d Fix missing context attribute access in asset shelf polls
When creating a new main window, the `context.object` attribute wouldn't
exist, causing an error message to be printed.

Rather than checking if the attribute extists, query the mode from
context directly (this is always available), rather than querying it
through the active object.
2023-08-25 19:38:09 +02:00

27 lines
510 B
Python

import bpy
class MyAssetShelf(bpy.types.AssetShelf):
bl_space_type = 'VIEW_3D'
bl_idname = "my_template.my_material_asset_shelf"
@classmethod
def poll(cls, context):
return context.mode == 'OBJECT'
@classmethod
def asset_poll(cls, asset):
return asset.file_data.id_type in {'MATERIAL', 'OBJECT'}
def register():
bpy.utils.register_class(MyAssetShelf)
def unregister():
bpy.utils.unregister_class(MyAssetShelf)
if __name__ == "__main__":
register()