2017-10-14 55 views
0

我正在爲Python 3DS Max 2018編寫用戶界面,而且我無法獲取任何文本輸入來工作,儘管到目前爲止我嘗試過的所有操作都正常。由於某種原因,它似乎沒有讀取按鍵。他們正在被Max註冊,它可以做適當的事情,比如當我按下'm'而不是輸入'm'時啓動素材編輯器。我試着打印出按鍵,它看起來像是控制,然後轉換工作。3DS Max 2018 Pyside2 - 文本輸入無法正常工作

我甚至嘗試運行與Max一起提供的示例腳本,並得到相同的錯誤,所以我意識到這可能是某種錯誤,但我不相信Autodesk正在修復它,所以我正在尋找解決辦法...

下面是測試一個例子:

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() 

回答

0

下面是一個簡單的用戶界面,我Autodesks論壇頁面上找到:

http://help.autodesk.com/view/3DSMAX/2018/ENU/?guid=__developer_what_s_new_in_3ds_max_python_api_what_s_new_in_the_3ds_max_2018_p_html

有相當多的不確定性的最大文檔,送花兒給人s已經,但希望它有幫助。我在一個不同的腳本中對此進行了一些編輯,我在控件中添加了自己,以便能夠訪問控件並在不同的功能中設置連接,並且工作得很好。

雖然這是非常糟糕的,我仍然覺得python的實現是笨重和繁瑣的。我仍然喜歡與Maya Python合作,它總是可靠的,但我現在必須與MaxPlus合作。

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() 
+0

這是一個非常乾淨的解決方案,它只是吮吸,你必須繼承每個部件。不過,我已經與Autodesk保持聯繫,他們讓我可以訪問完全解決這個「bug」的功能,並且應該在下一個版本中發佈。不知道它是如何進入第一個版本的,但我想這是每年推出的不利方面! – Spencer