Monday, December 3, 2012

Python in Maya

To Begin we need the right tools:

First, install the same version of Python on your machine as is being used inside of Maya.


To find out what version you are running go to your Python Tab and execute:


import sys

print sys.version


What version are you running?


Go here to download the correct version:

http://www.python.org/download/releases/

We also need to install

Ipython:

pyreadline:

and


numpy
http://www.scipy.org/Download

Download Eclipse Classic from:
http://www.eclipse.org/downloads/?osType=win32

Show ipython inside a command prompt

import numpy

use tab complete to find:

numpy.random.sample?


Where can we execute python in Maya?
from the command line of Maya

create sphere
create polyCube

Script Editor:
create new tabs
show "quick help" and call documentation


New Scene, use import maya.cmds

import maya.cmds

Explain modules in Python, think about Photoshop, or booting your PC

Ways to execute import maya.cmds?

Use Enter by the num pad, or right-click marking menu execute, or "play" button

next 
import maya.cmds
dir()

dir(maya)

dir(maya.cmds)

dir(maya.cmds.CreatePolygonSphere)

How many commands are inside of maya.cmds?

print (len(dir(maya.cmds)))

List what is in my scene:
maya.cmds.ls()

maya.cmds.ls(assemblies=True)

Create an Alias for maya.cmds
import maya.cmds as mc


Let's Create some items
mc.sphere()
mc.spaceLocator()
mc.camera()
mc.polyCube()

Select objects of different types
mc.ls(type='mesh')
mc.ls(type='geometryShape')

Put those items in a list
shapes = mc.ls(type='geometryShape')
print shapes[]
print shapes[0]


BREAK-----------------------------

self teaching...

----------------------------------------

Let's install Eclipse plugins

after launching Eclipse:

Help-> "pydev - http://pydev.org/updates/" Add and step through installing a Python Dev environment


Homework:
Use the powers of the internet to help you:

Create a python script that makes 20+ spheres in a loop and place them randomly around your scene.

Look up (google) how to move/rotate/scale things with python in Maya and copy someone else's code tweak it to get your own altered results.




No comments:

Post a Comment