Python to maxscript

Hi,

I’m trying to fire a bit of maxscript code into our render nodes running corona.

The script tells corona to finish the frame and save out the progress it has (so we don’t lose the render)

I have been playing about with a script I found online that I thought would work, whereby it looks for the active max window and pushes in the macroscript from python - but this sort of thing is a bit hacky and could break on any small change (and it would only pick a random 3dsmax window if multiple were open)

What would be the best way to accomplish this? I basically need to be able to fire the python command through a Deadline monitor script (which is python) and get it to target the open copy of 3dsmax that is currently rendering.

Any ideas appreciated!

Cheers.

1 Like

Using COM is about the only way you can accomplish sending commands to max from a process started externally to Max. MaxScript, and the Max implementation of Python, are single-threaded so you can’t set up a socket listener, which would be a more robust solution.

Check out https://github.com/JeffHanna/MXSPyCOM/releases MXSPyCOM is a small utility I maintain that helps in sending commands over to Max from external apps.

2 Likes

Jeff’s suggestion is a good one, though I’m not sure how Max will respond to receiving commands whilst rendering.

Might I suggest a ‘don’t let the perfect be the enemy of the good’ solution? Corona’s autosave function set to about 10 minutes should have a fairly minimal impact on render performance whilst also allowing you to basically never lose more than 10 minutes of rendering.

1 Like

Hi Dan,

We do tile rendering of large images through Deadline and Corona - these tile renders are set to hit a % noise amount before they finish.

Sometimes we have to just get the tiles out so the full image can complete and be assembled, no matter what noise level they have reached.

Good point about the autosave though, but this wouldn’t denoise the render elements (which happens after the tile has completed rendering) - But it might let us open it in the Corona Image Editor and manually denoise the passes.

Thanks for the suggestions guys, I’ll have a play and see if I can get a solution.

The max sublime plugin has examples of how to do this:
https://packagecontrol.io/packages/Send%20to%203ds%20Max

Hi guys,

I managed to get this to work through mxspycom which triggered the maxscript to stop renders whilst in progress.

It is a bit picky when multiple max windows are open, and I tried a few workarounds with injecting the initialize_COM_server maxscript at different times of program/file load/pre-render to see if it made any difference - which it didn’t. Whatever 3dsmax window was open first always took priority.

Is it possible to get information out of 3dsmax with mxspycom, or is it strictly 1 way communication?

Any other suggestions for being able to send and recieve commands to 3dsmax with python (or something similar)

I keep hearing about zeromq, but can’t find any examples on how it is setup, or how it talks to 3dsmax.

What would be the best way to proceed now?

Thanks for any info!

The code in: https://github.com/cb109/sublime3dsmax/blob/master/sublime3dsmax.py shows examples of how to access a max instance by its window handle and send code to said instances listener for execution. It does this using a cut down version of winapi.py, found in the root of the GitHub project.
This is the best approach you will find.
I have been able to use this as inspiration to create a stand alone module for my work, to send code from motion builder and from one max instance to another.
Read the code, it won’t take you long to figure it out. The author has done a good job with it.