Python

【Substance3DDesigner】Pythonでウィンドウ作成

shamimatsu

Adobe公式にサブスタンス3Dデザイナーのpythonでウィンドウを作成するコードがありましたが、ボタンが一つあるだけで押しても何も反応しない内容だったので、自作の関数を入れることができる仕組みを追加してみました。

使用バージョン:Substance3DDesiner2023

classは理解が難しく勉強中のため作法として正しくない箇所があるかもしれません

ウィンドウサンプル作成

サンプル内容

スクリプトを実行して表示されるウィンドウにボタンが2つあり、ボタンを押すとコンソールに文字列がプリントされます。
コード内の以下の関数内の書き換えれば別の処理を組み込むことができます。

def on_button1_clicked(self):
def on_button2_clicked(self):

コード

1import sd
2import sys
3from PySide2.QtWidgets import *
4
5
6class MainWindow(QWidget):
7    def __init__(self):
8        super().__init__()
9        app = sd.getContext().getSDApplication()
10        uiMgr = app.getQtForPythonUIMgr()
11
12        mainWindow = uiMgr.getMainWindow()
13        dialog = QDialog(parent=mainWindow)
14        dialog.setWindowTitle("window sample")
15        dialog.resize(300, 200)
16
17        button1 = QPushButton("Button 1")
18        button2 = QPushButton("Button 2")
19
20        layout = QVBoxLayout()
21        layout.addWidget(button1)
22        layout.addWidget(button2)
23        button1.clicked.connect(self.on_button1_clicked)
24        button2.clicked.connect(self.on_button2_clicked)     
25
26        dialog.setLayout(layout)
27
28        dialog.show()
29
30    def on_button1_clicked(self):
31        print("Button 1 clicked.")
32
33    def on_button2_clicked(self):
34        print("Button 2 clicked.")
35
36Window = MainWindow()

参考サイト

アドビ公式:Creating user interface elements

スポンサーリンク

ABOUT ME
shamimatsu
shamimatsu
3DCGデザイナー
ながらくゲーム業界で2D、3DCGデザイナーとして働いてきましたが、新しい業界に挑戦中です。 ブログのデザインをリニューアル中のため、見づらい箇所もあるかもしれませんが少しづつ修正していきます。
記事URLをコピーしました