Home Technical Talk

[3ds Max 2017] Noob Python/PySide Doubts

polycounter lvl 7
Offline / Send Message
EspiSensei polycounter lvl 7
Hi polycounters,

More or less my setup for 3ds max 2017 with python is:
Visual studio Code (with python, MaxScript plugins and MXSPyCOM connects to 3ds Max)
Pyside 1.2.2
Qt 4.8.5 (With QtDesigner)

Actually create a python script ( based on Drew Avis in Max Docs) with simple things, yesterday works more or less by now when I evaluate the script appear this errors:



Later I don't get to understand because inside on Def "buttonClicked" doesn't show me the QMessagebox :(

Here the code:

<div>import os, MaxPlus 
from PySide import QtCore, QtGui

fname = os.path.join(os.path.abspath(os.path.curdir), "my_ui.ui")
ui_type, base_type = MaxPlus.LoadUiType(fname)
print ui_type
print base_type

def buttonClicked():
  """ When you push this button, create spheres with the same name and clear and text again in TextEditor "Hellooo!!" """
  print "pushButton clicked"

  # create a sphere node
  node_name = "my_sphere"
  obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Sphere)
  node = MaxPlus.Factory.CreateNode(obj, node_name)
  MaxPlus.ViewportManager_RedrawViewportsNow(0)# after create the node or other operations its better to refresh de viewports
  print node.GetName()

  # create a Messagebox, with the following Title [Spehere created!]
  msgbox = QtGui.QMessageBox()
  msgbox.setWindowTitle(u'Spehere created!')
  msgbox.exec_()    

def printDate(datetime):
  print datetime.toString()

class MyWidget(base_type, ui_type):
  def __init__(self, parent = None):
    base_type.__init__(self)
    ui_type.__init__(self)
    self.setupUi(self)
    MaxPlus.AttachQWidgetToMax(self)
    pb = self.pushButton
    pb.clicked.connect(buttonClicked)
    self.dateTimeEdit.dateChanged[QtCore.QDate].connect(printDate)

form = MyWidget()
form.show()</div>


thanks for all guys!

Replies

  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    After some 3ds max restarts, now i can evaluate the scripts, i don't understand this :sweat:

  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    Acually I have he same problem, maybe can be the path with space ? or I'm doing wrong with .ui file and Python code? , my actual path is: "C:\Users\sergio.espinosa\AppData\Local\Autodesk\3dsMax\2017 - 64bit\ENU\scripts\Espi"

    thanks!! ^^
  • RN
    Offline / Send Message
    RN sublime tool
    Well the path in the error message is obviously different than the path that you say it should be, that's why the 'file not found' error.
    The code you're using to build the path is probably incorrect, os.path.curdir is referring to the working directory (3ds executable Path), not the user scripts folder.

    A Google search tells that the MaxPlus module has a class for getting paths, including the user scripts folder. Just append 'Espi' to it:
    http://help.autodesk.com/cloudhelp/2017/ENU/Max-Python-API/py_ref/class_max_plus_1_1_path_manager.html#a186e80376821d7e5367adb98190845dd
  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    thank for the help RN, ^^.

    But, it`s weird, because I've created other .py file into the same path ("C:\Users\sergio.espinosa\AppData\Local\Autodesk\3dsMax\2017 - 64bit\ENU\scripts\Espi") and execute perfectly the same .ui file. Maybe 3ds Max need to reset the "os.path.curdir" or another familiar variable of this?.
    I try this because i think this way i could create the scripts ( .py and .ui files) wherever i want without to rewrite the path into the code.
  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    i've discovered something new, if you start max and evaluate your Python script through Visual studio Code or 3ds max Python editor (without open previously the script) this crash, but if you close all the tabs (3ds max Python editor) and reopen the same script, works.  :sweat:
    :sweat:

    Later you can revaluate all times that you want through Visual studio code or 3ds Max editor :sweat:

  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    Hello again polycounters!
    i have some troubles with Qt Designer and 3ds Max about the icons.

    In Qt Designer i got load the icon(in editor and preview modes):


    Here the parameters:

              

    But in 3ds max no:



    the icon is into subfolder (UI/icons/folder-icon.png)
    I tried to save the icon into 3ds max folder "usericons".

    any ideas? :'(

  • monster
    Offline / Send Message
    monster polycounter
    I think it's a bug with pysideuic. Try putting the icon in the same folder as the PY file. Or try using the full path to the icon.

    I just remember icons didn't work in 2017, but they work in 2018.

    In either case, you should consider updating to 2018 or 2019. They removed PySide and replaced it with PySide2, and 2017 was the first version with pysideuic. So any tool you make the UI will be bound to only one version of max.
  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    Cool monster, i''m gonna do this things ^^
  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
     Hi again guys!

    I'm trying to import a custom Python Module (CarVerifierRules.py) but when i evaluate the main.py, show me this error:



    into main.py put this:

    import os, sys, MaxPlus
    from PySide import QtCore, QtGui
    from pymxs import runtime as rt
    from CarVerifierRules import CarVerifierConstant as CarRules

    CarRules.getMissingObjects() #(here show the error)

    class MyWidget(base_type, ui_type):
       #CODEBLOCK

    form = MyWidget()
    form.show()

    and into CarVerifierRules.py  put this:

    import os, sys, json ,MaxPlus
    from pymxs import runtime as rt

    class CarVerifierConstant():
       def __init__(self):
       #CODEBLOCK

       def getMissingObjects(self):
       #CODEBLOCK


    This code works perfectly, the problem is when i want to import this custom module into the main.py
  • Pac_187
    Offline / Send Message
    Pac_187 polycounter lvl 11
    Where is your CarVerifierRules module placed at? Did you add that folder to the sys.path list? It tells python where to search for modules.
  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    Thank you Pac-187! , i just try that, and works! thank you again man! 
Sign In or Register to comment.