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


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__()
        
        self.name = 'Deselector'
        
        self.setWindowTitle(self.name)
        
        self._init_ui()
    
    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.percentage_spin.setSingleStep(0.05)
        self.percentage_spin.setValue(0.50)
        
        self.reduce_button = QtGui.QPushButton('Reduce')
        
        # Layout
        self.main_layout = QtGui.QVBoxLayout()
        self.setLayout(self.main_layout)
        
        self.attribute_form = QtGui.QFormLayout()
        
        self.attribute_form.addRow(self.percentage_label, self.percentage_spin)
        
        self.main_layout.addLayout(self.attribute_form)
        self.main_layout.addWidget(self.reduce_button)
        
        # Signals
        self.reduce_button.clicked.connect(self._on_reduce_button_clicked)
        
    
    def _on_reduce_button_clicked(self):
        keep = self.percentage_spin.value()
        
        # save selection as a list, create empty list
        sel = cmds.ls(sl=1)
        new_sel = []
        
        # iterate over list only keeping some objects
        for item in sel:
            print item
            if random.random() < keep:
                new_sel.append(item)
                
        # select new selection
        cmds.select(new_sel)
        
        
my_win = Deselector()
my_win.show()

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 = cmds.ls(sl=True)

# 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 = cmds.ls(sl=1)

# iterate over each mesh in list
for mesh in sel:
    
    # re-initalalise
    print mesh 
    start_frame = 0.0
    cmds.currentTime(start_frame)
    
    # 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)
            cmds.currentTime(frame)
            
    # delete all frames after start_frame + frames_to_keep        
    cmds.cutKey('{0}'.format(mesh), time=(math.trunc(start_frame + frames_to_keep), last_frame))

cmds.currentTime(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 = cmds.ls(sl=1)

# For each item in the list add the suffix
for item in sel:
    cmds.rename(item,'{0}{1}'.format(item,suffix))

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.select("{0}.e[{1}]".format(lightningmesh,x))
            cmds.move(offset, z=1, r=1)
            
            
    #Create Second UV Set
    
    cmds.select("{0}.map[:]".format(lightningmesh))
    cmds.polyEditUV(pivotV=0, scaleV=0.01)
    
    cmds.select("{0}.map[:]".format(lightningmesh))
    cmds.polyEditUV(r=1, v=mesh*(1.0/numMeshes))

    cmds.select('{0}'.format(lightningmesh))
    cmds.polyCopyUV(createNewMap=1)
        
    cmds.polyNormalizeUV(pa=0)

    #Add a Wave Deformer
    
    Amp = (random.random()-0.5) * 0.4
    Wavelength = random.random() + 0.5
       
    cmds.select('{0}'.format(lightningmesh))
    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
    
    cmds.select('{0}'.format(lightningmesh))
    TwistDef = cmds.nonLinear(type='twist')
    
    cmds.setAttr('{0}.rz'.format(TwistDef[1]), 90)
    cmds.setAttr('{0}.endAngle'.format(TwistDef[0]), TwistAngle)