Blender Python API
参考:
Blender Python API Documentation [Official]
使い方
参考:
Blender 2.63 での Python の使い方についてまとめてみた | 凹みTips
Blender でプログラミング 導入編 | 三日坊主のエンジニアBlog
Blender Python の基本 | 三日坊主のエンジニアBlog
Blender 2.80 で UI のスクリプトを書く | dskjal
Blending Into Python Cookbook – Wikibooks
導入
参考:
Blender と Python で 3D モデルを動的生成してレンダリングする | pixiv inside
Python で始める Blender | Rafka の実験室
Blender 2.8 で Python スクリプトを実行してみる | 金子邦彦研究室
Blender × Python でお気楽 3DCG!| Adways エンジニアブログ
Quickstart Introduction | Blender Python API [Official]
テキストエディター/Pythonコンソール (Text Editor / Python Console)
参考:
テキストエディタとコンソール | Blender で Python スクリプト (Takosuke)
Blender 2.8 では、テキストを import できないので as_module() を使う | hzuika
Importing Text | Blender Developer Wiki [Official]
Text Editor | Blender Manual [Official]
Python Console | Blender Manual [Official]
bpy.types.Text.as_module | Blender Python API [Official]
自動実行
参考:
Scripting & Security | Blender Manual [Official]
View scripts so you can know if to trust them – Blender Artists Community
Python auto-execution disabled error – Blender Stack Exchange
データアクセス
参考:
Data Access | Blender Python API [Official]
bpy_struct.path_resolve | Blender Python API [Official]
What is bpy_struct for? – Blender Stack Exchange
set a property via its data path stored in a string – Blender Stack Exchange
プロパティ
参考:
スクリプトにおいてクラス間で変数を共有する方法 | dskjal
オペレータプロパティを活用する | はじめての Blender アドオン開発 (colorful-pico.net)
EnumProperty の選択項目を動的に設定する方法 – Qiita
Property Definitions (bpy.props) | Blender Python API [Official]
オペレーター (Operators)
参考:
Operators (bpy.ops) | Blender Python API [Official]
Example Operator | Blender Python API [Official]
モードを取得/変更する
エディターの種類
bpy.context.area.type
編集モード
bpy.context.mode
参考:
bpy.context.mode | Blender Python API [Official]
Get current editor toolbar tab via Python? – Blender Stack Exchange
値を操作する
データパスで指定された値を操作する。
- context_collection_boolean_set
- context_cycle_array
- context_cycle_enum
- context_cycle_int
- context_menu_enum
- context_modal_mouse
- context_pie_enum
- context_scale_float
- context_scale_int
- context_set_boolean
- context_set_enum
- context_set_float
- context_set_id
- context_set_int
- context_set_string
- context_set_value
- context_toggle
- context_toggle_enum
参考:
Wm Operators | Blender Python API [Official]
about wm.context_toggle confused | Blender Artists Community
How to make a shortcut for this button? – Blender Stack Exchange
ハンドラ
- depsgraph_update_post
- depsgraph_update_pre
- frame_change_post
- frame_change_pre
- load_factory_preferences_post
- load_factory_startup_post
- load_post
- load_pre
- redo_post
- redo_pre
- render_cancel
- render_complete
- render_init
- render_post
- render_pre
- render_stats
- render_write
- save_post
- save_pre
- undo_post
- undo_pre
- version_update
- persistent
参考:
Application Handlers | Blender Python API [Official]
カメラを操作する
参考:
Blender のカメラを Python で操作しよう | Rafka の実験室
How to move a camera in Blender 2.61 with Python – Stack Overflow
コンストレイントを付与する
参考:
How do I add a constraint to an object with Python? – Blender Stack Exchange
Can’t figure out how to use correct contexts? – Blender Stack Exchange
Set resting length for a generic spring constraint – Blender Stack Exchange
Child Of コンストレイント
参考:
Set inverse Child OF constraints via python – Blender Artists Community
Child Of Constraint Set Inverse with Python – Blender Stack Exchange
Fカーブを扱う
参考:
How to smooth curves in Graph Editor by Script – Blender Stack Exchange
剛体を扱う
参考:
Blender Python で剛体をいっぱい作成 | QCGANIME
カーソル位置を取得・設定する
context.scene.cursor.location
参考:
3D Cursor location in Blender 2.8 Python API | Interplanety
Scene.cursor | Blender Python API [Official]
View3DCursor | Blender Python API [Official]
How to set cursor location, pivot_point in script? – Blender Stack Exchange
オーバーレイ
参考:
View3DOverlay.show_overlays | Blender Python API [Official]
geometry wireframe shortcut 2.8 – Blender Artists Community
Toggle Overlays shortcut? – Blender Stack Exchange
Change edge information display in Blender 2.80 with python – Blender Stack Exchange
シェーディング
参考:
updating code sample from v. 2.63 (image rendering and saving) – Blender Stack Exchange
Where Is Shadeless Material Option For Blender 2.8? – Blender Stack Exchange
python code to switch shading mode (between wireframe and solid mode) – Blender Stack Exchange
レンダリングを実行する
参考:
Rendering a cube as png file using Blender’s Python API – Blender Stack Exchange
rendering and saving images through Blender python – Stack Overflow
bpy.ops.render.render() freezes Blender when used in an addon – Blender Stack Exchange
Crashing Blender using bpy.ops.render.render from a different thread – Blender Artists Community
レンダリング条件を変更する
参考:
Python スクリプトでレンダリングを制御 | K-Blender Laboratory
API access for workbench render settings – Blender Stack Exchange
Render specific frames with opengl via python – Blender Stack Exchange
条件に応じてレンダリングする
参考:
Change a Driver based on which Scene is being Rendered – Blender Stack Exchange
3D ビューポートを扱う
参考:
How to access properties of the 3d Viewport? – Blender Stack Exchange
ツールバー/サイドバー
参考:
Get current editor toolbar tab via Python? – Blender Stack Exchange
Tabs in Properties sidebar of the 3D view? – Blender Stack Exchange
ツールを選択する
参考:
bpy.ops.wm.tool_set_by_id | Blender Python API [Official]
エリアを再描画する
参考:
イベントタイマーを設定して1秒間に60回画面を更新する – Qiita
Area.tag_redraw | Blender Python API [Official]
How to force View3D update in the middle of Python script – Blender.org
Python performance with Blender operators – Blender Stack Exchange
マテリアルを変更する
参考:
Changing Viewport Color to Surface Color in Cycles – Blender Artists Community
Rendered object color different from viewport color, set in Python – Blender Stack Exchange
コレクションを扱う
参考:
Blender 2.8 の Python API ドキュメントを少しずつ読み解く クイックスタート その2 | MR が楽しい (bluebirdofoz.hatenablog.com)
Add objects to scene in Blender 2.80 – GitHub Gist
Batch exporting scene collections or selected objects using glTF-Blender-IO – Blender Stack Exchange
Delete Collection or clear the intial scene in scripting mode – Blender Stack Exchange
アーマチュア/ボーンを扱う
参考:
Blender で Bone の姿勢計算が合わないときの金の針 – Qiita
Converting armatures to mesh objects… – Blender Artists Community
How to copy position, size from one armature to another? – Blender Stack Exchange
Convert bones to meshes – Blender Stack Exchange
How to get an armature by name in Python and get access to its bones? – Blender Stack Exchange
頂点グループを扱う
参考:
特定の Vertex Group に対して、Python で色を塗る。- Qiita
how to rename vertex group? – Blender Artists Community
How to batch rename bones and their corresponding vertex groups? – Blender Stack Exchange
Batch rename vertex groups maintaining number heirachy – Blender Stack Exchange
How to modify vertex groups through script – Blender Stack Exchange
Applying per-vertex colors to new Bmesh – Blender Stack Exchange
Finding vertices in a Vertex Group using Blender’s Python API – Blender Stack Exchange
キーフレームを挿入する
参考:
Blender で音に合わせてキーフレームを打つ | Toshusai blog
Set keyframes using Python script – Blender Artists Community
BPy set keyframe by active object only? – Blender Stack Exchange
アクションを扱う
参考:
Get bones associated with specific action in python – Blender Stack Exchange
ノードを操作する
参考:
Set active image node with python – Blender Stack Exchange
How can I get the dimensions of a newly-created material node via Python? – Blender Stack Exchange
ドライバーを操作する
参考:
スクリプトからドライバーをつける & IK/FK 切り替えスイッチの自動セットアップ | dskjal
change the target object of a variable Driver – Blender Artists Community
How Can I modify drivers properties via python in blender? – Blender Stack Exchange
How to put together a driver with python – Blender Stack Exchange
カスタムプロファイルを操作する
参考:
T72422 Bevel Custom Profile: no way to Copy To Selected | Blender Developer [Official]
How do you add custom profile prop to operator (like in bevel operator) – Blender Developer Talk
custom curve – Blender Stack Exchange
カーブマップを操作する
参考:
bpy.types.CurveMap | Blender Python API [Official]
bpy.types.CurveMapPoint | Blender Python API [Official]
bpy.types.CurveMapPoints | Blender Python API [Official]
bpy.types.CurveMapping | Blender Python API [Official]
Add a custom curve mapping property for an add-on? – Blender Stack Exchange
フレーム/フレームレート (Frame / FPS)
参考:
Get/Set Frames per second in blender – Blender Artists Community
物理シミュレーションを実行する
参考:
Blender 2.8 の物理シミュレーションを Python から操作する | Takashi Q. Hanamura Photography
フォントを扱う
フォントディレクトリ:
bpy.context.preferences.filepaths.font_directory
参考:
bpy.types.PreferencesFilePaths.font_directory | Blender Python API [Official]
How to open all fonts at once? – Blender Stack Exchange
How to change font for text objects? – Blender Stack Exchange
コンソールに出力する
参考:
Blender script run print to console – Blender Stack Exchange
スクリプトを実行する
参考:
How to programmatically load a python script in Text Editor and launch it – Blender Stack Exchange
実行中のスクリプト名を取得する
参考:
How to get the active script name? – Blender Artists Community
ファイルのパスを取得する
参考:
How to get the directory of open blend file? (from Python) – Blender Stack Exchange
外部から呼び出す
参考:
blender を python のモジュールとして使う – Qiita
Blender を Python で試してみた | gangan の技術備忘録
ショートカットキーをカスタマイズする (Keymap)
参考:
スクリプト内部で自作の機能にショートカットキーを割り当てる – Qiita
ショートカット (ホットキー) の割り当て方 | Blender.jp フォーラム
custom_key_config.py at master · delorenj/Blender-Stuff – GitHub
Keymap Customization | Blender Manual [Official]
How to make a shortcut for this button? – Blender Stack Exchange
How do you make a shortcut for the Unwrap popup menu? – Blender Stack Exchange
Is it possible to create a modal operator with a modal keymap in Python? – Blender Stack Exchange
Add toggle hotkey to custom checkbox – Blender Stack Exchange
How to register keymaps for all editor types? – Blender Stack Exchange
How can I call a specific keymap to draw within my Addon Preferences? – Blender Stack Exchange
Shortcut to execute a Macro or Script – Blender Stack Exchange
How can I look up or create a shortcut? – Blender Stack Exchange
モーダル
参考:
スクリプトでマウスやキーボードのイベントを扱う方法 – Qiita
Using a key modifier with blender modal – Stack Overflow
How to define double shortcut like GG – Blender Stack Exchange
Call a modal operator from Python and keep its interactivity – Blender Stack Exchange
Is it possible to create a modal operator with a modal keymap in Python? – Blender Stack Exchange
About modal operators in Blender Python – Stack Overflow
Modal Operators: Click Object Event – Blender Stack Exchange
Modal Operator: How to change modifier settings? – Blender Stack Exchange
連続してモーダルオペレーターを実行する
参考:
How to use alternate user inputs and automation – Blender Artists Community
モーダルオペレーターに処理を引き継ぐ
class OBJECT_OT_do_something_and_translate(bpy.types.Operator) def execute(self, context): # ... # Do some operations here # ... return bpy.ops.transform.translate('INVOKE_DEFAULT')
参考:
Call a modal operator from Python and keep its interactivity – Blender Stack Exchange
UI
参考:
Blender の UI を制御する | はじめての Blender アドオン開発 (colorful-pico.net)
UIList | Blender Python API [Official]
ポップアップ
参考:
Blender の UI を制御する 3 | はじめての Blender アドオン開発 (colorful-pico.net)
bpy.types.WindowManager.invoke_popup | Blender Python API [Official]
bpy.types.WindowManager.invoke_prop | Blender Python API [Official]
add panel to invoke_props_dialog – Blender Stack Exchange
パイメニュー
参考:
How to properly overwrite Blender default keys with Pie Menu hotkeys – Blender Stack Exchange
イベント (Event)
参考:
スクリプトでマウスやキーボードのイベントを扱う方法 – Qiita
Event (bpy.types.Event) | Blender Python API [Official]
マクロ (Macro)
参考:
Blender でマクロを作る (Edit, Object Mode 用マクロの例) | Blender とか 3DCG とか (masayuki-osaka.hatenablog.com)
How Use Macro in 2.8? – Blender Developer Talk
Alternate between user input and automation in one-step script – Blender Stack Exchange
Macro operator children are not called from python – Blender Stack Exchange
初期設定を読み込む
参考:
bpy.ops.wm.read_factory_settings | Blender Python API [Official]
How to completely remove all loaded data from Blender? – Blender Stack Exchange
コマンドラインから実行する
参考:
Command Line | wiki.blender.jp
OpenGL
参考:
3Dview 上のオブジェクト頂点位置を取得して OpenGL で表示する | soramame 式
OpenGL Wrapper (bgl) | Blender Python API [Official]
入門
参考:
Python for Blender クックブック 〜はじめに〜 – Qiita
チュートリアル
参考:
Advanced Tutorials/Python Scripting/Introduction – Wikibooks
スニペット/コード断片
参考:
Python for Blender クックブックのレシピ一覧 – Qiita
Blender 2.79 の UI スクリプト集 | dskjal
Code snippets | wiki.blender.jp
Code snippets/Interface | wiki.blender.jp
bps.ops.transform
参考:
bpy.ops.transform による変換 | 環耀の備忘録
operator_menu_enum
参考:
calling “Add Modifier” popup – Blender Artists Community
print
の出力を見るためには Windows の場合はシステムコンソールを開く。Mac の場合はターミナルからアプリではなくバイナリを直接実行する。
Windows の場合
「ウィンドウ (Window)」メニューから「システムコンソール切替え (Toggle System Console)」を選択してシステムコンソールを開く。
Mac の場合
ターミナルから
$ /Applications/Blender.app/Contents/MacOS/Blender
を実行する。
参考:
テキストエディタとコンソール | Blender で Python スクリプト (Takosuke)
Windows 版のシステムコンソールを UTF-8 にする | おじさんからはじめる 3DCG (3dcg.hamken100.com)
ターミナルから Blender を起動 | K-Blender Laboratory
Mac で Blender の Print 結果を表示する | 3DCG と映像と INTERACTIVE (dekapoppo.blogspot.com)
コンソールウィンドウの開き方 | Blender.jp フォーラム
Blender で Python 実行時にエラーを見れない | teratail
blender の python から出力されるログを見たい | teratail
Where is the system console? – Blender Stack Exchange
Where does console output go – Blender Stack Exchange
How to open system console to get output from Blender on Mac OS 10? – Blender Stack Exchange
redirect_stdout
参考:
How to redirect output from ‘bpy.ops.*’? – Blender Stack Exchange
logging
参考:
Logging from Python code in Blender | Blender Developers Blog
Print method isn’t displaying results in the Blender Python Console – Blender Artists Community
UTF8 character issues – Blender Developer Talk
report
参考:
bpy.types.Operator.report | Blender Python API [Official]
Is it possible to print to the Report window in the Info view? – Blender Stack Exchange
How to script add-on info and warnings? – Blender Stack Exchange
RNA
参考:
Blender の RNA プロパティと ID プロパティとの違い | dskjal
驚くべき後方互換性を持つ Blender DNA-RNA システム | Blender.jp
Writing a custom modifier for Blender | exppad
命名規則
クラス名はカテゴリーを大文字で書き、続けて要素の種類をアンダースコアで挟み、操作や要素の名前を小文字 (スネークケース) で続ける。
- パネル (Panel):
CATEGORY_PT_name_xxx
- メニュー (Menu):
CATEGORY_MT_name_xxx
- オペレーター (Operator):
CATEGORY_OT_name_xxx
- UIリスト (UIList):
CATEGORY_UL_name_xxx
bl_idname
は全て小文字で、カテゴリーの後ろにドット (.
) を付けて操作や要素の名前を続ける。
bl_idname = 'category.name_xxx'
参考:
Class naming conventions in Blender 2.8 Python API | Interplanety
What are the class naming conventions for blender? – Blender Stack Exchange
export addon and bl_idname – Stack Overflow
コーディングスタイル
参考:
Requirements for Contributed Scripts | Blender Developer Wiki [Official]
VSCode で開発する
.vscode/settings.json
で Blender が使用する Python 実行バイナリを指定し、コード補完が可能なようにモジュールのパスを追加する。
{ "settings": { "python.pythonPath": "C:\\Program Files\\Blender Foundation\\Blender 2.xx\\2.xx\\python\\bin", "python.autoComplete.extraPaths": [ "C:\\Program Files\\Blender Foundation\\Blender 2.xx\\2.xx\\scripts\\modules" ] } }
参考:
Blender の開発環境を作る | reincarnation Tech
Blender のスクリプトを VSCode から実行 | reincarnation Tech
VSCode でアドオン開発 | reincarnation Tech
Visual Studio Code で Python スクリプトをコーディングする設定 | おじさんからはじめる 3DCG
Tips
参考:
Blender の python スクリプトの Tips | dskjal
バグの原因の見つけ方・潰し方・予防法・よくあるエラー | 忘却まとめ
Best Practice | Blender Python API [Official]
Tips and Tricks | Blender Python API [Official]
Gotchas | Blender Python API [Official]
バージョンアップ
参考:
Blender 2.79 のスクリプトを 2.80 にアップデートする | dskjal
Blender 2.7 と Blender 2.8 での Python API の変更点 | MRが楽しい
Blender の Python スクリプトのコードが 2.80 で動かなかった時に見る記事 – Qiita
2.80 Cheat Sheet for updating add-ons – Blender Artists Community
ビジュアライゼーション
参考:
ptabriz/FOSS4G_workshop: Real-time 3D visualization of geospatial data with Blender – GitHub
API Navigator
**OBSOLETE**
参考:
API Navigator | wiki.blender.jp
API Navigator add-on – Blender Artists Community
T24982 Development : API Navigator | Blender Developer [Official]
Is there a list for all available python functions? – Blender Stack Exchange
Print to Python Console
参考:
Print to Python Console | Interplanety
Print to Python Console | Gumroad
Print to Python console – YouTube
fake-bpy-module
参考:
nutti/fake-bpy-module: Fake Blender Python API module collection for the code completion – GitHub
テキストエディタで Blender の Python API を補完する – Qiita
Linting Blender Python in VSCode – Blender Stack Exchange
Auto-Completion for Blender Python in Any Editor – YouTube
blender-debugger-for-vscode
参考:
How to Remote Debug Blender with VS Code – YouTube
blender_scripter
参考:
ywaby/blender_scripter: blender script develop with vscode – GitHub
Scripting Live-Link
参考:
Scripting Live-Link | Blender Artists Community
How to run a script from outside Blender? (Script Live-Link Addon) | Blender Developer Talk
Blender Development
参考:
Blender Development | Visual Studio Marketplace [Official]
JacquesLucke/blender_vscode: Visual Studio Code extension for Blender development – GitHub
Unable to import ‘bpy’ pylint(import-error) · Issue #51 · JacquesLucke/blender_vscode – GitHub
Blender Python Code Templates
参考:
Blender Python Code Templates | Visual Studio Marketplace [Official]