Python + MXS


David, did you ever post this example? I’m looking at some networked functionality and thought your app might be a useful resource.


Hi erilaz,

Yeah I did and it worked really well. I will post the code shortly, all of the networking was handled by pyro.



Thanks, that will be helpful. Incidently, are you the same Dave that went to Mad Academy? I assume it’s not coincidence. :smiley:


Yep thats me!





Ok just wipped up some small examples of using pyro for networking.

First up the server:

   	Simple Pyro Example. 
   	Here is the 'Server' code.
   	Written By David Mackenzie
   import Pyro.core
   import socket
   class some_server(Pyro.core.ObjBase):
   	"""Pyro Server, handles the network transmission"""
   	def __init__(self):
   		self.ServerName = "CgTalk Example Server"
   	def Ping(self):
   		return "%s Checking In" % (socket.gethostname())
   	def DoSomeStuff(self, the_int):
   		return the_int*5
   if __name__ ==  "__main__":
   	daemon = Pyro.core.Daemon(port=7756)
   	uri = daemon.connect(some_server(), "cgTalk") 

Now for a simple client to connect to the server:

   	Here is the client code that demonstates connecting to the server and  calling a remote method.
   def connectToServ():
   	cgConn = Pyro.core.getProxyForURI("PYROLOC://%s:%s/%s" % ("", 7756 , "cgTalk"))
   	return cgConn
   if __name__ == "__main__":
   	conn = connectToServ()
   	print conn.Ping()
   	print conn.DoSomeStuff(10)

And here is a simple com class that connects to the server:

   	Here is a com example that we could call from max or anywhere that has com access. Please Note I have not tested the following code.
   import win32com.server.register
   import Pyro.core 
def connectToServ():
   	cgConn = Pyro.core.getProxyForURI("PYROLOC://%s:%s/%s" % ("", 7756 , "cgTalk"))
   	return cgConn
   class cgTalk_Com:
   	_public_methods_ = ['Ping', 'DoSomeStuff']
   	_reg_progid_ = "cgTalk.PyroExample"
   	_reg_clsid_ = '{59EA2ED9-8DAA-4092-8BD4-3A6069D3074B}'
   	def __init__(self):
   		self.Connection = connectToServ()
   	def Ping(self):
   		return self.Connection.Ping()
   	def DoSomeStuff(self, some_int):
   		return self.Connection.DoSomeStuff(10)
   if __name__ ==  "__main__":

Hope that helps, sorry for not getting this up earlier I have been swamped lately… I have tested the server and simple example. I have not tested the com class, if you have any problems just post them up.



Thanks Dave, really appreciated. This should be wikied! :slight_smile:


Agreed, I have to get off my @ss and get this stuff written up



Nah, I get the busy thing. Look how tardy I am at getting maxscript challenges written up!:smiley:

Oh, and for those that care, I just made an obscure python joke in this thread:

Hot damn I love


Just found this great converter: XML to Python Object class. Thought I’d share as many of us use xml. I spent hours learning the parsed XML syntax and trying to get the data out… then this happened… I love this python stuff…


Thanks heaps. This will definatly come in handy


there’s also elementtree. Anyone have experience with both?


cElementTree is the same as elementtree but written in C so it’s fast.
It is about 10 times faster then XMLObject. See attachement.
XMLObject is a wrapper of standard python dom.minidom library.
Lxml or cElementTree libraries are both fast and easy to use.


Hi Guys,

XMLObject is very cool, I love SQLObject to… While we are talking about XML here is XMLClass(s) that I use all the time, I have also recreated it in MXS wrapping the dotnet objects the max and python version are virtually identical.



Great stuff Dave. I hope I can get some time to pull it apart to see how it all works. :slight_smile:


Does anyone have a library that makes writing maxscripts pythonic? I’m thinking of starting opensourced work on making a python library for writing maxscripts instead of simply passing raw maxscript commands over COM. I might just be extending CgKit since it has functionalities for working with 3d objects.


I assume this is max 9+ :cry:

As for SQLObject, i have my reservations about it and SQLALchemy. What benefits does it provide over using SQL?


CgKit is pretty cool. I’m thinking one could use maxscript and the getpropnames command to generate most of the classes required to hold a MAX scene in python code. Minus lofts of course… ha ha…


Yep max 9+ only…

Yeah SQLObject is very cool it makes working with databases much more pythonic with all of your tables mapped to objects etc… I have looked at SQLAlchemy very quickly but have not used it, so I am not sure what benifits of SQLAlchemy are…



Sorry for pseudo necro-ing this thread…

I’m curious why you guys chose to use a giant Python application to handle all those tasks versus using some of the existing features in many of the more common issue-tracking applications out there (like Jira).

I had originally though about going the route you are describing (albeit via C#), but in the end decided it was redundant as we already have a perfectly viable task/status/time-card solution that integrates fairly cleanly with Perforce (our source control for everything) to link in versioning…