Skip to content

Instantly share code, notes, and snippets.

@epicallan
Created November 29, 2014 12:14
Show Gist options
  • Save epicallan/c76402715911d45cd636 to your computer and use it in GitHub Desktop.
Save epicallan/c76402715911d45cd636 to your computer and use it in GitHub Desktop.
Python script for maya that creates curves in form of a joint on a selected vertice, with a gui window having a name and radius field
'''
Created on 28 Sep 2014
@author: [email protected]
'''
import pymel.core as pm;
from functools import partial;
class JointCurve(object):
def __init__(self):
#window name and set up, variables
self.window="allan_window";
self.title="joint curve on point";
self.size=(100,200);
self.supportsToolAction =False;
def create(self):
#sets up UI windoow defaults
if pm.window(self.window,exists=True):
pm.deleteUI(self.window,window=True);
self.window=pm.window(
self.window,
title=self.title,
widthHeight=self.size,
menuBar=False)
uilayout= pm.columnLayout( adjustableColumn=True,rowSpacing=10, )
self.windowItems(uilayout);
pm.showWindow();
def windowItems(self,layout):
pm.text(label="", align='center',parent=layout);
#adding labels and text fields
pm.text(label="Control Name", align='center',parent=layout);
name=pm.textField(parent =layout);
pm.text(label="Radius", align='center',parent=layout);
radius=pm.textField(parent =layout);
#using pythons partial for call back
pm.button(label="Apply",command=partial(self.report,name,radius));
def report(self,field,radius,value):
#querrying name of the joint curve entered in the text field
myName=pm.textField(field,query=True,text=True)
#querrying radius of the joint curve entered in the text field
myradius=pm.textField(radius,query=True,text=True)
#creating tempory clustres on selected vertice so as to get its position
clustre=pm.cluster();
#getting position of clustere
trans=pm.xform(clustre[1],sp=True,q=True,ws=True,a=True);
#curve generating function
self.CurveJoint(myradius,myName,trans);
#delete tempory clustres
pm.delete(clustre);
def CurveJoint(self,Radius,name,pos):
circles =[]
circles_shapes=[];
#going to use 3 circles to create curve joint
for i in range(3):
#creating string number for naming
j=str(i);
#creating circle
myCircle=pm.circle(c=(0,0,0), r=Radius, name="test_"+j);
#adding new circle to circle list
circles.append(myCircle[0]);
#getting circle shape node and adding to circle shapes list
circles_shapes.append(myCircle[0].getShape());
if i==1 :
#rotating circle 1 by 90 to create joint curve
pm.xform(myCircle[0],ro=(90,0,0));
if i == 2 :
#rotating circle 2 by 90 to create joint curve
pm.xform(myCircle[0],ro=(0,90,0));
#freexing teansforms of the circles
pm.makeIdentity(myCircle[0],apply=True, scale=True,translate=True,rotate=True);
#all shape nodes of the circles are going to be parented to one circle
myParent=circles[0];
pm.parent(circles_shapes[1],myParent,s=True,r=True );
pm.parent(circles_shapes[2],myParent,s=True,r=True );
#rename the joint curve
pm.rename(myParent,name);
#translate it to the selected position which was the position of the temporary cluster
myParent.setTranslation(pos);
#delete the tansform nodes of circle 1 and 2 since we will use the transform node of circle[0]
pm.delete(circles[1],circles[2]);
#delete history
pm.delete(myParent,ch=True);
jntCurve= JointCurve();
jntCurve.create();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment