Last active
January 1, 2024 11:38
-
-
Save kotobukid/38f72a98427360f90a7be574a96f4490 to your computer and use it in GitHub Desktop.
Blender Add-onサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bl_info = { | |
"name": "Simple UV Editor Panel", | |
"author": "kotobukid", | |
"version": (1, 0), | |
"blender": (4, 0, 1), | |
"location": "UV Editor > Sidebar", | |
"description": "Adds a simple panel to the UV Editor", | |
"category": "UV", | |
} | |
import bpy | |
class MY_OT_EditUVLayout(bpy.types.Operator): | |
bl_idname = "uv.my_edit_uv_layout" | |
bl_label = "Edit UV Layout in External Editor" | |
def execute(self, context): | |
# context.space_dataは、このオペレータが実行されるImage Editorのコンテキストを提供します | |
image = context.space_data.image | |
if image: | |
# 画像の名前とファイルパスを表示 | |
self.report({'INFO'}, f"Image name: {image.name}, File path: {image.filepath}") | |
else: | |
self.report({'INFO'}, "No image is open in this editor.") | |
return {'FINISHED'} | |
# カスタムUIパネルの定義 | |
class SIMPLE_PT_uv_editor(bpy.types.Panel): | |
bl_label = "Simple UV Panel" | |
bl_idname = "SIMPLE_PT_uv_editor" | |
bl_space_type = 'IMAGE_EDITOR' | |
bl_region_type = 'UI' | |
bl_category = 'External Editor' | |
# bl_context = "uv" | |
def draw(self, context): | |
self.layout.label(text="Hello, UV Editor!") | |
self.layout.operator("uv.my_edit_uv_layout") | |
# パネルを登録・登録解除する関数 | |
def register(): | |
bpy.utils.register_class(SIMPLE_PT_uv_editor) | |
bpy.utils.register_class(MY_OT_EditUVLayout) | |
def unregister(): | |
bpy.utils.unregister_class(SIMPLE_PT_uv_editor) | |
bpy.utils.unregister_class(MY_OT_EditUVLayout) | |
# スクリプトが直接実行された場合にregister()を呼び出す | |
if __name__ == "__main__": | |
register() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment