Starting with Substance Painter 2020.1 (6.1.0), the Python API has been added in addition to the traditional JavaScript API.
[Substance Painter Version 2020 \ .1 \ (6 \ .1 \ .0 ) Release Notes – Born Digital Support](https://support.borndigital.co.jp/hc/ja/articles/900000700626-Substance-Painter -Version-2020-1-6-1-0-% E3% 83% AA% E3% 83% AA% E3% 83% BC% E3% 82% B9% E3% 83% 8E% E3% 83% BC% E3% 83% 88)
However, the official documentation has not yet mentioned the existence of the Python API. It was hard to know where to start, so I'll just make a note of the entrance.
As of SP 2020.2, the Python API version is 0.0.2. Please note that the content of this article is likely to become obsolete soon.
#Load module
import substance_painter
#Show module description
help(substance_painter)
#Show project module description
help(substance_painter.project)
Create plugins / hello_plugin.py
with the following contents.
"""The hello world of python scripting in Substance 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()
Rescan folders with _ "Python> Reload Plugin Folders" _.
There is an item called _ "Python> hello \ _plugin" _, so click it.
If a widget (pane) called "HELLO PLUGIN" is created on the screen, it is successful.
Recommended Posts