Autodesk 3ds Max ships with a pre-built version of PySide 1.2 compatible with Python 2.7.3. This version includes the following sub-set of modules:
The following simple example shows how to obtain a handle for the PySide application object and create a widget:
from PySide import QtGui import MaxPlus class _GCProtector(object): widgets = [] def make_cylinder(): obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Cylinder) obj.ParameterBlock.Radius.Value = 10.0 obj.ParameterBlock.Height.Value = 30.0 node = MaxPlus.Factory.CreateNode(obj) time = MaxPlus.Core.GetCurrentTime() MaxPlus.ViewportManager.RedrawViews(time) return app = QtGui.QApplication.instance() if not app: app = QtGui.QApplication([]) def main(): MaxPlus.FileManager.Reset(True) w = QtGui.QWidget() w.resize(250, 100) w.setWindowTitle('Window') _GCProtector.widgets.append(w) w.show() main_layout = QtGui.QVBoxLayout() label = QtGui.QLabel("Click button to create a cylinder in the scene") main_layout.addWidget(label) cylinder_btn = QtGui.QPushButton("Cylinder") main_layout.addWidget(cylinder_btn) w.setLayout(main_layout) cylinder_btn.clicked.connect(make_cylinder) if __name__ == '__main__': main()
Normally one creates a PySide application object in a script using QtGui.QApplication(). However, in 3ds Max, there is already a PySide application running, so you get a handle for that object like this:
QtGui.QApplication.instance()