Maya Scripts

Maya Python Scripts and plugins by Ermis Chalvatzis



Create an array of cubes in two directions

# Create cube array
# Written by: Ermis Chalvatzis
# Email:

import maya.cmds as cmds 

def cubeArray(wid, hei):
    for i in range( wid ):
        for j in range( hei ):
            cmds.move(i, j, 0);
cubeArray(100, 100);

# Enjoy!!!


Here is another handy script using maya’s cmds module!!!
Imagine we want to select out of a large array of mesh objects only a percentage of them. This script comes in to solve this:

# Written by: Ermis Chalvatzis
# Email:

import maya.cmds as cmds;
import random;

# select an array of mesh obejcts 
selMesh = cmds.filterExpand(ex=True, sm=12);

def selectPct(objs, pct, dlt):
    # clear the selection, if any;
    perCnt = pct;
    # new length of the array of objects
    len_new = int( len(objs)*perCnt );
    for i in range(len_new):
        rnd_sel = random.randrange( len(objs) );
        obj = objs[ rnd_sel ];, add=True);
    # delete the selection  
    if dlt==True:

# run the function
# provide the percentage as a float (0, 1.0]     
selectPct(selMesh, 0.25, False);

# Enjoy!!!

Implementation of selectPct

Implementation of selectPct