[MaxPlus] Help to understand base nodes

max
python

#1

Hello,

Beginning with the 3dsmax2017 python thing…
I use to daily having fun writing Maya, Python tools.

Basically I have 2 major questions :smile:

1 - object cast from INode.

  • object selection to dummy :

import MaxPlus
sl = MaxPlus.SelectionManager.GetNodes()
for item in sl:
	dummy = MaxPlus.DummyObject._CastFrom(item)
	print("dummy = " + str(dummy))

  • object selection to TriObject :

import MaxPlus
sl = MaxPlus.SelectionManager.GetNodes()
for item in sl:
	tri = MaxPlus.TriObject._CastFrom(item)
	print("tri = " + str(tri))
  • to make a Node from a Geometry, then cast the geometry from the Node :

import MaxPlus

geom = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.TriMeshGeometry)
print("geom = " + str(geom))
node = MaxPlus.Factory.CreateNode(geom)
print("node = " + str(node))
geom = MaxPlus.GeomObject._CastFrom(node)
print("geom = " + str(geom))

All return “None”, then not sure to get it… O_o.//

Mainly looking for get typeOf() an object, but found nothing working with typeOf(), getType(), etc…

Well I think it’s more about understand node hierarchy…
Mainly working with the 3dsmax documentation but not much resource on google :frowning:

2 - to build UI :
I found nothing from MaxPlus, there’s only the QtGui barely supported and it’s like everything should be evaluated from maxscript? O_o… I would like to hear some tips/advise please!
With QtGui idn’t even success to set color, text size, text style, or to create such as column or row, thing there is in Maya… Any equivault? or doc I could learn a bit more about how to build an interface?
Found the maxscript resource but well… it all has to be evaluate with python from maxscript string… O_o…

3 - Started 2 topic on autodesk forum but answer then glad if someone could have an answer also ! :slight_smile:

a- 3dsmax python doc search tool :
http://forums.autodesk.com/t5/3ds-max-programming/maxplus-python-api-documentation-search-tool/td-p/6797304
b- pycharm setup issue :
http://forums.autodesk.com/t5/3ds-max-programming/maxplus-python-api-documentation-search-tool/td-p/6797304

Thanks by advance! ^_-


#2

wow… and just found out the None value the GetChildren(idx) is not a python None constant but a string thing??

Simply select an object without children and run this script :


import MaxPlus
sl = MaxPlus.SelectionManager.GetNodes()
for iNode in sl:
	print(iNode)
	if iNode.GetChild(0) is not None:
		print("child Found")

	if str(iNode.GetChild(0)) != "None":
		print(iNode.GetChild(0))
	else:
		print("no child")

O_o… any explanation… did I miss one more thing?..
:wow:


#3

You are casting it to a string representation yourself, when casted to a string, it will result in a string. MaxPlus python is a direct translation of a .NET wrapper with all the shortcomings, not pythonic at all - for a pythonic experience, use the pymxs wrapper instead.

Here the direct translation of .NET nullable types results in None of type <class ‘MaxPlus.INode’>. It implements nonzero and can be used in bool tests without comparing it to None, like

	if iNode.GetChild(0):
		print "Has Children"
	else:
		print "No Children"

#4

[QUOTE=Swordslayer;30994]You are casting it to a string representation yourself, when casted to a string, it will result in a string. MaxPlus python is a direct translation of a .NET wrapper with all the shortcomings, not pythonic at all - for a pythonic experience, use the pymxs wrapper instead.

Here the direct translation of .NET nullable types results in None of type <class ‘MaxPlus.INode’>. It implements nonzero and can be used in bool tests without comparing it to None, like

	if iNode.GetChild(0):
		print "Has Children"
	else:
		print "No Children"

[/QUOTE]
Oh I see! thank you!
Made a lot of progress this week with MaxPlus, I start to understand the thing…
But pycharm still doesn’t load the Project interpreter and still a pain to work with MaxPlus including slow doc loading and no search tool :frowning:

What about the UI work? Can it be done from MaxPlus? or should it be eval from maxscript only? :frowning:


#5

[QUOTE=sama.van;31003]Oh I see! thank you!
Made a lot of progress this week with MaxPlus, I start to understand the thing…
But pycharm still doesn’t load the Project interpreter and still a pain to work with MaxPlus including slow doc loading and no search tool :frowning:

What about the UI work? Can it be done from MaxPlus? or should it be eval from maxscript only? :([/QUOTE]

I have no idea, sorry :frowning: I only played with python in max a few times before returning to maxscript.


#6

Alright!

Finallly found my way for the UI work using python only.
Actually once you understand how the PySide works including the QtGui and QtCore you can do pretty what you want.

If you come from Maya, check out the QVBoxLayout() and QHBoxLayout(), they are the matching features for columnLayout and rowLayout.
There is also a Grid available, and even more.

Then for the rest you can do pretty what you want, it is pure python oriented then no need the 3dsmax resources which sucks.
Good thing is you can use your UI script for another platform if you wished to.

To add a layout into another layer go with myLayout.addLayout(anotherLayout).
Then to add something to a layout (they call it “Widget”) such as a button, label, image, calendar, etc… go with myLayout.addWidget(yourWidget)

To make it super easy to use, you can build predefined function, to avoid the large amount of code to make a very custom button, etc…

I do not go much in detail for the explanation, but the following exemple I wrote should help to have a better idea.

You can use the demo file from your 3dsmax2017 install folder to connect the 2 following function and be able to play a bit more around it.

  • C:\Program Files\Autodesk\3ds Max 2017\scripts\Python\demoPySideQWidget.py

If you have any questions let me know and I’ll try to help you out! ^_^.
Cheers :slight_smile:


def ButtonRounded(widget, label, color, size, function):
    style_highlight = """
    QPushButton {
    color : #000000;
    font-family: Verdana;
    border-width: 1px;
    border-color: #""" + color + """;
    border-style: solid;
    border-radius: 7;
    background-color: #66cccc;
    }
    """

    qBtn = QPushButton(label)
    qBtn.move(50,0)
    qBtn.setFixedSize(size[0],size[1])
    qBtn.setStyleSheet(style_highlight) 
    # custom font
    qFont = QFont('Tahoma', 10)
    qFont.setBold(True)
    qBtn.clicked.connect(function)
    return qBtn


def ImageButton(path, size, function):

    style_highlight = """
    QPushButton {
    font-family: Verdana;
    border-width: 0px;
    border-style: solid;
    border-radius: 7;
    background-color: rgba(1, 2, 0, 0%);
    }
    """

    qBtn = QPushButton()
    qBtn.setStyleSheet(style_highlight)
    qBtn.setFixedWidth(110)
    qBtn.setFixedHeight(110)
    qBtn.setToolTip('This is a <b>QWidget</b> widget')

    # icon for the button
    qPixmap = QPixmap(path)
    qPixmap2 = qPixmap.scaled(size[0], size[1])
    qBtn.setIcon(qPixmap2)
    qBtn.setIconSize(QSize(size[0], size[1]))
    qBtn.resize(100,100)

    qBtn.clicked.connect(function)

    # label.setGeometry(QRect(rect[0], rect[1], rect[2], rect[3]))
    return qBtn


#7

More resource for building UI with Pyside.
Full Japanese but very well illustrated and the code speaks itself :


#8

Sama, you should look up QWidget inheritance.

Having a set of functions that set properties on a QPushButton is ‘ok’ but not massively expandable, consider the scenario whereby you want to take your custom button and add a little more behaviour. You could create yet another function and modify on top, that would be fine, but it would hit a wall if you want to start overriding/implementing events.

The good news is, Qt is geared up for exactly that, so you could define ImageRounded as a class which inherits from QPushButton, then does the alterations in the init. That way you’d end up with a nice library of widgets which can re-implement at a much lower level and feel native to incorporate into your UI’s.

Food for thought!

Mike.


#9

Thanks MikeM sounds good!

Actually every function I make return the QWidget then I can still access to it at anytime if I store it in any variable.
I aslo made a uiMax class I can access all the time, it make me forget about the PySide. UI I make are simple for now.

My 3dsmax UI started to look like the one I made in Maya then artist from Maya in the team can help the one using the new 3dsmax tool :smiley:

Kind of fun!!
But still having a hard time with MaxPlus, it progresses slowly…