本日はSubstance枠です。
SubstancePainterはBlender同様にPythonコードを実行して自身のプラグインを作成することができます。
今回はどのようにPythonAPIが提供されておりどのように実行するのかについて軽く見ていきます。
〇環境
・Windows 11PC
・SubstancePainter 10.0.0
〇SubstancePainterのスクリプトドキュメント
スクリプトドキュメントはヘルプメニューからアクセスできます。
Pythonの実行はモジュールを作成し、Python
ウィンドウからプラグインフォルダー
よりモジュールを指定することで可能です。
Substance 3D PainterのPython APIは以下のパスにインストールされています: C:\Program Files\Adobe\Adobe Substance 3D Painter\resources\python\modules\substance_painter
Python APIは特定のタスクを実行するための独自のプラグインを作成できます。
〇モジュールの作成
モジュールは以下のパスに作成します。
C:\Users\...\Documents\Adobe\Adobe Substance 3D Painter\python
このディレクトリにはデフォルトで3つのフォルダが存在しています。
startupはSubstance Painter起動時に読み込むモジュールを配置
Pluginsはオプションとして読み込むモジュールを配置する場所
modulesはプラグイン間で共有するモジュールを配置する場所
という形になります。
〇helloworld
ではハローワールドを実行します。
########################################################################## # ADOBE CONFIDENTIAL # ___________________ # Copyright 2010-2020 Adobe # All Rights Reserved. # NOTICE: All information contained herein is, and remains # the property of Adobe and its suppliers, if any. The intellectual # and technical concepts contained herein are proprietary to Adobe # and its suppliers and are protected by all applicable intellectual # property laws, including trade secret and copyright laws. # Dissemination of this information or reproduction of this material # is strictly forbidden unless prior written permission is obtained # from Adobe. ########################################################################## """The hello world of python scripting in Substance 3D Painter """ from PySide2 import QtWidgets import substance_painter.ui plugin_widgets = [] """Keep track of added ui elements for cleanup""" def start_plugin(): """This method is called when the plugin is started.""" # Create a simple text widget hello_widget = QtWidgets.QTextEdit() hello_widget.setText("Hello from python scripting!") hello_widget.setReadOnly(True) hello_widget.setWindowTitle("Hello Plugin") # Add this widget as a dock to the interface substance_painter.ui.add_dock_widget(hello_widget) # Store added widget for proper cleanup when stopping the plugin plugin_widgets.append(hello_widget) def close_plugin(): """This method is called when the plugin is stopped.""" # We need to remove all added widgets from the UI. for widget in plugin_widgets: substance_painter.ui.delete_ui_element(widget) plugin_widgets.clear() if __name__ == "__main__": start_plugin()
こちらのコードをstartupフォルダに配置します。
この状態でSubstancePainterを実行するとHELLO PLUGIN
というUIが表示されます。
ではstart_pluginの中身を少し変えてみます。
def start_plugin(): """This method is called when the plugin is started.""" # Create a simple text widget hello_widget = QtWidgets.QTextEdit() hello_widget.setText("Hi!I am HoloMoto")//変更 hello_widget.setReadOnly(True) hello_widget.setWindowTitle("HoloMoto")//変更
これによってUIも変化したことが確認できました。
以上でSubstancePainterでPythonを実行できました。
本日は以上です。