Notifications
Clear all

[Closed] 3dsmax 2017 Python

Has anybody tried the new python functions?
I’m having a hard time getting python to output anything at all… Maxscript print function works just fine, but python print doesn’t do anything. Neither does pymxs.print_(), or MaxPlus.Core.Print(). Even sys.stdout.write() gives me nothing…

I tried the following code from the docs, which states it should output the class of a teapot, but nothing shows up.

>>> import pymxs 
>>> rt = pymxs.runtime 
>>> t = rt.Teapot() 
>>> rt.classOf(t)

Further, when trying to get the max qt window, i get an import error:

Traceback (most recent call last):
  File "C:\Program Files\Autodesk\3ds Max 2017\MaxPlus.py", line 40340, in <<module>>
  File "C:\Program Files\Autodesk\3ds Max 2017\MaxPlusExtend.py", line 282, in <<module>>
ImportError: DLL load failed: %1 is not a valid Win32 application.

Has anybody else got these problems, or should I try a reinstall?

Uhmm, do you by any chance have blur python installed? There seems to be some dll loading errors that may be due to some wrong libraries loading.

denisT, you can build cpython extensions, accessing the MaxSDK, MaxPlus is a module that expose part of the SDK. We can still build mxs extensions and just called them using the pymxs.runtime.
I did made one work, but its to give access to .NET from cpython.

1 Reply
(@kolruds)
Joined: 10 months ago

Posts: 0

Thanks, but no, on my 2017 install there is nothing else. I still have 2014-2016 installed, and a local python2.7 thats 32 bit. I’m thinking at least for my PySide import errors, this might be causing problems. The 2017 python looks in the PATH variable as well, and there it will find a 32bit PySide install.
But that does not explain why MaxPlus won’t import.
pymxs module worked fine, and I did get the print_() function working, but does seem to crash max a couple of times.

Works as expected:

>>> import pymxs 
>>> rt = pymxs.runtime 
>>> print rt
<pymxs.runtime object at 0x00000000821BF090>
>>> t = rt.Teapot()
>>> print t
$Teapot:Teapot001 @ [0.000000,0.000000,0.000000]
>>> rt.classOf(t)
<GeometryClass<Teapot>>
1 Reply
(@kolruds)
Joined: 10 months ago

Posts: 0

Do you have a python install on your computer outside of max? If so, 32bit?

I did find a solution, but I’m not exactly sure what was the problem.
I completely removed python from my machine, including site-packages and pythonpath. When I started max after that, everything works as expected.
The docs states that environment variables is loaded last, but in my sys.path, they showed up first. I suspect python in max loaded stuff from my local python install, which is 32bit, whereas max uses 64bit python.
I will try reinstalling python, and keep testing with max until I find the error, if I can recreate it.

I have more than one other python install, 2.4.4 32-bit and 2.6.1 x64. Could you share the code that was throwing that error? I’ve only tried the demoPySideQWidget.py

The 2.6.1 x64 is your main one?
Mine was 2.7.8 x86, so I suspect there was problems with max trying to import from my pythonpath, and finding x86 libs, when expecting x64.
I had problems with the following commands

import MaxPlus
from PySide.QtCore import *
from PySide.QtGui  import *

They would throw an importerror. I didn’t try any of the examples.
I also had problems getting output, with normal python print and MaxPlus.Core.Print. However printing in maxscript did work, so I did get pymxs.print_() working, but this crashed max half the time.
After reinstalling python I didnt experience these problems anymore, so I guess there were some conflicts there, though I’m not sure exactly what caused the problems. It was an old installation with a bunch of installed stuff, so I wouldn’t be surprised if that was the case.
I think I’ll start using more virtual environments from now on!

Yes, the x64 version is the one I’m using and PYTHONPATH points there.

To stay on topic, I really like this release and both the pymxs and how easy it is now to use python modules from maxscript:

builtin = python.import "__builtin__"
itertools = python.import "itertools"

builtin.list(itertools.repeat 10 5) as array
builtin.all #{1..5,7}

And yet the whole python rebirth is only mentioned in passing…

1 Reply
(@davewortley)
Joined: 10 months ago

Posts: 0

Yep I’m really excited for what this means, Autodesk need some good feedback, any bugs and anything missing because it’s a massively complex integration, I think there is still work to do so lets make sure they know what is and isn’t working!

This feels like python in Max that we can actually use. Looks promising!


global mxsPythonHelper

struct mxsPythonHelperStruct
(
	py =  python.import("__builtin__"),
	json = python.import("json"),
	

	fn buildPyDictFromArray keyArray valueArray = 
	(	
		local pyDict
		if keyArray.count == valueArray.count then
		(		
			pyDict = py.dict()
			for each = 1 to keyArray.count do				
				pyDict[keyArray[each]] = valueArray[each]		
		)
		pyDict		
	),	
	

	fn writeJson file data =
	(		
		jsonFile = py.open file "wb"
		json.dump data jsonFile indent:4
		jsonFile.close()
		
	),
	
	fn readJson file asDataPair:false =
	(
		jsonFile = py.open file "r"
		dLoad =json.load jsonFile
		jsonFile.close()
		
		if asDatapair then
			for each in (dLoad.items() as array) collect (dataPair key:each[1] value:each[2])
		else
			dLoad
	)	
)

mxsPythonHelper = mxsPythonHelperStruct()
dictObj = mxsPythonHelper.buildPyDictFromArray #("woop", "yeah", "cmon") #(true, "meh", 2017)
strJPath =  @"C:\Users\Pete\Desktop\Woop.json" 

mxsPythonHelper.writeJson strJPath dictObj

rj = mxsPythonHelper.readJson strJPath asDatapair:true

Is this the right way of doing things like list>array casting etc?

edit: Ah ha, worth looking at this file as mentioned in the help

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

gives a little more info about casting types

Hey Guys,

Really looking forward to this python integration…(starting to feel more like an Autodesk Application) removing the need to use maxscript, like they did with mel in Maya… will be a very good thing.

Question, if anyone knows.(nothing in the docs about it)
In Maya, there is a userSetup.py file that runs when Maya opens.
In 3dsMax, it looks for a startup.ms file when max opens.
Any Python Equivalent to this in Max? startup.py perhaps? (tried it, didn’t work)

thanks
-Dan

You can just put anyscript into script\startup folder.

Page 2 / 3