Instantly share code, notes, and snippets.
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save nutti/b67b0c9dbbec3cbf0b49 to your computer and use it in GitHub Desktop.
[Blender] プラグインでサブメニューを作成する方法 ref: http://qiita.com/nutti/items/3f75f34adab99a805a35
This file contains hidden or 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
# メニュー | |
class CHoge(bpy.types.Operator): | |
bl_idname = "uv.hoge" # ID名 | |
bl_label = "Hoge Menu" # メニューに表示される文字列 | |
bl_description = "Hoge Piyo" # メニューに表示される説明文 | |
bl_options = {'REGISTER', 'UNDO'} | |
# 実際にプラグインが処理を実施する処理 | |
def execute(self, context): | |
return {'FINISHED'} # 成功した場合はFINISHEDを返す | |
# メニューを登録する関数 | |
def menu_func(self, context): | |
self.layout.operator("uv.hoge") # 登録したいクラスの「bl_idname」を指定 | |
# プラグインをインストールしたときの処理 | |
def register(): | |
bpy.utils.register_module(__name__) | |
bpy.types.VIEW3D_MT_uv_map.append(menu_func) |
This file contains hidden or 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
# Blender内部のデータ構造にアクセスするために必要 | |
import bpy | |
# プラグインに関する情報 | |
bl_info = { | |
"name" : "Hoge Plugin", # プラグイン名 | |
"author" : "Piyo", # 作者 | |
"version" : (0,1), # プラグインのバージョン | |
"blender" : (2, 6, 5), # プラグインが動作するBlenderのバージョン | |
"location" : "UV Mapping > Hoge", # Blender内部でのプラグインの位置づけ | |
"description" : "Hoge Fuga Piyo", # プラグインの説明 | |
"warning" : "", | |
"wiki_url" : "", # プラグインの説明が存在するWikiページのURL | |
"tracker_url" : "", # Blender Developer OrgのスレッドURL | |
"category" : "UV" # プラグインのカテゴリ名 | |
} | |
# サブメニュー | |
class SubMenu(bpy.types.Operator): | |
bl_idname = "uv.hoge_sub" | |
bl_label = "Sub Hoge Menu" | |
out_text = bpy.props.StringProperty() | |
def execute(self, context): | |
self.report({'INFO'}, self.out_text) | |
return {'FINISHED'} | |
# メインメニュー | |
class Menu(bpy.types.Menu): | |
bl_idname = "uv.hoge" | |
bl_label = "Hoge Menu" | |
bl_description = "Hoge Piyo" | |
def draw(self, context): | |
layout = self.layout | |
# サブメニューの登録+出力文字列の登録 | |
layout.operator(SubMenu.bl_idname).out_text = "Sub Hoge Menu" | |
# Editモードにて「U」を押したときに表示されるメニューに登録(bpy.types.VIEW3D_MT_uv_map.append(menu_func)から呼ばれる) | |
def menu_func(self, context): | |
self.layout.separator() # メニューにセパレータを登録 | |
self.layout.menu(Menu.bl_idname) | |
# 登録 | |
def register(): | |
bpy.utils.register_module(__name__) | |
bpy.types.VIEW3D_MT_uv_map.append(menu_func) | |
# プラグインをアンインストールしたときの処理 | |
def unregister(): | |
bpy.utils.unregister_module(__name__) | |
bpy.types.VIEW3D_MT_uv_map.remove(menu_func) | |
# メイン関数 | |
if __name__ == "__main__": | |
register() |
This file contains hidden or 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
# サブメニュー | |
class SubMenu(bpy.types.Operator): | |
bl_idname = "uv.hoge_sub" | |
bl_label = "Sub Hoge Menu" | |
out_text = bpy.props.StringProperty() | |
def execute(self, context): | |
self.report({'INFO'}, self.out_text) | |
return {'FINISHED'} | |
# メインメニュー | |
class Menu(bpy.types.Menu): | |
bl_idname = "uv.hoge" | |
bl_label = "Hoge Menu" | |
bl_description = "Hoge Piyo" | |
def draw(self, context): | |
layout = self.layout | |
# サブメニューの登録+出力文字列の登録 | |
layout.operator(SubMenu.bl_idname).out_text = "Sub Hoge Menu" | |
# Editモードにて「U」を押したときに表示されるメニューに登録(bpy.types.VIEW3D_MT_uv_map.append(menu_func)から呼ばれる) | |
def menu_func(self, context): | |
self.layout.separator() # メニューにセパレータを登録 | |
self.layout.menu(Menu.bl_idname) | |
# 登録 | |
def register(): | |
bpy.utils.register_module(__name__) | |
bpy.types.VIEW3D_MT_uv_map.append(menu_func) |
This file contains hidden or 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
# サブメニュー | |
class SubMenu(bpy.types.Operator): | |
bl_idname = "uv.hoge_sub" | |
bl_label = "Sub Hoge Menu" | |
out_text = bpy.props.StringProperty() | |
def execute(self, context): | |
self.report({'INFO'}, self.out_text) | |
return {'FINISHED'} |
This file contains hidden or 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
# メインメニュー | |
class Menu(bpy.types.Menu): | |
bl_idname = "uv.hoge" | |
bl_label = "Hoge Menu" | |
bl_description = "Hoge Piyo" | |
def draw(self, context): | |
layout = self.layout | |
# サブメニューの登録+出力文字列の登録 | |
layout.operator(SubMenu.bl_idname).out_text = "Sub Hoge Menu" |
This file contains hidden or 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
# Editモードにて「U」を押したときに表示されるメニューに登録(bpy.types.VIEW3D_MT_uv_map.append(menu_func)から呼ばれる) | |
def menu_func(self, context): | |
self.layout.separator() # メニューにセパレータを登録 | |
self.layout.menu(Menu.bl_idname) | |
# 登録 | |
def register(): | |
bpy.utils.register_module(__name__) | |
bpy.types.VIEW3D_MT_uv_map.append(menu_func) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment