プロパティ
公式サイト:
Property Definitions (bpy.props) | Blender Python API [Official]
目次
- 1 使い方
- 2 概要
- 3 書き方
- 4 パラメーター
- 5 表示形式 (subtype)
- 6 ブーリアン型 (Bool Property)
- 7 文字列型 (String Property)
- 8 ポインター (Pointer Property)
- 9 列挙型 (Enum Property)
- 10 プロパティグループ (Property Group)
- 11 コレクション (Collection Property)
- 12 ベクトル (FloatVectorProperty)
- 13 更新コールバック (update)
- 14 ゲッター/セッター (getter / setter)
- 15 オペレーターに渡す
- 16 カスタムプロパティ
- 17 デフォルト値を設定する
- 18 プロパティを読み取り専用にする
- 19 プロパティを列挙する
- 20 動的にリストを作成する
- 21 列挙型プロパティの値一覧を取得する
- 22 パスを扱う
- 23 画像シーケンスを扱う
- 24 オブザーバー
- 25 辞書型を使いたい
- 26 基底クラス
- 27 subscribe_rna
- 28 読み取り専用エラー
- 29 Tips
- 30 チュートリアル
使い方
定義
- bpy.props.BoolProperty
- bpy.props.BoolVectorProperty
- bpy.props.CollectionProperty
- bpy.props.EnumProperty
- bpy.props.FloatProperty
- bpy.props.FloatVectorProperty
- bpy.props.IntProperty
- bpy.props.IntVectorProperty
- bpy.props.PointerProperty
- bpy.props.StringProperty
削除
del
delattr
- bpy.props.RemoveProperty
参考:
スクリプトにおいてクラス間で変数を共有する方法 | dskjal
オペレータプロパティを活用する | はじめての Blender アドオン開発
Blender でプロパティを追加して UI で編集する Addon サンプル | トックの CG 部屋
Blender 2.8 で UI パネルに自作のプロパティを追加する | MR が楽しい
Addon のチェックボックスの追加とプロパティへのアクセス | ぬの部屋(仮)
Property Definitions (bpy.props) | Blender Python API [Official]
概要
参考:
プロパティとID プロパティおよび両者の違い | wiki.blender.jp
Blender の RNA プロパティと ID プロパティとの違い | dskjal
Properties, ID-Properties and their differences | wiki.blender.jp
書き方
参考:
ClassVar – typing | Python 3.x ドキュメント [公式]
Class Property Registration | Blender Developer Wiki [Official]
PEP 526 – Syntax for Variable Annotations | Python.org [Official]
Can´t see the inputs in dialog box – Blender Stack Exchange
2.93 update throws error with bpy.props – Blender Stack Exchange
パラメーター
共通
name
description
default
オプション
override
tags
subtype
ハンドラ
update
get
set
表示形式 (subtype)
FloatProperty
'PIXEL'
:ピクセル'UNSIGNED'
:符号なし'PERCENTAGE'
:パーセント'FACTOR'
:係数'ANGLE'
:角度'TIME'
:時間'DISTANCE'
:距離'DISTANCE_CAMERA'
'POWER'
'TEMPERATURE'
:温度'NONE'
:なし
参考:
bpy.types.Property.subtype | Blender Python API [Official]
Display an integer property as a percent? – Blender Artists Community
ブーリアン型 (Bool Property)
参考:
Addon のチェックボックスの追加とプロパティへのアクセス | ぬの部屋 (仮)
bpy.props.BoolProperty | Blender Python API [Official]
文字列型 (String Property)
参考:
bpy.props.StringProperty | Blender Python API [Official]
How to create text input field with Blender Python API? – Blender Stack Exchange
text input field panel – Blender Stack Exchange
ポインター (Pointer Property)
シーンまたはウィンドウマネージャにポインタプロパティを追加する。
def register():
bpy.types.Scene.my_pointer = bpy.props.PointerProperty(type=MyParams)
bpy.types.WindowManager.my_pointer = bpy.props.PointerProperty(type=MyParams)
def unregister():
del bpy.types.Scene.my_pointer
del bpy.types.WindowManager.my_pointer
Code language: Python (python)
参考:
bpy.props.PointerProperty | Blender Python API [Official]
Assigning value to PointerProperty? – Blender Artists Community
How do you access the object that a PointerProperty points to? – Blender Stack Exchange
How to check if a PointerProperty has a value? – Blender Stack Exchange
How to assign PointerProperty in Operator through UI? – Blender Stack Exchange
Limit “prop_search” to Specific Types of Objects – Blender Stack Exchange
New property type: IDPointerProperty – Right-Click Select
Examples of bpy.props.PointerProperty | ProgramCreek.com
列挙型 (Enum Property)
参考:
EnumProperty の選択項目を動的に設定する方法 – Qiita
bpy.props.EnumProperty | Blender Python API [Official]
default_flag – bpy.types.EnumProperty | Blender 2.79 Python API [Official]
Add/remove EnumProperty items? – Blender Artists Community
automatically update EnumProperty from UI Panel – Blender Artists Community
enum property with enum flag – Blender Artists Community
How to go about changing a property to that of another object? – Blender Stack Exchange
プロパティグループ (Property Group)
参考:
Blender 2.8 で UI パネルに自作のプロパティを追加する | MR が楽しい
PropertyGroup | Blender Python API [Official]
How to create text input field with Blender Python API? – Blender Stack Exchange
Using new PointerProperty with custom property – Blender Stack Exchange
Store Pointer Property array / list – Blender Stack Exchange
PointerProperty to node of material node tree – Blender Stack Exchange
Can I create a CollectionProperty of brushes? – Blender Stack Exchange
Get previous value of updated property – Blender Stack Exchange
prop_search with a custom PropertyGroup – Blender Stack Exchange
bpy.types.PropertyGroup properties not updating when changed in Redo Panel – Blender Stack Exchange
コレクション (Collection Property)
参考:
CollectionProperty | Blender Python API [Official]
Collection Example | Blender Python API [Official]
bpy.props.CollectionProperty | Blender Python API [Official]
bpy_prop_collection | Blender Python API [Official]
python/intern/bpy_rna.c at v2.93.0 · blender/blender – GitHub
makesrna/intern/rna_access.c at v2.93.0 · blender/blender – GitHub
Role of “name” in Collection Property – Blender Artists Community
Custom CollectionProperty different from builtin collections? – Blender Artists Community
Adding a Property to a CollectionProperty After Creating it – Blender Stack Exchange
How to get the class type of a Blender Collection Property? – Blender Stack Exchange
change item’s index – Blender Stack Exchange
can’t find update callback for CollectionProperty – Blender Stack Exchange
Combining bpy_prop_collection to use in prop_search() – Blender Stack Exchange
How to create dict from Collection Property? – Blender Stack Exchange
ベクトル (FloatVectorProperty)
参考:
bpy.props.FloatVectorProperty | Blender Python API [Official]
Insert a FloatVectorProperty into a customized interface – Blender Stack Exchange
How to get a vector type from a FloatVectorProperty? – Blender Stack Exchange
更新コールバック (update)
プロパティの値が変更された時に、コールバックを実行する。
参考:
Update Example | Blender Python API [Official]
Updating properties based on object selection state – Blender Artists Community
function update on boolean property – Blender Stack Exchange
How to get an IntProperty to update a function? – Blender Stack Exchange
How to make Blender run check()/redraw when option changed? – Blender Stack Exchange
Temporarily disable add-on UI property update callback – Blender Stack Exchange
poll function for a BoolProperty – Blender Stack Exchange
update function for a custom property? – Blender Artists Community
ゲッター/セッター (getter / setter)
オブジェクトに対して直接に値を設定した場合、コールバックは呼ばれない。
scene['my_prop'] = 123
Code language: Python (python)
プロパティとしてアクセスすると、コールバックが呼ばれる。
scene.my_prop = 123
Code language: Python (python)
参考:
Getter / Setter Example | Blender Python API [Official]
Get previous value of updated property – Blender Stack Exchange
Internal “get / set” function of property? – Blender Stack Exchange
オペレーターに渡す
参考:
Operator Example – Property Definitions | Blender Python API [Official]
How to access variable of other user Class? – Stack Overflow
カスタムプロパティ
オブジェクトにカスタムプロパティを設定する。
object["prop_name"] = 123.45
Code language: Python (python)
カスタムプロパティが未設定の場合に、値を設定する。
if object.get("prop_name") is None:
object["prop_name"] = 123.45
Code language: Python (python)
参考:
Custom Property | Interplanety
Custom Properties | Blender Manual [Official]
custom pointer property is read only? – Blender Artists Community
How to access the variables of a class – Stack Overflow
How do I read out custom properties in Blender with Python? – Stack Overflow
How to check if an object has a custom property with Python? – Blender Stack Exchange
custom pointer property is read only? – Blender Stack Exchange
assign datablock to custom property – Blender Stack Exchange
デフォルト値を設定する
参考:
Property の default 値をユーザー設定にする方法 | 忘却まとめ
How can I change IntProperty default value? – Blender Stack Exchange
How can I change IntProperty default value stored within PropertyGroup? – Blender Stack Exchange
プロパティを読み取り専用にする
ゲッターを指定して、セッターは指定せずにプロパティを定義する。
def get_my_prop(self):
return self['my_prop']
def register():
# ...
bpy.types.Object.my_prop = bpy.proprs.StringProperty(
get=get_my_prop
)
def unregister():
# ...
del bpy.types.Object.my_prop
if __name__ == '__main__':
obj = bpy.context.object
obj['my_prop'] = "Hello!"
Code language: Python (python)
参考:
How to block custom properties from being edited by the user? – Blender Stack Exchange
How can I display a FloatVector without it being editable by the user? – Blender Stack Exchange
プロパティを列挙する
参考:
Walking the Property – Blender Artists Community
動的にリストを作成する
参考:
Can bpy.props be used for dynamic lists? – Blender Developer Talk
列挙型プロパティの値一覧を取得する
参考:
How to get a list with all possible values of an EnumProperty | Interplanety
パスを扱う
参考:
画像シーケンスを扱う
参考:
Setting custom prop to Sequence – Blender Stack Exchange
Setting custom prop to Sequences – Blender Developer Talk
オブザーバー
参考:
Execute function on object property change – Blender Stack Exchange
辞書型を使いたい
参考:
How can I save a dict in a scene propertyGroup? – Blender Stack Exchange
基底クラス
bpy.types.Property
:プロパティの基底クラス
参考:
Property | Blender Python API [Official]
bpy_struct | Blender Python API [Official]
subscribe_rna
参考:
bpy.msgbus.subscribe_rna | Blender Python API [Official]
Update a custom property after leaving edit-mode? – Blender Stack Exchange
読み取り専用エラー
現象:
読み取り専用であるため、プロパティを更新できない旨のエラーが発生する。
AttributeError: bpy_struct: attribute "xxx" from "Hoge" is read-only.
原因:
仕様です。
参考:
Custom pointer property is read only? – Blender Artists Community
How to assign PointerProperty in Operator through UI? – Blender Stack Exchange
Custom pointer property is read only? – Blender Stack Exchange
Tips
参考:
Blender の RNA プロパティと ID プロパティとの違い | dskjal