Python環境 / API
出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2022/07/09 15:53 UTC 版)
「Blender」の記事における「Python環境 / API」の解説
Blenderには独立したPython環境が搭載されており、Python言語を使用して独自のスクリプトや拡張アドオンを作成することが可能となっている。 BlenderのPython環境には標準で数学モジュールのNumPy/mathutils/bl_mathや、低レイヤーグラフィクスモジュールのgpu/gpu_extras(及び非推奨のbgl)、アプリケーションモジュールのbpyなどが搭載されている。それ以外の拡張モジュールを使うためにはpipなどを使って外部パッケージをBlenderのPython環境にインストールする必要がある。 BlenderのPython APIではアプリケーション情報にbpy.app経由でアクセスする。 import bpyprint(bpy.app.version_string) # Blenderのバージョンを表示 開いているファイルの全データにはbpy.data経由でアクセスし、操作中のデータにはbpy.context経由でアクセスする。データの変更はbpy.msgbusで受け取ることが可能。 import bpyprint(bpy.data.objects['Cube'].location) # 'Cube'オブジェクトの位置を表示print(bpy.context.active_object.rotation_euler) # 選択中のオブジェクトのオイラー角を表示 オペレータの実行はbpy.ops経由で行う。 import bpybpy.ops.transform.resize(value=(2, 2, 2)) # 選択中のオブジェクトを二倍に拡大 オペレータは自前で追加することも可能である。 import bpydef main(context): for ob in context.scene.objects: print(ob)class SimpleOperator(bpy.types.Operator): """ツール tip""" bl_idname = "object.simple_operator" bl_label = "Simple Object Operator" @classmethod def poll(cls, context): return context.active_object is not None def execute(self, context): main(context) return {'FINISHED'}def register(): bpy.utils.register_class(SimpleOperator)def unregister(): bpy.utils.unregister_class(SimpleOperator)if __name__ == "__main__": register() # test call bpy.ops.object.simple_operator()
※この「Python環境 / API」の解説は、「Blender」の解説の一部です。
「Python環境 / API」を含む「Blender」の記事については、「Blender」の概要を参照ください。
- Python環境 / APIのページへのリンク