Incorrect Python Joint Creation

Incorrect Python Joint Creation

shomari.rivero65CK4
Explorer Explorer
225 Views
1 Reply
Message 1 of 2

Incorrect Python Joint Creation

shomari.rivero65CK4
Explorer
Explorer

This function creates a straight joint chain emanating from the origin.
It is working, although all the joints are being created from the origin.
How would I adjust this function so they are created normally in a hierarchy ?

 

def createSimpleSkeleton(joints): # joints = # of joints to create
   cmds.select(clear =True)
   bones = []
   pos = [0,0,0]

   for i in range(0, joints):
  pos[1] = i * 4
  bones.append(cmds.joint(p=pos))
  cmds.select(bones[0], replace = True)

 

 createSimpleSkeleton(4)

0 Likes
226 Views
1 Reply
Reply (1)
Message 2 of 2

Kahylan
Advisor
Advisor

Hi!

 

Your select command was always reselecting bones[0] instead of bones[i]

def createSimpleSkeleton(joints):
    """
    has positional attribute 'joints' which needs an integer to specify the number of joints created
    """
    cmds.select(clear =True)
    bones = []
    pos = [0,0,0]
    for i in range(0, joints):
        pos[1] = i * 4
        bones.append(cmds.joint(p=pos))
        cmds.select(bones[i], replace = True)

 

createSimpleSkeleton(4)

But also, the joint command automatically selects the joint that is created, so this line is obsolete unless you are doing something else in your loop afterwards:

def createSimpleSkeleton(joints):
    """
    has positional attribute 'joints' which needs an integer to specify the number of joints created
    """
    cmds.select(clear =True)
    bones = []
    pos = [0,0,0]
    for i in range(0, joints):
        pos[1] = i * 4
        bones.append(cmds.joint(p=pos))

 

createSimpleSkeleton(4)

 

I hope it helps!

0 Likes