Here are a selection of Maya Python scripts I've been using to make my workflow easier:

Random Deselect

Assign Different Collision Layer

Delete Keyframes after a Specified Time

Add Suffix to Name

Create Lightning Mesh

Sort Outliner Alphabetically

Random Deselect - now with UI!

import maya.cmds as cmds
import random

from PySide import QtCore, QtGui

class Deselector(QtGui.QWidget):
    def __init__(self):
        super(Deselector, self).__init__()
        = 'Deselector'
    def _init_ui(self):
        # Widgets
        self.percentage_label = QtGui.QLabel('Percentage')
        self.percentage_spin = QtGui.QDoubleSpinBox()
        self.percentage_spin.setRange(0.0, 1.0)
        self.reduce_button = QtGui.QPushButton('Reduce')
        # Layout
        self.main_layout = QtGui.QVBoxLayout()
        self.attribute_form = QtGui.QFormLayout()
        self.attribute_form.addRow(self.percentage_label, self.percentage_spin)
        # Signals
    def _on_reduce_button_clicked(self):
        keep = self.percentage_spin.value()
        # save selection as a list, create empty list
        sel =
        new_sel = []
        # iterate over list only keeping some objects
        for item in sel:
            print item
            if random.random() < keep:
        # select new selection
my_win = Deselector()

This simple script just randomly selects a percentage of the objects in your current selection - very useful for quickly creating randomness.  


Assign Different Collision Layer

import maya.cmds as cmds

# save selection as a list 
sel =

# iterate over items in the list setting each to have a different Collision Layer
for i in range(len(sel)):
    cmds.setAttr('{0}.collisionLayer'.format(sel[i]), i)

This script again iterates over a selection and sets each object to have a different Collision Layer - useful for speeding up things like brick wall explosions where the inter-object collisions aren't really important.  Remember to set you impact object and ground plane to Collision Layer -1 so that it still collides with everything. 


Delete Keyframes after a Specified Time

import maya.cmds as cmds
import math

# setup inital variables 
start_frame = 0.0
last_frame = 200
frames_to_keep = 20.0
move_tolerance = 0.1

# list selected objects
sel =

# iterate over each mesh in list
for mesh in sel:
    # re-initalalise
    print mesh 
    start_frame = 0.0
    # find the first frame the mesh moves 
    for frame in range(last_frame):
        if not start_frame > 0:
            if cmds.getAttr('{0}.ty'.format(mesh)) > move_tolerance:
                start_frame = cmds.currentTime(query=1)
    # delete all frames after start_frame + frames_to_keep        
    cmds.cutKey('{0}'.format(mesh), time=(math.trunc(start_frame + frames_to_keep), last_frame))


This script iterates over a selection and only keeps a set number of keyframes after the object first moves vertically.  This is useful for creating 'ground crack' style simulations - simulate your pieces being impacted without gravity and then just keep the first 10-20 frames of the simulation


Add Suffix to Name

import maya.cmds as cmds

# Suffix text to add
suffix = '_low'

# List all selected objects
sel =

# For each item in the list add the suffix
for item in sel:

Adds the specified suffix to the object names - useful for baking by name in Substance.


Create Lightning Mesh

import maya.cmds as cmds
import random

Create and deform a number of meshes and uv's for use with a scrolling UV2 material 

numMeshes = 10

divisions = 20
moveRepeats = 3  #more repeats results in a more jagged mesh
offsetfactor = 1

#Loop over numMeshes

for mesh in xrange(0, numMeshes):

    #Create Mesh and randomly move Edges
    lightningmesh = cmds.polyPlane( sx=divisions, sy=1, w=20, h=0.5)[0]
    for rep in xrange(0,moveRepeats):
        for x in xrange(3,(divisions*2),2):
            offset = (random.random()-0.5)*2 * offsetfactor
            cmds.move(offset, z=1, r=1)
    #Create Second UV Set"{0}.map[:]".format(lightningmesh))
    cmds.polyEditUV(pivotV=0, scaleV=0.01)"{0}.map[:]".format(lightningmesh))
    cmds.polyEditUV(r=1, v=mesh*(1.0/numMeshes))'{0}'.format(lightningmesh))

    #Add a Wave Deformer
    Amp = (random.random()-0.5) * 0.4
    Wavelength = random.random() + 0.5
    WaveDef = cmds.nonLinear(type="wave")[0] 
    cmds.setAttr('{0}.amplitude'.format(WaveDef), Amp)
    cmds.setAttr('{0}.wavelength'.format(WaveDef), Wavelength)
    cmds.setAttr('{0}.dropoff'.format(WaveDef), 1)
    #Add a Twist Deformer
    TwistAngle = (random.random()-0.5)*2 * 720'{0}'.format(lightningmesh))
    TwistDef = cmds.nonLinear(type='twist')
    cmds.setAttr('{0}.rz'.format(TwistDef[1]), 90)
    cmds.setAttr('{0}.endAngle'.format(TwistDef[0]), TwistAngle)


#Sort objects in the Outliner Alphabetically

import maya.cmds as cmds

#Select all Geometry and reverse
sel = 
#print sel

#Create an Empty Group, name='temp')

#Parent to the Empty Group and then back to World
for item in sel:
    cmds.parent('{0}'.format(item), 'temp')
    cmds.parent('{0}'.format(item), world=1)
#Select all Cameras 
sel = 

#Parent to the Empty Group and then back to World
for item in sel:
    cmds.parent('{0}'.format(item), 'temp')
    cmds.parent('{0}'.format(item), world=1)

#Delete the Empty Group