import maya.cmds as cmds
  
# Useage: 
# from shape_utils import get_verts
# print get_verts('pSphere1')
# Returns a list of lists ie. [[x,y,z,[x,y,z]....] 
def get_verts(tnode, useLocalSpace=True):
    verts = []
    shape = cmds.listRelatives(tnode, shapes=True)[0]
    num_verts = cmds.polyEvaluate(tnode, vertex=True)
    for n in range(num_verts):
        vert_str = shape + '.vtx[%d]' % n;
        vert_pos = cmds.pointPosition(vert_str, local=useLocalSpace) 
        verts.append(vert_pos)    
    return verts
  
# Same as get_verts() but returns a flat list of coords ie. 
#  [x0,y0,z0,x1,y1,z1....]
def get_coordinates(tnode, useLocalSpace=True):
    coords = []
    verts = get_verts(tnode, useLocalSpace)
    for vert in verts:
        coords.extend(vert)
    return coords