How to get it from the window area
----------
>>> bpy.context.screen.areas[3].spaces.active.params.filename
'geometry_nodes\\procedural_hair_node_assets.blend\\NodeTree\\Braid Hair Curves'
[![enter image description here][1]][1]
If the asset browser area on the window has been identified, it is useful to learn the information from the console.
In the example, it is "bpy.context.screen.areas[2]", but the number will vary depending on the environment.
The area can be identified
by https://github.com/Pullusb/devTools
which is an add-on that provides a convenient button on the console.
[![enter image description here][3]][3]
Acquire information via operator
----------------
We already have the code for the answer, but some of the context data accesses have "mechanisms that can only be accessed via the operator".
For example, the following access is only accessible on the operator and not in the area
https://docs.blender.org/api/current/bpy.types.FileSelectEntry.html
Therefore, it is necessary to set up an access button in the area from which to obtain the divestment.
Of course, if you place this button anywhere other than on the asset browser, it will not work.
import bpy
from pathlib import Path
breakpoint = bpy.types.BP_PT_bp.bp
class PrintSelectedAssets(bpy.types.Operator):
bl_idname = "asset.print_selected_assets"
bl_label = "Print Selected Assets"
@classmethod
def poll(cls, context):
return context.selected_asset_files
def execute(self, context):
for asset in context.selected_asset_files:
asset_re_path=asset.relative_path
print("### asset path :",asset_re_path)
return {"FINISHED"}
def display_button(self, context):
self.layout.operator(PrintSelectedAssets.bl_idname)
def register():
bpy.utils.register_class(PrintSelectedAssets)
bpy.types.ASSETBROWSER_MT_editor_menus.append(display_button)
def unregister():
bpy.utils.unregister_class(PrintSelectedAssets)
bpy.types.ASSETBROWSER_MT_editor_menus.remove(display_button)
if __name__ == "__main__":
register()
[![enter image description here][2]][2]
[![enter image description here][4]][4]
[1]: https://i.sstatic.net/IpRIe.png
[2]: https://i.sstatic.net/S4N0Z.png
[3]: https://i.sstatic.net/KZgsx.png
[4]: https://i.sstatic.net/ZAMVg.png