Oct 4 2013

Python in 3ds Max 2014 first impressions..

Well folks, it’s finally here… just a few days ago Autodesk released it’s 3dsmax 2014 extension to those who are members of the subscription program.

This extension release is something that I’ve been very excited about ,and have been looking forward to  ever since the new features were first announced.

Well thankfully the wait is over. I’ve spent some time today checking out the new implementation trying to figure out what this update will mean to future mango development for 3ds max (which I would rather do in python and PySide so that apps can float between Max, Maya, Nuke).

Anyway here are some of my first impressions along with some snippets from today’s familiarization session, I hope they might be insightful.

This is not Blur Python

While evaluating the new python implementation in max 2014, it becomes very hard not to compare it to Blur python. They are both CPython implementations. But that’s about where the similarities end. If you have experience working with Blur Python this first installment of 3dsmax python by autodesk is going to be somewhat of hard pill to swallow.
Unlike Py3dsMax(blur python), maxPlus (autodesk python) does not really expose the same set of libraries and methods that people familiar with maxscript already know and love. Instead it exposed a very small (it’s actually pretty large) subset of the max SDK, and relies heavily on the idea, that programers will do most of the max interactions by writing python string containing max script code.
This string are then to be evaluated by “maxPlus.Core.EvalMAXScript” python method. In my opinion this will alienate allot of people.

  • Those who are familiar with maxscript but are new to python will have to learn a whole new way of working with the limited set of exposed functions, and a brand new methodology behind creating and manipulating objects and data in max. Everything you know about max-script is now obsolete.
  •  Those who looked at python as a bridge to write tools for max with out having to learn maxscript will still have to learn maxscript to access the majority of functions and methods available via maxscript.

I’m hoping that the awkwardness of MaxPlus is just due to it’s infancy, and that in the next year or so it will be expanded to equal or even best blur python. At first glance it seems Autodesk really did the bare minimum. We can only hope that this was a time limitation, and that they will continue to devote time to growing the max python ecosystem.

No Python.import

One of Blur Python’s coolest features was the ability to import python modules right into maxscript via the “python.import” method.
This was really great for production, since any max scripter could use python libraries straight in maxscript with out knowing anything about python. For anyone that has used this feature to quickly harness the power of python external libraries inside of their native maxscript code, this will more than likely be very sad news. I really hope Autodesk can bring this feature back since it opens up the power of python to a much larger sets of users.

Where is PySide/PyQt?

Well not surprisingly Autodesk has decided not include PySide or PyQt with it’s new implementation of Python. The fact that PySide doesn’t come integrated with this first release of python is incredibly disappointing. Especially since I have been running Blur Python (Without Qt) in 2014 for months now, the Autodesk implementation of Python is a major downgrade when compared to Blur Python. This alone will keep me from upgrading current mango clients to this new extension (mango currently uses blur Python).

I really hope that they will spend sometime integrating PySide by the time 3ds max 2015 comes out. Switching from Py3dsMax (Blur Python) to MaxPlus (Autodesk Python) is going to be painful, but a properly supported PySide module would really make the switch worth it.

DIY PySide?

While Autodesk failed to give us an easy to use PySide implemention similar to the ones natively supported in Nuke and Maya, they were nice enough to include some documentation that the more technically inclined can use to compile PySide (that’s right! you going to compile stuff!!) against the proper builds of qt and python that are now bundled with max (Python 2.7.3, Qt 4.8.2). From the documentation hints, I was able to actually make my own image of PySide that allows me to start using Qt inside of 3dsmax 2014. This process while a bit technical and esoteric, is actually not to difficult and requires zero programing experience, I recommend that anyone interested actually try it. If you are too lazy to do it your self,  you can try using my compiled installer (use it at your own risk) , which can be found here .
After installing my newly compiled PySide build, I set to do some basic testing using the following snippets. My initial test was just a QMessageBox…

st = "
import sys
import MaxPlus
from PySide import QtGui, QtCore
msg = 'hello'

n = MaxPlus.Core.GetRootNode()
msg = 'objects in scene:\\n'
for c in n.Children:
	msg += '%s%s%s' % ('\\t',c.Name,'\\n')

msg = str(msg)

app = QtGui.QApplication.instance()
if app == None:
	app = QtGui.QApplication([])

QtGui.QMessageBox.about(None,'PySide',msg)
"
python.execute st

This messagebox was just a way to test that the PySide was actually being loaded and working in max, and that python could collect some data from max and pass it to Qt.

While I was writing this snippet there were a few things that I noticed that seem strange.

  • Modal windows have no effect on the max session. It’s not really clear to me how to parent Qt windows to the max application it self. So modal windows which would usually freeze max until the user close the dialog are not actually freezing max.
  • Executing a QApplication is not needed, doing so actually really screws up the max environment, the behavior makes seem as if qt and python are not running on the main max thread. But I’m more than likely just missing a step.

Other than those strange oddities PySide seems to actually be working. Even with out executing the QApplication I can launch dialogs add widgets via the .show() and exec_() methods. exec_() seems to have absolutely no effect on the max session itself (same as qmessagebox) which is very strange.

Here’s my second test a simple Dialog snippet example…

st = "
from PySide import QtCore, QtGui

class mApp(QtGui.QDialog):
	def __init__(self,parent=None):
		super(mApp,self).__init__(parent)
		vL = QtGui.QVBoxLayout(self)
		for i in range(5):
			cb = QtGui.QComboBox(self)
			vL.addWidget(cb)
		btn = QtGui.QPushButton(self)
		vL.addWidget(btn)
		btn.setText('press me')
		btn.clicked.connect(lambda:QtGui.QMessageBox.about(self,'Modal Test','is this modal?'))

app = QtGui.QApplication.instance()
if app == None:
	app = QtGui.QApplication([''])

ui = mApp()
ui.show()

"
python.execute st

here’s what it looks like..

 

Conclusion

Even though Autodesk’s first version of Python for max leaves a lot to be desired, I’m vary happy that Autodesk has actually taken on the task of bringing this very important feature to max. Not having to depend on a 3rd party to provided python support will make it much easier for studios to migrate to feature version of 3ds max with out fear of breaking their pipeline. With today’s need for python and Qt in the never ending realm of unified pipelines an awkward implementation of python, and a ghetto home brew of PySide are much better than NO PYTHON and NO PYSIDE.

I’m looking forward to experimenting with Mango and 3ds Max using this setup, and seeing what new knowledge tips and tricks the community will bring forth in the upcoming months…

Until next time..

Stay frosty my friends 🙂


Jul 20 2011

converting activeX tabs to dotNet tabs in maxScript (repost)

This is an other repost from an old blog.. i figure i transfer it over 🙂

Ok, so i started updating some scripts that I’ve used tabs for, this is what i have found so far.

the dot net controller syntax for tabs is..

dotNetControl axList "System.Windows.Forms.Tabcontrol"

this makes a tab controller with the variable name of axList
the previous activeX controller would make the tab group and give you one default tab, this is not the same for dotNet tabs. in dotNet Tabs you have to create each tab your self.

adding new tabs is very easy, here’s the syntax to add tabs….

Tab = axList.tabPages.add "myAwsomeTab"

tab information can be access through “tabPages”, for example to query how many tabs there are in the tab controller you can do this…

numberOfTabs = axList.tabPages.count

to query individual tabs you have to use add “.Item” and then the index of the node you want to acess, (keep in mind that dot net controller arrays start at 0 and not at 1 like activeX and maxscript arrays)

firstTab = axList.tapPages.item[0]

this will store the first tab in the tab controller to in the variable first Tab.

if you need to query the or change the selected node there are now two methods to do this

selectedIndex = axlist.selectedIndex
selectedTab = axlist.selectedTab

the last thing i found out is some simple way of changing the appearance of your tabs.

tabStyle = dotNetClass  "System.Windows.Forms.TabAppearance"

this give you a dot net class from which you can apply 1 of the the following 3 styles

apClass.buttons
apClass.flatButtons
apClass.normal

this is how you apply the flatButtons style to your tab controller.

tabStyle = dotNetClass  "System.Windows.Forms.TabAppearance"
axlist.Appearance = apClass.flatButtons

this is what I’ve run into today, i don’t like how the tab’s are highlighted by default when selected i don’t think it is obvious enough. i will play around and see if a can find some good methods of changing that, i might play around with changing the color of selected nodes or something until then, good luck and good night.

cheers,

Los.


Jul 20 2011

controlling Dot Net Fonts in Maxscript (Repost)

This are some old notes, i had posted on another site regarding activeX to dotNet scripting… might be old news but i figured someone might find it usefull 🙂

So today i began to look into dot net controllers inside of max so that i can brake the studios current dependency on max 8 (activeX controller in max 9 don’t work unless 8 is installed),

and while it seem that the general work flow of the activeX controllers carries over to dotNet, there are allot of thing that are not documented and have become way more complex.

the main thing i noticed is dealing with object fonts, sizes, and styles such as bold italic etc, has become a bit more of a chore. here are some of the things i’ve found out, that i couldn’t find any where on the net.

when dealing with tree view nodes under activeX this is how you would change the text

node.font = "Tahoma"
node.fontsize = 7
node.bold = true

this has become a bit more complex in dotNet. a font is now an object value which is created out of sevral other objects and classes…

“fontfamily” this is the actual windows font to use

“fontStyle” this is the style of the text which can be bold , italic, crossed, etc

size can be controlled by a single integer value

so the first thing is to create both of this objects

fontFam = dotNetObject "system.drawing.fontfamily" "tahoma" --this makes the font object
fontStyle = dotNetClass "system.drawing.fontStyle" --this creates a list from which style can be pulled

next we will put it all together

myFont = dotNetObject "system.drawing.font" fontFam 7 fontStyle.bold
--the node font can now be overwritten by this line
node.nodeFont = myFont

anwyas i hope this helps some of you out there some. i will try and make more of this blog as i keep working with the new dotNet controllers in maxscript.

cheers,

Los.