次の項目は別ページに分割しました。
関連ページ:
Blender におけるスクリプトの使い方一般については次のページにまとめています。
目次
- 1 モードを取得/変更する
- 2 値を操作する
- 3 カメラを操作する
- 4 視錘台/カメラに映る範囲を描画する (Camera Frustum)
- 5 レイキャスト/カメラに映っているか判定する
- 6 レンダーリージョンを設定する
- 7 コンストレイントを付与する
- 8 Child Of コンストレイント
- 9 Fカーブを扱う
- 10 モーションパスを扱う
- 11 剛体を扱う
- 12 カーソル位置を取得/設定する
- 13 オーバーレイ (Overlays)
- 14 シェーディング (Shading)
- 15 レンダリングを実行する
- 16 レンダリング条件を変更する
- 17 条件に応じてレンダリングする
- 18 バックグラウンドでの実行を判別する
- 19 アニメーションをレンダリングする
- 20 3D ビューポートを扱う
- 21 3D ビューポートに描画する
- 22 ツールを選択する
- 23 ウィンドウを扱う
- 24 エリアを再描画する
- 25 エリアを分割する
- 26 フルスクリーンで表示する
- 27 マテリアルを変更する
- 28 コレクションを扱う
- 29 アーマチュア/ボーンを扱う
- 30 頂点グループを扱う
- 31 頂点カラーを扱う
- 32 キーフレームを挿入する
- 33 アクションを扱う
- 34 ドライバーを操作する
- 35 カスタムプロファイルを操作する
- 36 カーブマップを操作する
- 37 フレーム/フレームレート (Frame / FPS)
- 38 物理シミュレーションを実行する
- 39 フォントを扱う
- 40 別のスクリプトを呼び出す
- 41 実行中のスクリプト名を取得する
- 42 ファイルのパスを取得する
- 43 ショートカットキーをカスタマイズする (Keymap)
- 44 テーマ/配色を変更する
- 45 初期設定を読み込む
- 46 アドオン一覧を取得する
- 47 アドオンの有効/無効を切り替える
- 48 bps.ops.transform
- 49 operator_menu_enum
モードを取得/変更する
アクティブなエディターの種類を取得する。
Code language: Python (python)area_type = bpy.context.area.type
現在の編集モードを判定する。
if bpy.context.mode == 'OBJECT':
print('In Object Mode')
Code language: Python (python)
オブジェクトモードに切り替える。
if bpy.context.view_layer.objects.active:
bpy.ops.object.mode_set(mode='OBJECT')
Code language: Python (python)
メッシュ編集モードに切り替える。
if bpy.context.view_layer.objects.active:
bpy.ops.object.mode_set(mode='EDIT_MESH')
Code language: Python (python)
参考:
bpy.ops.object.mode_set が context is incorrect で失敗する | ゲーム作りが大好きな人のブログ
bpy.context.area | Blender Python API [Official]
bpy.context.mode | Blender Python API [Official]
bpy.ops.object.mode_set | Blender Python API [Official]
bpy.ops.object.mode_set_with_submode | Blender Python API [Official]
bpy.ops.mesh.select_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
カメラを操作する
参考:
Blender のカメラを Python で操作しよう | Rafka の実験室
How to move a camera in Blender 2.61 with Python – Stack Overflow
Cycles Camera Culling set by Python not triggering – Blender Stack Exchange
視錘台/カメラに映る範囲を描画する (Camera Frustum)
参考:
How do you find the corners of a camera frustum? – Blender Stack Exchange
View camera boundaries in user perspective? – Blender Stack Exchange
レイキャスト/カメラに映っているか判定する
参考:
ray_cast function not able to select all the vertices in camera view – Blender Stack Exchange
レンダーリージョンを設定する
参考:
How to toggle Render Region between camera bounds and marquee-selection? – Blender Stack Exchange
コンストレイントを付与する
参考:
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
モーションパスを扱う
参考:
Convert object motion path to curve – Blender Artists Community
剛体を扱う
参考:
Blender Python で剛体をいっぱい作成 | QCGANIME
カーソル位置を取得/設定する
Code language: Python (python)cursor_location = bpy.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
オーバーレイ (Overlays)
参考:
Operator for Toggling Checkboxes | Interplanety
View3DOverlay.show_overlays | Blender Python API [Official]
can’t find a way to toggle overlay options in 3D View – Blender Artists Community
geometry wireframe shortcut 2.8 – Blender Artists Community
toggle overlays shortcut? – Blender Stack Exchange
grid_scale? – Blender Stack Exchange
Change edge information display in Blender 2.80 with Python – Blender Stack Exchange
access viewport overlay options using Python API – Blender Stack Exchange
How to add buttons from “Overlay” section in custom panel? – Blender Stack Exchange
Customize bpy.context.space_data.overlay.show_stats – Blender Stack Exchange
シェーディング (Shading)
参考:
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
レンダリング条件を変更する
シーンデータブロック (Scene)
render
:レンダリングの設定を保持する RenderSettings のインスタンスresolution_x
:出力画像の幅resolution_y
:出力画像の高さresolution_percentage
:出力解像度の比率 (単位:パーセント)fps
:フレームレートframe_start
:開始フレームframe_end
:終了フレームimage_settings
:出力フォーマットの設定を保持する ImageFormatSettings のインスタンスfile_format
:出力ファイルの形式
filepath
:出力ファイルのパスcamera
:アクティブカメラ
参考:
Python スクリプトでレンダリングを制御 | K-Blender Laboratory
Scene | Blender Python API [Official]
RenderSettings | Blender Python API [Official]
ImageFormatSettings | Blender Python API [Official]
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
バックグラウンドでの実行を判別する
参考:
bpy.app.background | Blender Python API [Official]
Test if .blend is running in background – Blender Stack Exchange
アニメーションをレンダリングする
参考:
3D ビューポートを扱う
参考:
How to access properties of the 3d Viewport? – Blender Stack Exchange
3D ビューポートに描画する
参考:
スクリプトの内部から OpenGL を利用する – Qiita
gpu モジュールを使って図形描画する | はじめての Blender アドオン開発
bpy.types.SpaceView3D.draw_handler_add | Blender Python API [Official]
bpy_extras.view3d_utils | Blender Python API [Official]
How do I get a python reference to the viewport camera? – Blender Stack Exchange
draw_handler_add() and draw_handler_remove() – Blender Stack Exchange
How to draw geometry in 3D View window with bgl – Blender Stack Exchange
How can I add a text help window and a help button into the 3D View? – Blender Stack Exchange
Is automatic “Reload from disk” confirmation in Text Editor possible? – Blender Stack Exchange
コード:
3D View上 の頂点位置を OpenGL で表示する (12funkeys) – GitHub Gist
openGL_test.py の更新版/ポーズモードに対応 (12funkeys) – GitHub Gist
ツールを選択する
参考:
bpy.ops.wm.tool_set_by_id | Blender Python API [Official]
ウィンドウを扱う
参考:
Python API による UI レイアウト、Workspace の制御方法の調査 – Qiita
Screen Operators | Blender Python API [Official]
エリアを再描画する
参考:
イベントタイマーを設定して1秒間に60回画面を更新する – Qiita (archive)
Area.tag_redraw | Blender Python API [Official]
How to force View3D update in the middle of Python script – Blender.org (archive)
Python performance with Blender operators – Blender Stack Exchange
エリアを分割する
参考:
How to split and join Blender interface windows thruough the python API | Interplanety
bpy.ops.screen.area_split | Blender Python API [Official]
フルスクリーンで表示する
参考:
script to view animation preview panel in fullscreen – Blender Stack Exchange
script to toggle fullscreen area – 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 が楽しい
Collection | Blender Python API [Official]
bpy.types.Collection.children | Blender Python API [Official]
CollectionChildren | Blender Python API [Official]
bpy.types.CollectionChildren.link | Blender Python API [Official]
bpy.types.CollectionChildren.unlink | Blender Python API [Official]
New python snippets Blender 2.8x (alchem0x2A) – GitHub Gist
Help adding new scene, collection, objects in 2.8 – Blender Artists Community
Batch exporting scene collections or selected objects using glTF-Blender-IO – Blender Stack Exchange
How to move collection into another collection? – Blender Stack Exchange
What is the Python API for moving a collection? – Blender Stack Exchange
Delete Collection or clear the intial scene in scripting mode – Blender Stack Exchange
How to obtain the parent of a collection using Python – Blender Stack Exchange
How to get all collections of the current scene? – Blender Stack Exchange
disable render of all collections with python in blender 2.8 – Blender Stack Exchange
Sorting Collections Alphabetically in the Outliner – Blender Stack Exchange
アーマチュア/ボーンを扱う
参考:
Blender で Bone の姿勢計算が合わないときの金の針 – Qiita
Blender でスクリプトからボーンにキーフレームを打つ – GitHub Gist
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
Select pose bone in pose mode – Blender Artists Community
How to make a bone active? – Blender Stack Exchange
Set active bone in pose mode from Python script – 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
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
頂点カラーを扱う
- bpy.ops.paint.vert_select_all
- bpy.ops.paint.vertex_color_dirt
- bpy.ops.paint.vertex_color_hsv
- bpy.ops.paint.vertex_color_set
- bpy.ops.paint.vertex_color_smooth
参考:
特定の Vertex Group に対して、Python で色を塗る。 – Qiita
Paint Operators | Blender Python API [Official]
How to paint vertices in different object using python scripts? – Blender Stack Exchange
Changing vertex colors through python – Blender Stack Exchange
set a specified vertex color to black via python – Blender Stack Exchange
Applying per-vertex colors to new Bmesh – Blender Stack Exchange
キーフレームを挿入する
参考:
Blender で音に合わせてキーフレームを打つ | Toshusai blog
Set keyframes using Python script – Blender Artists Community
set keyframe by active object only? – Blender Stack Exchange
modal operator cannot insert keyframe and move object – Stack Overflow
アクションを扱う
参考:
Get bones associated with specific action in 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
How to access driver f-curve data 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
フォントを扱う
フォントディレクトリを取得する。
Code language: Python (python)font_dir = 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 の Python スクリプト実行で別ファイルの関数を利用する | MR が楽しい
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
ショートカットキーをカスタマイズする (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
テーマ/配色を変更する
参考:
How to change a ui color from within the console? – 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
アドオン一覧を取得する
Code language: Python (python)print(bpy.context.preferences.addons.keys())
参考:
bpy.types.Preferences.addons | Blender Python API [Official]
アドオンの有効/無効を切り替える
参考:
Preferences Operators | Blender Python API [Official]
How can I permanently enable an addon in the userpref through Python? – Blender Stack Exchange
Reset all add-ons – Blender Stack Exchange
Cancel addon registering – Blender Stack Exchange
bps.ops.transform
参考:
bpy.ops.transform による変換 | 環耀の備忘録
参考: