Some python code that creates a copy of a mesh shape based on frame and time range. Perfect for creating an animation set for particle instancing.
import maya.cmds as mc
from functools import partial
class MeshCopyWindow:
def __init__(self):
self.name = ‘w_meshCopy_JR’
self.title = ‘Mesh Copy!’
#———————————————————————-
# UI Wrapper
#———————————————————————-
def create_meshCopyUI_JR ( self, arg=None ):
nFrame = mc.intFieldGrp ( “ifg_evryFrame_meshCopy_JR”, q=True, v=1 )
nMinMax = mc.intFieldGrp ( “ifg_minmaxVal_meshCopy_JR”, q=True, v=1 )
self.create_meshCopy_JR ( nFrame, nMinMax )
#———————————————————————-
# Build Asset
#———————————————————————-
def create_meshCopy_JR ( self, nFrame, nMinMax ):
mesh = mc.ls ( selection=True, dag=True, shapes=True )
start = mc.playbackOptions ( query=True, min=True )
end = mc.playbackOptions ( query=True, max=True )
for i in range ( nMinMax[0], nMinMax[1]+1, nFrame[0] ) :
mc.currentTime ( int(i) )
mc.select ( mesh[0], replace=True )
mc.duplicate()
mc.pickWalk ( direction=”up” )
mc.move ( i*20, 0, 0 )
def doit(self):
# check for existing window
if ( mc.window(self.name, q=1, exists=1) ) : mc.deleteUI ( self.name )
mc.window ( self.name, title=self.title, s=1 )
# UI components
mc.rowColumnLayout ( nc=1, cw=[(1, 420)] )
mc.text ( l=”" )
mc.intFieldGrp ( “ifg_evryFrame_meshCopy_JR”, numberOfFields=1, l=”Every Frame”, cw3=[20, 80, 100], value1=1)
mc.intFieldGrp ( “ifg_minmaxVal_meshCopy_JR”, numberOfFields=2, l=”Timeline min/max”, cw3=[140, 80, 100], value1=1, value2=24 )
mc.text ( l=”" )
mc.button ( l=”Do it!”, c=partial(self.create_meshCopyUI_JR) )
mc.setParent ( ‘..’ )
# set window width/height
mc.showWindow(self.name)
mc.window(self.name, e=1, wh=[420, 120])
meshCopy = MeshCopyWindow()
meshCopy.doit()