Notifications
Clear all

[Closed] writing and executing .py files from maxscript

Bestow upon me your wisdom. Is this possible?

–using maxscript, write a .py file from a string*
–launch the .py from a cmd line call
–the .py file runs, does stuff, writes another file
–once the file is written, the file is loaded back into the maxscript
–the .py file is deleted

  • it makes more sense to just ‘supply’ the .py file, but I’d like to write it from a .mse for reasons beyond the scope of this post… I’d like the user to never know that a .py file was created, nor do I want them to have access to it. Think of it as a temporary .py file that is written dynamically based on data from the maxscript.
6 Replies

Sure. Just store the string as a variable, write it to a file, then run the python script using shellExecute or hiddenDosCommand. The hardest part would be actually including a python distribution. Perhaps you should consider looking in to py2exe or similar to distribute your script as an executable. This would also have the advantage of supplying the script as compiled python code, giving you the obfuscation It seems like you’re aiming for.

1 Reply
(@norman3d)
Joined: 11 months ago

Posts: 0

If you compile the python script you could also pass whatever info you want from maxscript to the exe through arguments.

 j83

Or perhaps try C#, since the user would have at least whatever .NET version 3ds Max is using, if not newer.

Wisdom has been bestowed.

I don’t think I could include a python distribution, forcing the user to install python on their own.
Using a ‘frozen binary’ python exe sounds like a good route to go, but writing a ‘frozen binary’ python exe using a string in maxscript does not sound fun… although I’m sure it’s possible.
C# sounds like a safe route to go considering it installs with max… but wouldn’t the C# code written need to be compiled? Or could it be compiled onComplete/just in time? Sorry if that is a stupid question, I don’t know much about C#.

 j83

Here are two examples from Denis,

http://forums.cgsociety.org/showpost.php?p=6590713&postcount=1
http://forums.cgsociety.org/showpost.php?p=6758071&postcount=6

Perhaps when I have time I’ll post some examples and tests, as of right now, I’m too sleepy.

Thankyou j83! :applause: I’ll be studying those examples, and looking forward to any you post as well!