Maya Scripts

Maya Python Scripts and plugins by Ermis Chalvatzis

Latest

cubeArray

Create an array of cubes in two directions


# UTILITY
# Create cube array
# Written by: Ermis Chalvatzis
# Email: Ermis.Chalvatzis@lianou-chalvatzis.com

import maya.cmds as cmds 

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


# Enjoy!!!


selectPct

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: Ermis.Chalvatzis@lianou-chalvatzis.com

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
    cmds.select(d=True);
    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 ];
        cmds.select(obj, add=True);
        
    # delete the selection  
    if dlt==True:
        cmds.delete();

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

# Enjoy!!!

Implementation of selectPct

Implementation of selectPct