Python + MXS

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

REPLY TO THREAD
 
Thread Tools Search this Thread Display Modes
Old 06 June 2007   #1
Python + MXS

Hi, Guys, sorry this is bit late but its been one of those weeks. Better late than never I guess. Anyways there a a couple of ways to get python to talk to max and vice versa. The simplest way being COM. This of course requires that you have max registered as a COM server and that you have some MXS function visible to COM (if you have not used com before check the Example scripts on 3ds max disc for getting com going, very easy to do).

First off the code im posting is the most simple of examples! but it should give you a glimpse of what could be possible, which is allot.

Fist off create a really simple function in max:

Code:
fn DoSomething obj = ( try( execute obj return true )catch( return false ) ) registerOLEInterface #(DoSomething)



As you can see there is a ultra simple function that will just execute whatever is parsed to it. Now for the Python part, this will require the win32 module.

Code:
#Import win32com. import win32com.client #Create a connection to Max conn = win32com.client.Dispatch("MAX.Application.9") #Flag as a Method otherwise python or win32com will most likely treat it as attribute. conn._FlagAsMethod("DoSomething") #Call 'DoSomething' #obj.DoSomething("Box()") Thanks to Joel Hooks for pointing out the typo.. conn.DoSomething("Box()")



With any luck you should have a box sitting in the middle of you view port. As I said above this is a very simple example, I will post some more exciting ones! Its worth mentioning that python can be called from max in much the same way, although the best* work flow (at least i think so) is to create a python server, which listens for and queries max, this has some awesome work flow implications, ie lots of artists working on the same job it becomes very easy all the sudden to keep things in sink like camera animation for example... did someone say camera server?

Hope thats enough to get you guys started, as I said I will post more stuff soon!

Cheers
Dave

Last edited by specxor : 09 September 2007 at 11:19 PM.
 
Old 06 June 2007   #2
Thanks for setting this up Dave. Really appreciated. Can you do a copy/paste of your python resources post from the challenge thread here?
__________________
"There Really is No Secret"
Martin Brennand - mocha Product Manager - Imagineer Systems

Last edited by erilaz : 06 June 2007 at 11:47 PM.
 
Old 06 June 2007   #3
I sure can:

I use python for all manor of things we have written full feature project management apps, asset browsers and a host of other bits and pieces. In terms of resources I must admit my first port of call is python.org, however I do like the oreily books "Programing Python" comes to mind. I would also recommend the Python help file that comes with the Active State distribution of python (I also think there IDE is the best, Komodo, wich is now free).

There also so some modules that I like and use all the time, I found these ones come in handy all the time:
  • PIL, this imaging lib is awesome I have written some really cool asset browsers that have utilised PIL, http://www.pythonware.com/products/pil/
  • Pyro, or Python Remote Object, I love this module for simple networking tasks, RPC and distrusted process's, http://pyro.sourceforge.net/
  • Twisted, is another networking module, its a bit big (theres an entire book on it), but it has some useful parts...
  • WxPython, this is the BEST gui lib for python, its wrapped around the C lib so its not so 'pythonic' but once your used to it or wrapped it you can build very feature rich apps very quickly and its very well documented... http://www.wxpython.org/
  • PyWin lib is awesome it provides access to just about everything in windows, including com/ole so working with max becomes very easy. You can do some very cool stuff with it. I don't have a link as I have no idea were i downloaded it, I know Mark Hammond wrote it (most of it??) I do believe its built into the Active State distribution that I mentioned above. (If anyone wants it just pm me)
Hope that helps, I think allot of people (maxers at least) tend to skip over python, but it is very easy to work with python in max and have python work with max (Pyro = back burner replacement)...
 
Old 06 June 2007   #4
Code:
did someone say camera server?


What's a camera server?

Thanks for this introduction. I'm not as biased against winOS like maybe others. But OLE somehow got a 'bad bad' tag. I will have to reevaluate this.

Having a queque and a lockfile on your server that keeps track of requests could be a way to build a 'remote scene compositor' where the 'artists' could be just monkeys spread around the world.

Sidenode:
What are the legal consequences of such setups? I think most plugins aren't licensed for server setups?

Anyway:
I heard that other applications use/will use python as well - so it is propable the middleware of choice for pipelines. Though I miss the {} ...

Georg
__________________
Georg Duemlein
 
Old 06 June 2007   #5
Why not ironPython

hi,

personnaly, i use IronPython for developpe Dotnet assembly and use in 3dsmax and communicate with maxscript

less problem than OLE communication

but i don't if all "classic" python librairy can be use with ironPython

Kermit
 
Old 06 June 2007   #6
Thanks David for the simple but very interesting example.
Yes, Python is one of the best scripting language.

I've also read an article about using 3ds Max as OLE Server (show how to communicate between XSI and Max) : http://www.sloft.net/2006/11/26/how...nd-max-friends/
__________________
 
Old 06 June 2007   #7
Hi Dave,

Thanks for starting this off. Muchly appreciated! there goes my weekends!

ezza, can we have a sticky please?

Josh.
__________________
www.joshuanewman.net
 
Old 06 June 2007   #8
I wish that I had weekends to dedicate to this...darn.

This is a great start. I have known this was possible for a long tim but I have never look into how to do it. Time to start I guess.

Can this thread please be made sticky! It is a very important solution for Max houses that need complex pipelines. Which is exactly what I'm in the process of setting up.

I wish that I had gone with Python in the first place an not learned Perl. ah well.
__________________
Paul Neale
http://paulneale.com
 
Old 06 June 2007   #9
Quote:
Originally Posted by PEN

Can this thread please be made sticky! It is a very important solution for Max houses that need complex pipelines. Which is exactly what I'm in the process of setting up.



What the Paul wants, the Paul gets.

Quote:
Originally Posted by j-man
Hi Dave,

Thanks for starting this off. Muchly appreciated! there goes my weekends!


Same here. Not that I don't have a billion other things to be learning right now, but this is too good to pass up.
__________________
"There Really is No Secret"
Martin Brennand - mocha Product Manager - Imagineer Systems

Last edited by erilaz : 06 June 2007 at 02:16 PM.
 
Old 06 June 2007   #10
Quote:
Originally Posted by erilaz
What the Paul wants, the Paul gets.


Ok then...a three day work week, paid for six. Am I pushing it now? Thanks for making it sticky.

I just had a look at setting up OLE and that looks stright forward.

I'm looking at the example scripts, Funny...I didn't know that PEN Attribute Holder still shiped with Max Any way I can't find the COM scripts? What are they called? This is the Max 9 disc.

And, does 64 bit change any of this?
__________________
Paul Neale
http://paulneale.com
 
Old 06 June 2007   #11
Quote:
Originally Posted by PEN
Any way I can't find the COM scripts? What are they called?


Sorry Paul, which COM scripts are you referring to?
__________________
"There Really is No Secret"
Martin Brennand - mocha Product Manager - Imagineer Systems
 
Old 06 June 2007   #12
Quote:
Originally Posted by erilaz
Sorry Paul, which COM scripts are you referring to?

Maybe ole.ms and oledemo.xls ("Running the OLE Demo" in MAXScript Reference). Can't find them to.
__________________

Last edited by ypuech : 06 June 2007 at 03:28 PM.
 
Old 06 June 2007   #13
oh ,.............

at last i can help Paul and Yupech :P


Samples\Scripts\Examples
 
Old 06 June 2007   #14
Thumbs up From the maxScript challenge 17 post

Quote:
Originally Posted by specxor
There also so some modules that I like and use all the time, I found these ones come in handy all the time:

  • PIL, this imaging lib is awesome I have written some really cool asset browsers that have utilised PIL, http://www.pythonware.com/products/pil/
  • Pyro, or Python Remote Object, I love this module for simple networking tasks, RPC and distrusted process's, http://pyro.sourceforge.net/
  • Twisted, is another networking module, its a bit big (theres an entire book on it), but it has some useful parts...
  • WxPython, this is the BEST gui lib for python, its wrapped around the C lib so its not so 'pythonic' but once your used to it or wrapped it you can build very feature rich apps very quickly and its very well documented... http://www.wxpython.org/
  • PyWin lib is awesome it provides access to just about everything in windows, including com/ole so working with max becomes very easy. You can do some very cool stuff with it. I don't have a link as I have no idea were i downloaded it, I know Mark Hammond wrote it (most of it??) I do believe its built into the Active State distribution that I mentioned above. (If anyone wants it just pm me)
Hope that helps, I think allot of people (maxers at least) tend to skip over python, but it is very easy to work with python in max and have python work with max (Pyro = back burner replacement)...

Cheers
Dave
I believe that pyWin can be found here:
http://sourceforge.net/projects/pywin32/
__________________
Blue

Last edited by Blue : 06 June 2007 at 08:46 PM.
 
Old 06 June 2007   #15
Great, I have it. Like I have time for this!! Damn you, damn you all to hellllllllllllllllllllllllllllll! Now I just need a quite beach, were the rest of humanity has been whipped out and the bank and tax man isn't looking for me so that I can sit down and learn some of this. The talking apes might become of bit of a distraction.
__________________
Paul Neale
http://paulneale.com
 
reply share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 02:00 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.