Created
January 9, 2023 23:48
-
-
Save BigRoy/97150c7c6f0a0c916418207b9a2bc8f1 to your computer and use it in GitHub Desktop.
Scrape the export formats labels + internal urls from the Substance Painter Export dialog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from PySide2 import QtCore, QtWidgets | |
import substance_painter.js | |
def scrape_export_presets(): | |
app = QtWidgets.QApplication.instance() | |
# Allow app to catch up | |
app.processEvents() | |
dialog = app.activeWindow() | |
assert dialog, "A window must be active now" | |
assert dialog.windowTitle() == "Export textures", "Export Textures dialog must be visible" | |
app.processEvents() | |
presets = {} | |
for box in dialog.findChildren(QtWidgets.QComboBox): | |
# Let's assume the box we want has both 'Sketchfab' and '2D View' | |
if box.findText("Sketchfab") == -1: | |
continue | |
if box.findText("2D View") == -1: | |
continue | |
model = box.model() | |
for y in range(model.rowCount()): | |
item = model.item(y) | |
label = item.text() | |
print(label) | |
try: | |
url = item.data(QtCore.Qt.UserRole + 1) # url role? | |
presets[url.toDisplayString()] = label | |
except (RuntimeError, AttributeError): | |
print('NO URL') | |
dialog.close() | |
data = json.dumps(presets, indent=4) | |
print(data) | |
QtCore.QTimer.singleShot(0, scrape_export_presets) | |
substance_painter.js.evaluate("alg.mapexport.showExportDialog()") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output from Substance Painter 8.2.0:
Substance Painter
export-preset-generator
entriesAnd that makes the export preset generator entries like this from URL to label.