アストラルプリズム

PC、スマホ、ゲームなどの備忘録と日記

Blender2.7系 pythonで3dビューのプロパティ・シェルフを操作する

3dビューのプロパティシェルフ(Nキーを押すと右にでてくるやつ)の中身を操作するのがちょっと面倒なのでメモ。

画面は残念ながらBlender2.79なのだけど、まあ2.8も特に変わってないと思いたい。

結構変わってましたorz

2.8系用の説明はこっち。

katsumi3.hatenablog.com

 

以下は2.7系の説明。

f:id:katsumi3:20191212170458p:plain

 

例えばシェーディングのMatcapにチェックを入れたいとして、カーソルを変更したいところにもっていくか操作したとき情報で表示されるコマンドを使えば出来ると思ったら出来ないの。

 

f:id:katsumi3:20191212171610p:plainf:id:katsumi3:20191212173522p:plain

これについて。

まず表示されているウィンドウの中から3dビューを探す。

それにはbpy.context.screen.areasのtypeがVIEW_3Dになってるのを探す。

コンソールに以下を入力してみるとbpy.context.screen.areas[4]に3dビューの情報があるみたいだ。

########################

>> bpy.context.screen.areas[0].type
'INFO'

>>> bpy.context.screen.areas[1].type
'PROPERTIES'

>>> bpy.context.screen.areas[2].type
'CONSOLE'

>>> bpy.context.screen.areas[3].type
'OUTLINER'

>>> bpy.context.screen.areas[4].type
'VIEW_3D'

>>> bpy.context.screen.areas[5].type
'TEXT_EDITOR'

############################

f:id:katsumi3:20191212174848p:plain

で、最初にうまくいかなかったbpy.context.space_data.use_matcap = Trueをちょっと変えて

>>> bpy.context.screen.areas[4].spaces[0].use_matcap = True

とするとMatcapにチェックがつく

f:id:katsumi3:20191212180759p:plain

 

 

その他、トランスフォームの方向を変えたい場合はこんな感じになる。

>>> bpy.context.screen.areas[4].spaces[0].transform_orientation = 'GLOBAL'
(GLOBALのところをNORMALとかLOCALに変える)

f:id:katsumi3:20191212181501p:plain

 

実際のスクリプト

v3d = [x for x in bpy.context.screen.areas if x.type == 'VIEW_3D']

v3d[0].spaces[0].use_matcap = True

 

3dビューを複数出してる場合はv3d[1]とか[2]とか変更したいビューを自分で指定する事。