How to make Substance Painter Python plugin (Introduction)

sp_python_1.png

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.

Location of Python API reference

sp_python_2.png

Where to place the script

Python console

#Load module
import substance_painter

#Show module description
help(substance_painter)

#Show project module description
help(substance_painter.project)

Tutorial to make a simple plugin

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.

sp_python_3.png

Other supplements

Recommended Posts

How to make Substance Painter Python plugin (Introduction)
[Introduction to Python] How to parse JSON
[Blender] How to make a Blender plugin
[Introduction to Python] How to use class in Python?
[Python] How to make a class iterable
Spigot (Paper) Introduction to how to make a plug-in for 2020 # 01 (Environment construction)
How to make Spigot plugin (for Java beginners)
[Introduction to Udemy Python3 + Application] 23. How to use tuples
How to install Python
How to install python
Introduction to Python language
[Introduction to Python] How to handle JSON format data
Introduction to OpenCV (python)-(2)
How to make a QGIS plugin (package generation)
[Blender x Python] How to make an animation
[Blender x Python] How to make vertex animation
How to make Python faster for beginners [numpy]
How to make Python Interpreter changes in Pycharm
[Introduction to Python] How to use while statements (repetitive processing)
[Introduction to Python] How to iterate with the range function?
Explain in detail how to make sounds with python
How to make a Python package using VS Code
[Introduction to Udemy Python3 + Application] 27. How to use the dictionary
[Introduction to Udemy Python3 + Application] 30. How to use the set
[Introduction to Python] How to stop the loop using break?
[Introduction to Python] How to write repetitive statements using for statements
[2020.8 latest] How to install Python
How to install Python [Windows]
python3: How to use bottle (2)
[Python] How to use list 1
How to update Python Tkinter to 8.6
Introduction to serial communication [Python]
How to study Bukkit Plugin
Python: How to use pydub
[Python] How to use checkio
How to run Notepad ++ Python
[Introduction to Python] <list> [edit: 2020/02/22]
Introduction to Python (Python version APG4b)
How to change Python version
An introduction to Python Programming
How to develop in Python
[python] How to judge scalar
[Python] How to use input ()
[Introduction] How to use open3d
How to use Python lambda
[Python] How to use virtualenv
Introduction to Python For, While
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
[Introduction to Python] How to write conditional branches using if statements
[Python] How to make a list of character strings character by character
[Python] How to make an adjacency matrix / adjacency list [Graph theory]
[Introduction to Udemy Python 3 + Application] 36. How to use In and Not
How to make a Python package (written for an intern)
[Introduction to Python] How to get data with the listdir function
[Introduction to Udemy Python 3 + Application] 58. Lambda
[Introduction to Udemy Python 3 + Application] 31. Comments
How to write a Python class
[Python] How to FFT mp3 data
[Python] How to do PCA in Python