# Joints On Curve Script

Hi everyone!

Today I wrote a new script that I call jntsOnCrv. It’s a script that creates n number of joints on any arbitrary curve. It could really come in handy when trying to make high number and complex joint chains like tails, ropes, etc.

All you need to do is have a curve selected and the script will do the rest. So what is it doing? Primarily, it is:

1. Finding the number of spans on the curve. This will determine our “i” value.
2. “i” is equal to the number of spans (u) / (segments – 1.0)
1. It’s important that this value is a float
3. So we have u, i, and now we just make joints at the point “a” on the curve until “a” is equal to u.
1. The pointOnCurve command gives us the world space coordinates of a point along a curve at the specified U value.

Other than that, I made a UI that allows you to adjust the number of joints with a slider and float box. It’s re-purposed code from my divideJoint script 🙂 Always nice to be able to re-use code.

```import maya.cmds as cmds

def jntsOnCrv(curve=None, segments=2):
# creates an oriented joint chain that follows a selected curve
if segments < 2:
return
if not curve:
curve = cmds.ls(sl=1, o=1)[0]

# use pointOnCurve(pp=0->2) to find world coordinates on the curve
jnts = []
a = 0.0
# find the max U value. It's equal to the number of spans on the curve
u = cmds.getAttr(curve + ".spans")
# these have to be float values!
i = u / (float(segments) - 1.0)
cmds.select(cl=1)
# c will be used to check for computational errors because on some numbers we end at segments - 1
c = 0
while a <= u:
jnts.append(cmds.joint(p=cmds.pointOnCurve(curve, pr=a)))
a += i
c += 1
# in some cases (segments=10,12,19) we end at one joint before the end. This fixes this problem.
if c != segments:
jnts.append(cmds.joint(p=cmds.pointOnCurve(curve, pr=u)))
# orient our joint chain
cmds.joint(jnts[0], e=1, oj="xyz", ch=1)
cmds.joint(jnts[-1], e=1, oj="none")

```