I am writing a UI in python for 3DS Max 2018 and I cannot get any text input to work, though everything else I have tried so far works fine. It just doesn't seem to read the keystrokes for some reason. They are being registered by Max instead, which does the appropriate things like launching the material editor when I press 'm' instead of typing an 'm'. I tried printing out keypresses and it looks like control, alt and shift work though.
I even tried running the example scripts that ship with Max and got the same error, so I realize this is probably a bug of some sort however I have no faith in Autodesk fixing it right now so I'm looking for a workaround...
Here's an example for testing:
from PySide2 import QtWidgets, QtCore, QtGui
import MaxPlus
import os
class SampleUI(QtWidgets.QDialog):
def __init__(self, parent=MaxPlus.GetQMaxMainWindow()):
super(SampleUI, self).__init__(parent)
self.initUI()
def initUI(self):
self.testBtn = QtWidgets.QPushButton("Test")
mainLayout = QtWidgets.QHBoxLayout()
testBox = QtWidgets.QLineEdit("Test!")
mainLayout.addWidget(testBox)
self.setLayout(mainLayout)
if __name__ == "__main__":
try:
ui.close()
except:
pass
ui = SampleUI()
ui.show()
Here is a simple ui that I found on Autodesks forum page:
There is quite a lot of ambiguity in the max docs, always has been, but hope it helps. I made some edits to this in a different script, where I added self to the controls to be able to access controls and to setup the connections in a different function and it works pretty well.
This is very blasé though and I still feel the python implementation is clunky and cumbersome. I still prefer to work with Maya Python, its always been reliable, but I have to work with MaxPlus for now.
from PySide2 import QtWidgets, QtCore, QtGui
import MaxPlus
import os
class SuperDuperText(QtWidgets.QLineEdit):
def focusInEvent(self, event):
MaxPlus.CUI.DisableAccelerators()
def focusOutEvent(self, event):
MaxPlus.CUI.EnableAccelerators()
class SuperDuperUI(QtWidgets.QDialog):
def __init__(self, parent=MaxPlus.GetQMaxMainWindow()):
super(SuperDuperUI, self).__init__(parent)
self.setWindowTitle("Sample UI")
self.initUI()
def initUI(self):
mainLayout = QtWidgets.QVBoxLayout()
maxScriptsDir = MaxPlus.PathManager.GetScriptsDir()
testLabel = QtWidgets.QLabel("Your scripts dir is: " + maxScriptsDir)
mainLayout.addWidget(testLabel)
testBtn = QtWidgets.QPushButton("This does nothing.")
mainLayout.addWidget(testBtn)
testEdit = SuperDuperText()
testEdit.setPlaceholderText("You can type in here if you like...")
mainLayout.addWidget(testEdit)
self.setLayout(mainLayout)
if __name__ == "__main__":
try:
ui.close()
except:
pass
ui = SuperDuperUI()
ui.show()