Python is a dynamic object-oriented programming language that can be used for many kinds of software development. It offers strong support for integration with other languages and tools, comes with extensive standard libraries, and can be learned in a few days. Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code.
Example shown: Allow a text input variable to be passed to Maya
Prior to starting, you will need to opena port on Maya to allow commands to be sent. This can be done done in one of two ways. Copy (Right click and choose save) this script to your Maya scripts Start up directory.
Windows:
Mac: ~/Library/Preferences/Alias/maya/
IRIX/Linux: ~/maya/
or you can create your own script using the following command to open the port and save the script as userSetup.mel
Python Passing Text:
You may be saying, big deal, you can send a message in maya. Well, think about some of the broader implications. In this example we sent text, but you could also pass things like scenes, render commands, Custom Mel scripts accross an entire network etc.
From dominic pascasio
2009-10-09 11:33:16
Nice, it is so important to know how would maya be used in network games...
hmm... we can also use socket to connect to the database, right?
From Brad
2009-10-13 15:02:24
I don't have any experience using Maya in a network game environment, can you clarify what that means? Are you referring to game model creation?
From joshua
2010-03-18 13:57:03
This is nice and works well but how do you go about getting information back? I know there is a .recv() and a .recvfrom() but the sting they return is not really that useful. Is there a better way?
From Brad
2010-03-18 14:15:27
Sure, what kind of information are you looking to get back? The easiest way to to tell if what you want is possible is by running your command first through MEL, then view the out put. If what you wanted was confirmation of a render command you can dump the output of the Python to a temp file then parse that file, a hack for sure but just the first thought off the top of my head.
From joshua
2010-03-18 18:09:39
for example if I wanted a list of the selected icons the .recv() would return something like this.
bob1 bob2 bob3 bob4
(cube thihg)
Is there a way to get it to come back as a list instead of string?
From Brad
2010-03-18 18:46:43
I don't think so, BUT you can take that input and reformat it inside python, lets take your example using .recv()
From Joshua
2010-03-19 08:40:11
Thank you I don't know why I didn't think of using split sooner.
maya.send(r'ls-sl;')
sel1 = maya.recv(1024)
sel2 = sel1.split()[:-1]
maya.send(r'select -r %s;' % sel2[1])
You don't need the (' ') if you just leave it blank it will split it into words automatically. And the [:-1] will get rid of that unknown character.
O how did you get your code in that box?
Feel free to leave a comment or question
Code block comments
2010-03-19
Added a code block for comments
Windows 7 Items
2009-09-24
new info on windows 7
Snort on Debain Lenny
2009-08-19
Installing snort+PGSQL on Debian