Linear Curve Script

Took a quick break from rigging and wrote this script that basically creates a line between two objects using a curve. I’ve seen this kind of setup used a lot on pole vector controls so I thought I’d give it a shot.

As an update on my leg rig, I’m currently working to give it more robust squash and stretch controls. For the most part, the rig is complete, but it still is missing traits like an IK/FK align script. I’m still having trouble writing that.

import maya.cmds as cmds

"""
Class that takes two points and creates a linear curve between them.
It then creates Clusters at those points and those clusters
are parented to those two objects.
"""

class linearCrv(object):
def __init__(self,point1,point2):
# points 1 and 2 are the two objects we gave this script
self.point1 = point1
self.point2 = point2
# point 1 and 2 position can be static because we will later use constraints
self.point1Pos = cmds.xform(point1,q=1,t=1)
self.point2Pos = cmds.xform(point2,q=1,t=1)

self.crv = cmds.curve(degree=1,p=[(self.point1Pos),(self.point2Pos)])

cmds.select(self.crv + ".cv[0]")
self.cluster1 = cmds.cluster()

cmds.select(self.crv + ".cv[1]")
self.cluster2 = cmds.cluster()

cmds.parentConstraint(self.point1,self.cluster1)
cmds.parentConstraint(self.point2,self.cluster2)

cmds.setAttr(self.cluster1[1] + ".visibility",0)
cmds.setAttr(self.cluster2[1] + ".visibility",0)

self.clusterGrp = cmds.group(self.cluster1,self.cluster2)
cmds.rename(self.clusterGrp,"ClusterGrp#")

Advertisements
Image

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