Maya Python scripting – Iterate through the timeline frames

Software:
Maya 2018

The following Python script iterates though Maya’s timeline frames, and for each frame creates a new cube, and aligns it’s position to the selected animated locator.

* There is probably a nicer way to set one object’s position according to anothers but haven’t found it yet (not finding enough examples of the cmds.xform command…) so sorry for that..

import maya.cmds as cmds

selection = cmds.ls(sl=1,sn=True)
for frame in range(1,80):
    cmds.currentTime(frame)
    newCube = cmds.ls (cmds.polyCube( sx=1, sy=1, sz=1), long=True)
    posX = cmds.getAttr(selection[0]+'.translateX')
    posY = cmds.getAttr(selection[0]+'.translateY')
    posZ = cmds.getAttr(selection[0]+'.translateZ')
    cmds.setAttr(newCube[0]+'.translateX',posX)
    cmds.setAttr(newCube[0]+'.translateY',posY)
    cmds.setAttr(newCube[0]+'.translateZ',posZ)

maya_python_frames

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s