Skip to main content
Add For Blender4.0
Source Link
mml
  • 734
  • 4
  • 14

For blender4.0

There seems to have been a change in the API. The following are the changes

From selected_asset_files

To selected_assets

https://docs.blender.org/api/current/bpy.context.html#bpy.context.selected_assets

https://docs.blender.org/api/current/bpy.types.AssetRepresentation.html#bpy.types.AssetRepresentation

import bpy from pathlib import Path class PrintSelectedAssets(bpy.types.Operator): bl_idname = "asset.print_selected_assets" bl_label = "Print Selected Assets" @classmethod def poll(cls, context): return context.selected_assets def execute(self, context): for asset in context.selected_assets: asset_path=asset.full_path print("### asset :",asset_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(): for f in bpy.types.ASSETBROWSER_MT_editor_menus._dyn_ui_initialize(): if f.__name__ == display_button.__name__: bpy.types.ASSETBROWSER_MT_editor_menus.remove(f) return if __name__ == "__main__": unregister() register() 

For blender4.0

There seems to have been a change in the API. The following are the changes

From selected_asset_files

To selected_assets

https://docs.blender.org/api/current/bpy.context.html#bpy.context.selected_assets

https://docs.blender.org/api/current/bpy.types.AssetRepresentation.html#bpy.types.AssetRepresentation

import bpy from pathlib import Path class PrintSelectedAssets(bpy.types.Operator): bl_idname = "asset.print_selected_assets" bl_label = "Print Selected Assets" @classmethod def poll(cls, context): return context.selected_assets def execute(self, context): for asset in context.selected_assets: asset_path=asset.full_path print("### asset :",asset_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(): for f in bpy.types.ASSETBROWSER_MT_editor_menus._dyn_ui_initialize(): if f.__name__ == display_button.__name__: bpy.types.ASSETBROWSER_MT_editor_menus.remove(f) return if __name__ == "__main__": unregister() register() 
added 16 characters in body
Source Link
mml
  • 734
  • 4
  • 14

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

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 it is "bpy.context.screen"bpy.context.screen.areas[3]".areas2", 

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

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 operatoronly 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

enter image description here

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

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.areas2", 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

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

enter image description here

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

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[3]". 

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

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

enter image description here

Added how to acquire context information from via operator
Source Link
mml
  • 734
  • 4
  • 14

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

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.areas2", 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

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

enter image description here

>>> bpy.context.screen.areas[3].spaces.active.params.filename 'geometry_nodes\\procedural_hair_node_assets.blend\\NodeTree\\Braid Hair Curves' 

enter image description here

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.areas2", 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

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

enter image description here

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

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.areas2", 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

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

enter image description here

Added how to acquire context information from via operator
Source Link
mml
  • 734
  • 4
  • 14
Loading
Source Link
mml
  • 734
  • 4
  • 14
Loading