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.
27 lines
510 B
Python
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()
|