[3dsMax 2015][PySide] Selection not refreshing in viewport when tool open

I’ve created a tool in python for 3dsMax and created the UI in Qt Designer. The tool class is defined as you would in Maya, by loading the UI file and extracting the form, and base classes.

When I open the tool in 3dsMax, it works, however the 3dsMax viewport selections do not refresh. The white highlight doesn’t appear or disappear regardless of whether I select or deselect. Furthermore transformations are doubling values. For instance translating an object will send it shooting beyond the location of the cursor…

Someone from the forums was kind enough to put together a decorator function to protect from GC a python script. Unfortunately this didn’t resolve the issue, so I went ahead and made a few tests.

First I ran this code:

class TestTool(QtGui.Widget):
    pass

testTool = TestTool()
testTool.show()

The issue persisted. So then I added the decorator function…

@MaxWindow
class TestTool(QtGui.Widget):
    pass

testTool = TestTool()
testTool.show()

Lo’ and behold everything works as intended. I then decided to take it a step further and initialize the superclass.

@MaxWindow
class TestTool(QtGui.Widget):
    def __init__(self):
        super(TestTool, self).__init__()

testTool = TestTool()
testTool.show()

Back to square one, the viewports don’t refresh, etc…

Does anyone know how I can bring in a QMainWindow I designed in Qt Designer into 3dsMax without causing these kind of issues?

Are you using: sys.exit(app.exec_()) ? if so, don’t.

Check this for a simple pyside example: https://github.com/arturleao/YCDIVFX_MaxPlus/blob/master/Examples/pyside_simple.py

That was it. I remove the sys.exit(app.exec_()) everything is as intended. Thanks Kameleon!

You’re welcome, just remember to get that _gcprotector object like I have in the example to protect the objects from being garbage collected.