SubstanceDesigner
SubstanceDesigner PythonAPI大解読
SDSBSCompGraph:#3
2024/04/28
![](./thumbnails/SDSBSCompGraph_03.jpg)
実行環境
- SubstanceDesignerバージョン:13.1.1
- PythonAPIバージョン:13.0.0
getPropertyInheritanceMethod
getPropertyInheritanceMethod (sdProperty: sd.api.sdproperty.SDProperty) →
sd.api.sdproperty.SDPropertyInheritanceMethod
Paremeters:
- sdProperty - The property we want to query the inheritance method
リファレンスによると、次のように説明があります。
![](./images/SDSBSCompGraph/03_getpropertyIM_ref.jpg)
この説明だけではなんのこっちゃ分からないので、SDPropertyInheritanceMethod クラスのリファレンスも確認してみます。
![](./images/SDSBSCompGraph/03_sdpropertyIM_ref.jpg)
む。なんだか見慣れた横文字がありますね。。
プロパティの 継承モード を参照する関数とみて間違いないでしょう。
![](./images/SDSBSCompGraph/03_inheritance_method_menu.jpg)
ですが、引数に SDProperty
クラスのオブジェクトを要求しているのが難儀です。。
おそらく、どのプロパティの継承モードを参照したいかを引数で指定するということなのでしょう。
検証するためには、グラフのプロパティのオブジェクト を取得せねばなりません。
![](./images/SDSBSCompGraph/03_IM_menu.jpg)
このあたりはプラグインの開発経験から勘があるので、詳細は後のトピックで触れるとして、ひとまず検証してみます。
import sd
from sd.api.sdproperty import SDPropertyCategory
ctx = sd.getContext()
app = ctx.getSDApplication()
uiMgr = app.getQtForPythonUIMgr()
c_graph = uiMgr.getCurrentGraph()
# カレントグラフのinputプロパティを取得
input_props = c_graph.getProperties(SDPropertyCategory.Input)
for prop in input_props:
print(prop.getId())
# >>
# $outputsize
# $format
# $pixelsize
# $pixelratio
# $tiling
# $randomseed
# OutputSizeプロパティの継承モードを参照
print(c_graph.getPropertyInheritanceMethod(input_props[0]))
# >> SDPropertyInheritanceMethod.RelativeToParent
sd.api.sdproperty.SDPropertyInheritanceMethod
クラスのオブジェクトが返ってきました。
例えば、Relative to Parent になっていないプロパティをチェックするツールなどに応用できるかもしれませんね。
setPropertyInheritanceMethod
setPropertyInheritanceMethod (sdProperty: sd.api.sdproperty.SDProperty, inheritanceMethod: sd.api.sdproperty.SDPropertyInheritanceMethod)
→ None
Paremeters:
- sdProperty - The property we want to set the inheritance method
- inheritanceMethod - The inheritance method to set on the property
こちらは、パラメータの継承モードを指定する関数です。
from sd.api.sdproperty import SDPropertyCategory
from sd.api.sdproperty import SDPropertyInheritanceMethod
c_graph = uiMgr.getCurrentGraph()
# カレントグラフの「OutputSize」パラメータのオブジェクトを取得
p_output_size = c_graph.getPropertyFromId(
"$outputsize", SDPropertyCategory.Input)
# OutputSizeの継承モードを「RelativeToInput」に指定
c_graph.setPropertyInheritanceMethod(
p_output_size, SDPropertyInheritanceMethod.RelativeToInput)
getUID
getUID () → str
グラフのUID (グラフを識別するための重複なしの連番?) を取得するメソッドです。
UIDでグラフを参照するなどの用途で利用するのでしょうか。
c_graph = uiMgr.getCurrentGraph()
uid = c_graph.getUID()
print(uid)
# >> 1502332060
print(type(uid))
# >> class 'str'
reorderGraphInput
reorderGraphInput (inputIdentifier: str, newPosition: int) → None
Paremeters:- inputIdentifier - The Identifier of the input to reorder
- newPosition - The position of the input
グラフのインプットパラメータの並び順を操作するメソッドです。
インプットパラメータの順番は、グラフをノードとして他のグラフに配置した際の入力ピンの順番に影響するため、こういったメソッドが提供されているのはありがたいですね!
![](./images/SDSBSCompGraph/03_graph_input_order.jpg)
第1引数に 移動させるパラメータのID、第2引数に移動先の位置 (整数) を指定するようです。
移動先の位置は、0 スタートです。
c_graph = uiMgr.getCurrentGraph()
# input_1 を一番先頭に移動
c_graph.reorderGraphInput("input_1", 0)
ただし、検証したところ、インプットノードで追加したパラメータ しか操作することができませんでした。。
![](./images/SDSBSCompGraph/03_reorder_input_graph.jpg)
reorderGraphOutput
reorderGraphOutput (outputIdentifier: str, newPosition: int) → None
Paremeters:- outputIdentifier - The Identifier of the output to reorder
- newPosition - The position of the output
グラフのアウトプットパラメータの並び順を操作するメソッドです。
第1引数に 移動させるパラメータのID、第2引数に移動先の位置 (整数) を指定します。
c_graph = uiMgr.getCurrentGraph()
# basecolorを2番目(0スタート)の位置に移動
c_graph.reorderGraphOutput("basecolor", 1)
setDefaultParentSize
setDefaultParentSize (size: sd.api.sdbasetype.int2) → None
Paremeters:- outputIdentifier - The Identifier of the output to reorder
- newPosition - The position of the output
前回の記事 で、グラフのペアレントサイズを取得する getDefaultParentSize を紹介しましたが、こちらはペアレントサイズを指定することができます。
c_graph = uiMgr.getCurrentGraph()
parent_size = sd.api.sdbasetypes.int2()
parent_size.x = 512
parent_size.y = 512
# カレントグラフのペアレントサイズを 512px*512px に指定
c_graph.setDefaultParentSize(parent_size)
setIcon
setIcon(sdTexture: sd.api.sdtexture.SDTexture) → None
Paremeters:- identifier - The new resource identifier
グラフのサムネイルアイコンを指定することができます。
import sd
from sd.api.sdtexture import SDTexture
# ...
c_graph = uiMgr.getCurrentGraph()
# 画像ファイルからSDTextureインスタンスを作成
tex = SDTexture.sFromFile("path_to_image_file")
# カレントグラフのアイコンを指定
c_graph.setIcon(tex)
まとめ
今回で、SDSBSCompGraph クラスのメソッドの調査は完了です。
よりグラフの理解を深めていくためには、親クラスの SDGraph についても調べていく必要がありそうです。