A free Maya Python script that creates a 3D stroke joint animation

Oscar de la Hera
AR Tips And Tricks
Published in
2 min readJul 26, 2018

Step 1: Create a surface extrude and bind it to joints

PART A: Create the surface extrude [This tutorial].

PART B: Create joints along a curve [This tutorial].

PART C: Bind the joints to the extrude [This tutorial].

Step 2: Select ALL your joints

Command + Click on “Joint 1” to reveal all the joints, then scroll to the bottom and shift select the last one to select all of the joints.

In the example below, there are 100 joints.

Step 3: Run the following script.

Shout out to Mark Yagos for the help.

Please note that the “Factor” indicates the number of frames per animation.

Please note that the scale MUST be larger than 0 for it to export to a dae file.

import maya.cmds as mc
########################################
# UI #
########################################
myWindow = mc.window(title="Create Joint Stroke");
mc.rowColumnLayout(nc = 2);
mc.button(l = "Animate", w = 150, c="animateJointsAlongCurve()");
mc.button(l = "Cancel", w = 150, c="mc.deleteUI(myWindow)");
mc.showWindow();
########################################
# VARIABLES #
########################################
jointArray = [];
def animateJointsAlongCurve():
print "Animate Joints Along A Curve";
jointArray = mc.ls(sl = True);
jointAmount = len(jointArray);
for i in range(0, jointAmount):
currentJoint = jointArray[i];
mc.setAttr(currentJoint + ".scaleX", 1);
mc.setAttr(currentJoint + ".scaleY", 1);
mc.setAttr(currentJoint + ".scaleZ", 1);

if(i < (jointAmount-1)):
nextJoint = jointArray[i+1];
mc.setAttr(nextJoint + ".scaleX", .01);
mc.setAttr(nextJoint + ".scaleY", .01);
mc.setAttr(nextJoint + ".scaleZ", .01);

factor = 1;

mc.setKeyframe(currentJoint, t=[i*factor], at='sx', v=.01);
mc.setKeyframe(currentJoint, t=[(i+1)*factor], at='sx', v=1);

mc.setKeyframe(currentJoint, t=[i*factor], at='sy', v=.01);
mc.setKeyframe(currentJoint, t=[(i+1)*factor], at='sy', v=1);

mc.setKeyframe(currentJoint, t=[i*factor], at='sz', v=.01);
mc.setKeyframe(currentJoint, t=[(i+1)*factor], at='sz', v=1);

#BONUS: Run it in iOS

Follow the following tutorial.

Oscar

--

--

Oscar de la Hera
AR Tips And Tricks

Oscar is an award-winning Spanish Inventor whose work impacts lives through brands that include Nike, MoMA and Samsung.