Coding in Python Maya, problems with Textfield and button

Hey I am totally new to coding in python for Maya. I have got the bare basics but I have come to a wall.

Basically I am creating a tool for animation where you can create control shapes for a skeleton and snap them to a joint and set the tranlations and rotations to 0. However it will name the nurb circle, group the nurb circle and then name the group in it’s process.

What I am stuck on is connecting the Textfield to the button. I want the user to write in the joint they want the Nurb Circle to snap to and using the text they have written will rename the Nurb circle and the group the Nurb circle while naming it at the click of a button.

Here is what I want my button to do:

import maya.cmds

#Create circle

circle_names = maya.cmds.circle( c=(0, 0, 0), nr=(0, 1, 0), sw=360, r=1, d=3, ut=0, tol=0.01, s=8, ch=1);

#Rename Circle

maya.cmds.rename(circle_names[0], “ctrl_L_Wrist”);

#Select the circle

maya.cmds.select(“ctrl_L_Wrist”)

#Group the NURB circle

group_name = maya.cmds.group();

#Name the group

maya.cmds.rename(group_name, “grp_L_Wrist_offset”);

#Select the group and joint

maya.cmds.select(“grp_L_Wrist_offset”, r=1);

maya.cmds.selectKey(clear=1);

maya.cmds.select(“jnt_L_forearmtwist”, tgl=1);

#Parent the group and joint

maya.cmds.parent();

maya.cmds.select(“grp_L_Wrist_offset”, r=1);

#Set the translate and rotation to the value of 0

maya.cmds.setAttr(“grp_L_Wrist_offset.rotate”, 0, 0, 0);

maya.cmds.setAttr(“grp_L_Wrist_offset.translate”, 0, 0, 0);

#Select the group and unparent it from the selected joint.

maya.cmds.select(“grp_L_Wrist_offset”, r=1);

maya.cmds.parent(w=1);

And here is the UI for the tool:

import maya.cmds as cmds

def UI():

#Check to see if our window exists
if cmds.window("exampleUI", exists = True):
	cmds.deleteUI("exampleUI")

#Create a window
window = cmds.window ("exampleUI", title = "Adjusting Your CTRL Shape", w = 500, h =300)

#Giving the button an action
def CreateCtrl(*args):
	
	#Create circle
	circle_names = cmds.circle( c=(0, 0, 0), nr=(0, 1, 0), sw=360, r=1, d=3, ut=0, tol=0.01, s=8, ch=1);
	
	
	#Linking the text field with button
	global
	buttoncre = cmds.ls
	
	
	

#Create a main layout
cmds.rowColumnLayout(numberOfRows=2, rowHeight=[(1,100), (2, 300)] )

#Banner image
imagePath = cmds.internalVar(upd = True) + "icons/adjustingyourctrlshape.jpg"
cmds.image(w = 300, h = 100, image = imagePath)

#making a tab system

tabs = cmds.tabLayout(innerMarginWidth=5, innerMarginHeight=5)


#creating columns and the creating control shape ctrl menu


child1 = cmds.rowColumnLayout( numberOfColumns=3, columnWidth=[(1, 100), (2, 120), (3, 90)] )

cmds.text(label="Joint Name: ")
cmds.textField("jointN", edit=True, query=True, command=buttoncre )
cmds.button(label="Create", command=CreateCtrl)
cmds.setParent( ".." )

#Creating the colour menu

child2 = cmds.rowColumnLayout( numberOfRows=2, rowHeight=[(1,50), (2, 100)] )

cmds.text( label="Colour:")
cmds.colorSliderGrp( label='Colour Of Ctrl Shape:  ', rgb=(0, 0, 1) )
cmds.setParent( ".." )


child3 = cmds.rowColumnLayout("tabThree", numberOfRows=2, rowHeight=[(1,50), (2, 100)] )
cmds.text( label="Scale:")
cmds.floatSlider()
cmds.setParent( ".." )

#labelling tabs
cmds.tabLayout( tabs, edit=True, tabLabel=((child1, 'Creating Control Shape'), (child2, "Colour"), (child3, "Scaling")) )



#Show Window
cmds.showWindow(window)

Are you trying to create the button from the command in the text field? Would a static button work instead? As written 'buttoncre" doesn’t exist, it’s going to try to call ls when you enter text.

[QUOTE=Theodox;19734]Are you trying to create the button from the command in the text field? Would a static button work instead? As written 'buttoncre" doesn’t exist, it’s going to try to call ls when you enter text.[/QUOTE]

Well I managed to fix the problem, but now my UI has completely changed. Instead of inputting the value into the text field and apply the code with the button, the user is now able to click the joint on screen and then apply the code to the selected joint.

Problem now is scaling the curve in hull and CV mode. I manage to get a floatSlider working, but it’s not quite working. I can choose a value from 0 - 50 and hit a button to scale it but if I hit the button again it adds the same value on top of the current value.

E.G. scale the curve to 10 and hit apply

#result is 10

hit apply again

#result is 20

is there anyway to fix this problem?

Here is my code so far:

def Scaling(*args):
	
	#select the transform
	Scales = cmds.ls(selection = True, type = ('transform'))
	scalesName = str(Scales).replace("[u'", "").replace("']", "")
	ActivateSelectMode= cmds.selectType(objectComponent=True)
	hullMode = cmds.selectType(hull=True)
	cmds.select(scalesName+".cv[0:7]")
	
	
	scalingSlider = cmds.floatSlider(scaleSlider, query=True, value=True)
	print scalingSlider
	cmds.scale(scalingSlider,scalingSlider,scalingSlider)
	
	X_tf = cmds.textField(x, query=True, text=True)
	Y_tf = cmds.textField(y, query=True, text=True)
	Z_tf = cmds.textField(z, query=True, text=True)
	
	cmds.scale(X_tf, Y_tf, Z_tf)


#Scaling tab

child3 = cmds.rowColumnLayout("tabThree", numberOfRows=8, rowHeight=[(1,50), (2, 50), (3,40), (4,50), (5,20), (6,20), (7,20), (8,40)] )

cmds.text( label="Scale:")
scaleSlider = cmds.floatSlider( min=-0, max=50, step=1)
cmds.button(label="Apply", width=10, command=Scaling)
cmds.text(label="XYZ Scale:")
x = cmds.textField()
y = cmds.textField()
z = cmds.textField()
cmds.button(label="Apply", command=Scaling)
cmds.setParent( ".." )

Firgured out the problem lol. but the problem now is that it can scale nurbCircles but not hand drawn curves. Anyone can figure this out?

Here is the whole code:

import maya.cmds as cmds

def UI():

#Check to see if our window exists
if cmds.window("exampleUI", exists = True):
	cmds.deleteUI("exampleUI")

#Create a window
window = cmds.window ("exampleUI", title = "Adjusting Your CTRL Shape", w = 500, h =500)

tweakScaleSlider = ""
#Giving the button an action
def CreateCtrl(*args):
	object_name=""

	try:
		#Selecting joint
		JointList = cmds.ls(selection = True, type = ('joint'))
		
		if (str(JointList)=="[]"): #If joint is selected print this
			print("Hello user! You have not selected a joint!")
			
		else:
			Test = cmds.optionMenuGrp(Shapeist, query=True, select=True)
			
			if (Test==1):
				object_name = cmds.curve( degree = 1,\
			knot = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],\
			point = [(-0.5, 0.5, -0.5),\
					(-0.5, 0.5, 0.5),\
					(0.5, 0.5, 0.5),\
					(0.5, 0.5, -0.5),\
					(-0.5, 0.5, -0.5),\
					(-0.5, -0.5, -0.5),\
					(-0.5, -0.5, 0.5),\
					(0.5, -0.5, 0.5),\
					(0.5, 0.5, 0.5),\
					(-0.5, 0.5, 0.5),\
					(-0.5, -0.5, 0.5),\
					(-0.5, -0.5, -0.5),\
					(0.5, -0.5, -0.5),\
					(0.5, 0.5, -0.5),\
					(0.5, 0.5, 0.5),\
					(0.5, -0.5, 0.5),\
					(0.5, -0.5, -0.5)]\
					)
				print "A nurbsCube has been created!"
				
			if (Test==2):
				object_name = cmds.curve( degree = 3,\
			knot = [-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\
			point = [(1.9590290622280626, 1.199559335247117e-016, -1.9590290622280595),\
					(-3.1607926519573314e-016, 1.6964330807777285e-016, -2.7704854688859699),\
					(-1.9590290622280606, 1.1995593352471178e-016, -1.9590290622280606),\
					(-2.7704854688859699, 4.9158386540469646e-032, -8.0281737680930749e-016),\
					(-1.9590290622280613, -1.1995593352471173e-016, 1.9590290622280602),\
					(-8.3480134089762987e-016, -1.6964330807777287e-016, 2.7704854688859704),\
					(1.9590290622280595, -1.199559335247118e-016, 1.9590290622280611),\
					(2.7704854688859699, -9.1115751697619806e-032, 1.4880331498201463e-015),\
					(1.9590290622280626, 1.199559335247117e-016, -1.9590290622280595),\
					(-3.1607926519573314e-016, 1.6964330807777285e-016, -2.7704854688859699),\
					(-1.9590290622280606, 1.1995593352471178e-016, -1.9590290622280606)]\
				)
				print "A Circle has been created!"
				
			if (Test==3):
				object_name = cmds.curve( degree = 1,\
				knot = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,\
					21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,\
					39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52],\
				point = [(0, 1, 0),\
					(0, 0.92388000000000003, 0.382683),\
					(0, 0.70710700000000004, 0.70710700000000004),\
					(0, 0.382683, 0.92388000000000003),\
					(0, 0, 1),\
					(0, -0.382683, 0.92388000000000003),\
					(0, -0.70710700000000004, 0.70710700000000004),\
					(0, -0.92388000000000003, 0.382683),\
					(0, -1, 0),\
					(0, -0.92388000000000003, -0.382683),\
					(0, -0.70710700000000004, -0.70710700000000004),\
					(0, -0.382683, -0.92388000000000003),\
					(0, 0, -1),\
					(0, 0.382683, -0.92388000000000003),\
					(0, 0.70710700000000004, -0.70710700000000004),\
					(0, 0.92388000000000003, -0.382683),\
					(0, 1, 0),\
					(0.382683, 0.92388000000000003, 0),\
					(0.70710700000000004, 0.70710700000000004, 0),\
					(0.92388000000000003, 0.382683, 0),\
					(1, 0, 0),\
					(0.92388000000000003, -0.382683, 0),\
					(0.70710700000000004, -0.70710700000000004, 0),\
					(0.382683, -0.92388000000000003, 0),\
					(0, -1, 0),\
					(-0.382683, -0.92388000000000003, 0),\
					(-0.70710700000000004, -0.70710700000000004, 0),\
					(-0.92388000000000003, -0.382683, 0),\
					(-1, 0, 0),\
					(-0.92388000000000003, 0.382683, 0),\
					(-0.70710700000000004, 0.70710700000000004, 0),\
					(-0.382683, 0.92388000000000003, 0),\
					(0, 1, 0),\
					(0, 0.92388000000000003, -0.382683),\
					(0, 0.70710700000000004, -0.70710700000000004),\
					(0, 0.382683, -0.92388000000000003),\
					(0, 0, -1),\
					(-0.382683, 0, -0.92388000000000003),\
					(-0.70710700000000004, 0, -0.70710700000000004),\
					(-0.92388000000000003, 0, -0.382683),\
					(-1, 0, 0),\
					(-0.92388000000000003, 0, 0.382683),\
					(-0.70710700000000004, 0, 0.70710700000000004),\
					(-0.382683, 0, 0.92388000000000003),\
					(0, 0, 1),\
					(0.382683, 0, 0.92388000000000003),\
					(0.70710700000000004, 0, 0.70710700000000004),\
					(0.92388000000000003, 0, 0.382683),\
					(1, 0, 0),\
					(0.92388000000000003, 0, -0.382683),\
					(0.70710700000000004, 0, -0.70710700000000004),\
					(0.382683, 0, -0.92388000000000003),\
					(0, 0, -1)]\
			)
				print "A Sphere has been created!"
			
			if (Test==4):
				object_name = cmds.curve( degree = 1,\
			knot = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\
			point = [(-4, 0, 0),\
					(-2, 0, -2),\
					(-2, 0, -1),\
					(2, 0, -1),\
					(2, 0, -2),\
					(4, 0, 0),\
					(2, 0, 2),\
					(2, 0, 1),\
					(-2, 0, 1),\
					(-2, 0, 2),\
					(-4, 0, 0)]\
					)
				print "Arrow 1 has been created!"
				
			if (Test==5):
				object_name = cmds.curve( degree = 1,\
			knot = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],\
			point = [(-4.5, 0, 0),\
					(-2.5, 0, -2),\
					(-2.5, 0, -1.5),\
					(-1.5, 0, -1.5),\
					(-1.5, 0, -2.5),\
					(-2, 0, -2.5),\
					(0, 0, -4.5),\
					(2, 0, -2.5),\
					(1.5, 0, -2.5),\
					(1.5, 0, -1.5),\
					(2.5, 0, -1.5),\
					(2.5, 0, -2),\
					(4.5, 0, 0),\
					(2.5, 0, 2),\
					(2.5, 0, 1.5),\
					(1.5, 0, 1.5),\
					(1.5, 0, 2.5),\
					(2, 0, 2.5),\
					(0, 0, 4.5),\
					(-2, 0, 2.5),\
					(-1.5, 0, 2.5),\
					(-1.5, 0, 1.5),\
					(-2.5, 0, 1.5),\
					(-2.5, 0, 2),\
					(-4.5, 0, 0)]\
			)
				print "Arrow 2 has been created!"
				
			if (Test==6):
				object_name = cmds.curve( degree = 1,\
				knot = [0, 2.3135629999999998, 4.6271259999999996, 6.9406889999999999, 8.5778230000000004,\
					10.214957999999999, 11.849695000000001, 13.484432, 15.119168999999999, 16.744737000000001,\
					18.379473999999998, 20.014211, 21.648949000000002, 23.283685999999999, 24.920819999999999,\
					26.557953999999999, 28.871517000000001, 31.185079999999999, 33.498643000000001, 35.812206000000003,\
					38.125770000000003, 40.439332999999998, 42.076467000000001, 43.713600999999997, 45.348337999999998,\
					46.983074999999999, 48.617812000000001, 50.252549999999999, 51.878118000000001, 53.512855000000002,\
					55.147592000000003, 56.782328999999997, 58.419463, 60.056598000000001, 62.370161000000003,\
					64.683723999999998, 66.997287, 69.310850000000002, 71.624413000000004, 73.937976000000006,\
					75.575109999999995, 77.212243999999998, 78.846981999999997, 80.481718999999998, 82.116455999999999,\
					83.742024000000001, 85.376761000000002, 87.011498000000003, 88.646235000000004, 90.280972000000006,\
					91.918107000000006, 93.555240999999995, 95.868803999999997, 98.182366999999999, 100.49593,\
					102.809493, 105.12305600000001, 107.43661899999999, 109.07375399999999, 110.710888, 112.345625,\
					113.980362, 115.615099, 117.240667, 118.875404, 120.510142, 122.144879, 123.779616,\
					125.41674999999999, 127.053884, 129.367447, 131.68100999999999, 133.994574],\
				point = [(0, 2.4341246999999999, 2.6128529999999999),\
					(0.49114020000000003, 1.9503278999999996, 2.5325198999999996),\
					(0.98228040000000005, 1.4899844999999996, 2.3634132000000001),\
					(1.4734209, 1.0692317999999996, 2.1114609000000004),\
					(0.98228040000000005, 1.0692317999999996, 2.1114609000000004),\
					(0.49114020000000003, 1.0692317999999996, 2.1114609000000004),\
					(0.49114020000000003, 0.70281809999999978, 1.7854947000000001),\
					(0.49114020000000003, 0.40358759999999982, 1.3969409999999998),\
					(0.49114020000000003, 0.1820294999999999, 0.95941979999999993),\
					(0.48826769999999997, 0.045909599999999953, 0.49114020000000003),\
					(0.95941979999999993, 0.18202949999999996, 0.49114020000000008),\
					(1.3969409999999998, 0.40358759999999988, 0.49114020000000003),\
					(1.7854946999999999, 0.7028181, 0.49114020000000003),\
					(2.1114609, 1.0692317999999998, 0.49114020000000014),\
					(2.1114609, 1.0692318000000001, 0.98228040000000016),\
					(2.1114609, 1.0692318000000001, 1.4734209),\
					(2.3634132000000001, 1.4899844999999998, 0.98228040000000005),\
					(2.5325198999999996, 1.9503279, 0.49114020000000025),\
					(2.6128529999999999, 2.4341246999999999, 2.4238995509170921e-016),\
					(2.5325198999999996, 1.9503279, -0.49114019999999975),\
					(2.3634132000000001, 1.4899845, -0.98228039999999994),\
					(2.1114609, 1.0692318000000001, -1.4734208999999998),\
					(2.1114609, 1.0692318000000001, -0.98228039999999983),\
					(2.1114609, 1.0692318000000001, -0.49114019999999986),\
					(1.7854946999999999, 0.7028181, -0.49114019999999997),\
					(1.3969409999999998, 0.40358760000000005, -0.49114019999999997),\
					(0.95941979999999993, 0.18202950000000004, -0.49114019999999992),\
					(0.48826769999999997, 0.045909600000000043, -0.49114020000000003),\
					(0.49114020000000003, 0.18202950000000009, -0.95941979999999993),\
					(0.49114020000000003, 0.40358760000000016, -1.3969409999999998),\
					(0.49114020000000003, 0.70281810000000011, -1.7854946999999997),\
					(0.49114020000000003, 1.0692318000000003, -2.1114608999999995),\
					(0.98228040000000005, 1.0692318000000003, -2.1114608999999995),\
					(1.4734209, 1.0692318000000003, -2.1114608999999995),\
					(0.98228040000000005, 1.4899845000000003, -2.3634131999999997),\
					(0.49114020000000003, 1.9503279000000002, -2.5325198999999996),\
					(0, 2.4341246999999999, -2.6128529999999999),\
					(-0.49114020000000003, 1.9503279000000002, -2.5325198999999996),\
					(-0.98228040000000005, 1.4899845000000003, -2.3634131999999997),\
					(-1.4734209, 1.0692318000000003, -2.1114608999999995),\
					(-0.98228040000000005, 1.0692318000000003, -2.1114608999999995),\
					(-0.49114020000000003, 1.0692318000000003, -2.1114608999999995),\
					(-0.49114020000000003, 0.70281810000000011, -1.7854946999999997),\
					(-0.49114020000000003, 0.40358760000000016, -1.3969409999999998),\
					(-0.49114020000000003, 0.18202950000000009, -0.95941979999999993),\
					(-0.48826769999999997, 0.045909600000000043, -0.49114020000000003),\
					(-0.95941979999999993, 0.18202950000000004, -0.49114019999999992),\
					(-1.3969409999999998, 0.40358760000000005, -0.49114019999999997),\
					(-1.7854946999999999, 0.7028181, -0.49114019999999997),\
					(-2.1114609, 1.0692318000000001, -0.49114019999999986),\
					(-2.1114609, 1.0692318000000001, -0.98228039999999983),\
					(-2.1114609, 1.0692318000000001, -1.4734208999999998),\
					(-2.3634132000000001, 1.4899845, -0.98228039999999994),\
					(-2.5325198999999996, 1.9503279, -0.49114019999999975),\
					(-2.6128529999999999, 2.4341246999999999, 2.4238995509170921e-016),\
					(-2.5325198999999996, 1.9503279, 0.49114020000000025),\
					(-2.3634132000000001, 1.4899844999999998, 0.98228040000000005),\
					(-2.1114609, 1.0692318000000001, 1.4734209),\
					(-2.1114609, 1.0692318000000001, 0.98228040000000016),\
					(-2.1114609, 1.0692317999999998, 0.49114020000000014),\
					(-1.7854946999999999, 0.7028181, 0.49114020000000003),\
					(-1.3969409999999998, 0.40358759999999988, 0.49114020000000003),\
					(-0.95941979999999993, 0.18202949999999996, 0.49114020000000008),\
					(-0.49114020000000003, 0.045909599999999953, 0.48826769999999997),\
					(-0.49114020000000003, 0.1820294999999999, 0.95941979999999993),\
					(-0.49114020000000003, 0.40358759999999982, 1.3969409999999998),\
					(-0.49114020000000003, 0.70281809999999978, 1.7854947000000001),\
					(-0.49114020000000003, 1.0692317999999996, 2.1114609000000004),\
					(-0.98228040000000005, 1.0692317999999996, 2.1114609000000004),\
					(-1.4734209, 1.0692317999999996, 2.1114609000000004),\
					(-0.98228040000000005, 1.4899844999999996, 2.3634132000000001),\
					(-0.49114020000000003, 1.9503278999999996, 2.5325198999999996),\
					(0, 2.4341246999999999, 2.6128529999999999)]\
			)
				print "Arrow 3 had been created!"
				
			if (Test==7):
				object_name = cmds.curve( degree = 1,\
				knot = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,\
					21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41],\
				point = [(0.54489100000000001, 0, -1.0972170000000001),\
					(-0.54489100000000001, 0, -1.0972170000000001),\
					(-0.57190399999999997, 0, -1.448294),\
					(-0.51227900000000004, 0, -1.7534350000000001),\
					(-0.39327099999999998, 0, -1.92306),\
					(-0.26683899999999999, 0, -2.0357470000000002),\
					(-0.133965, 0, -2.097731),\
					(0, 0, -2.1201279999999998),\
					(0.133965, 0, -2.097731),\
					(0.26683899999999999, 0, -2.0357470000000002),\
					(0.39327099999999998, 0, -1.92306),\
					(0.51227900000000004, 0, -1.7534350000000001),\
					(0.57190399999999997, 0, -1.448294),\
					(0.54489100000000001, 0, -1.0972170000000001),\
					(0.54505400000000004, 0, -0.74610399999999999),\
					(0.59780699999999998, 0, -0.41958600000000001),\
					(0.67365600000000003, 0, -0.12723699999999999),\
					(0.74920699999999996, 0, 0.167214),\
					(0.82460199999999995, 0, 0.55612799999999996),\
					(0.84614400000000001, 0, 0.82138999999999995),\
					(0.81947400000000004, 0, 1.166447),\
					(0.73763100000000004, 0, 1.452029),\
					(0.636486, 0, 1.6792670000000001),\
					(0.51900800000000002, 0, 1.858641),\
					(0.39550400000000002, 0, 1.9981),\
					(0.266596, 0, 2.09545),\
					(0.134293, 0, 2.163449),\
					(-1.6742199999999999e-006, 0, 2.182925),\
					(-0.13416, 0, 2.1634199999999999),\
					(-0.26677899999999999, 0, 2.095529),\
					(-0.39547199999999999, 0, 1.99807),\
					(-0.51899300000000004, 0, 1.8586320000000001),\
					(-0.63649599999999995, 0, 1.679268),\
					(-0.73763199999999995, 0, 1.452024),\
					(-0.81947400000000004, 0, 1.166445),\
					(-0.84614400000000001, 0, 0.82138699999999998),\
					(-0.82460199999999995, 0, 0.55612799999999996),\
					(-0.74920600000000004, 0, 0.167213),\
					(-0.67365600000000003, 0, -0.12723699999999999),\
					(-0.59780800000000001, 0, -0.41958699999999999),\
					(-0.54505400000000004, 0, -0.74610399999999999),\
					(-0.54489100000000001, 0, -1.0972170000000001)]\
			)
				print "Foot has been created!"
				
			if (Test==8):
				object_name = cmds.curve( degree = 1,\
			knot = [0, 4, 8, 12, 16, 24.485281000000001, 32.970562999999999, 36.970562999999999,\
					45.455843999999999, 53.941125, 57.941125, 66.426406999999998, 74.911687999999998],\
			point = [(-0.80000000000000049, 3.2000000000000002, 0.80000000000000004),\
					(0.7999999999999996, 3.2000000000000002, 0.80000000000000004),\
					(0.7999999999999996, 3.2000000000000002, -0.80000000000000004),\
					(-0.80000000000000049, 3.2000000000000002, -0.80000000000000004),\
					(-0.80000000000000049, 3.2000000000000002, 0.80000000000000004),\
					(0, 0, 0),\
					(0.7999999999999996, 3.2000000000000002, 0.80000000000000004),\
					(0.7999999999999996, 3.2000000000000002, -0.80000000000000004),\
					(0, 0, 0),\
					(-0.80000000000000049, 3.2000000000000002, -0.80000000000000004),\
					(-0.80000000000000049, 3.2000000000000002, 0.80000000000000004),\
					(0, 0, 0),\
					(0.7999999999999996, 3.2000000000000002, 0.80000000000000004)]\
			)
				print "Pyrimid Point have been created!"

			#changing the name of the control shape using the info from user
		
			
			joint_name1 = str(JointList).replace("[u'jnt_", "").replace("']", "")
			print object_name
			circleName = cmds.rename(object_name, "ctrl_"+joint_name1)
		
		
		
		
		
			#group the circle
			group_name = cmds.group();
			new_Group_name = cmds.rename(group_name, "grp_"+joint_name1+"_offset")
			
			#Select group and joint
			cmds.select(new_Group_name)
			cmds.select(JointList, add=True)
		
			#Parent group and joint
			cmds.Parent()
		
		
			#Select and set the translate and rotation to the value of 0
			cmds.select(new_Group_name)
			cmds.setAttr(new_Group_name + ".rotate", 0, 0, 0);
			cmds.setAttr(new_Group_name + ".translate", 0, 0, 0);
		
			#Select the group and unparent it from the selected joint.
			cmds.select(new_Group_name);
			cmds.parent(w=1);
			
	except: #if this part of the code does not work then print this
		print("Error performing this action, unknowed reason.")
	
	
def ColourChange(*args):
	
	#Click the NurbCurve and change the colour
	#try:
	NurbCurve = cmds.ls(selection = True, type = ("transform", 'nurbsCurve'), noIntermediate=True, leaf=True, dag=True )
	CurveNameOverride = str(NurbCurve) + ".overrideEnabled"
			
	cmds.setAttr(CurveNameOverride.replace("[u'", "").replace("']", "") , 1);
		
	#choosing the colour
		
		
		
	#except:
	#	print("Hello user! You have not selected a nurbCurve.")
		
	Colours = cmds.colorIndexSliderGrp(colour, query=True, value=31)
	CurveNameCColor = str(NurbCurve) + ".overrideColor"
	cmds.setAttr(CurveNameCColor.replace("[u'", "").replace("']", ""), Colours-1) #-1 to get the cell number in the array of colour 
	
def ScalingSlide(*args):
	
	#select the transform
	Scales = cmds.ls(selection = True, type = ('transform'))
	scalesName = str(Scales).replace("[u'", "").replace("']", "")
	ActivateSelectMode= cmds.selectType(objectComponent=True)
	hullMode = cmds.selectType(hull=True)
	cmds.select(scalesName+".cv[0:7]")
	
	#Scaling with slider
	scalingSlider = cmds.floatSlider(scaleSlider, query=True, value=True)
	print scalingSlider
	cmds.scale(scalingSlider,scalingSlider,scalingSlider)
	
def ScalingText(*args):
	
	#select the transform
	Scales = cmds.ls(selection = True, type = ('transform'))
	scalesName = str(Scales).replace("[u'", "").replace("']", "")
	ActivateSelectMode= cmds.selectType(objectComponent=True)
	hullMode = cmds.selectType(hull=True)
	cmds.select(scalesName+".cv[0:7]")
	
	#Scaling with textfield
	X_tf = cmds.textField(x, query=True, text=True)
	Y_tf = cmds.textField(y, query=True, text=True)
	Z_tf = cmds.textField(z, query=True, text=True)
	print Y_tf
	cmds.scale(int(X_tf),int(Y_tf),int(Z_tf))


	
	
#Create a main layout
cmds.rowColumnLayout(numberOfRows=2, rowHeight=[(1,100), (2, 400)] )

#Banner image
imagePath = cmds.internalVar(upd = True) + "icons/adjustingyourctrlshape.jpg"
cmds.image(w = 300, h = 100, image = imagePath)

#making a tab system

tabs = cmds.tabLayout(innerMarginWidth=5, innerMarginHeight=5)


#creating columns and the creating control shape ctrl menu
#Nurb circle create
child1 = cmds.rowColumnLayout( numberOfRows=3, rowHeight=[(1, 80), (2, 50), (3, 40)] )

#dropdown list

Shapeist = cmds.optionMenuGrp(label="Select Shape: ")
Cube = cmds.menuItem(label="Cube")
Circle = cmds.menuItem(label="Circle")
Sphere = cmds.menuItem(label="Sphere")
Arrow1 = cmds.menuItem(label="Arrow 1 (one point)")
Arrow2 = cmds.menuItem(label="Arrow 2 (four points)")
Arrow3 = cmds.menuItem(label="Arrow  3 (four points curved)")
Foot = cmds.menuItem(label="Foot")
Pyrimid_Point = cmds.menuItem(label="Pyrimid Point")

#create button
cmds.text(label="Select Joint: ")
cmds.button(label="Create", command=CreateCtrl)
cmds.setParent( ".." )

#Creating the colour menu

child2 = cmds.rowColumnLayout( numberOfRows=3, w=(100), rowHeight=[(1, 40), (2,20), (3, 40)] )

cmds.text( label="Select nurbCurve")
colour = cmds.colorIndexSliderGrp( label="Colour Of Ctrl Shape:  ", min=0, max=32)
cmds.button(label="Apply", command=ColourChange)
cmds.setParent( ".." )

#Scaling tab

child3 = cmds.rowColumnLayout("tabThree", numberOfRows=8, rowHeight=[(1,50), (2, 50), (3,40), (4,50), (5,20), (6,20), (7,20), (8,40)] )

cmds.text( label="Scale:")
scaleSlider = cmds.floatSlider( min=-0, max=50, step=1)
cmds.button(label="Apply", width=10, command=ScalingSlide)
cmds.text(label="XYZ Scale:")
x = cmds.textField()
y = cmds.textField()
z = cmds.textField()
cmds.button(label="Apply", command=ScalingText)
cmds.setParent( ".." )

#labelling tabs
cmds.tabLayout(tabs, edit=True, tabLabel=((child1, "Creating Control Shape"), (child2, "Colour"), (child3, "Scaling")) )



#Show Window
cmds.showWindow(window)

A couple of general things:

  • Don’t start variables or functions with capital letters, most people expect that naming convention to denote a python class.

  • Use the [ CODE ] tag when pasting code, it makes it easier to identify and maintains whitespace better.

  • In Python 2.6 (which maya uses), print is a statement, not a function, so no parentheses are needed ( print “hello”, not print(“hello”) )

  • This code for example:

JointList = cmds.ls(selection = True, type = ('joint'))

if (str(JointList)=="[]"):
    print("Hello user! You have not selected a joint!")

str(JointList)=="[]" is completely unnecessary, an empty list evaluates as boolean False, so this has the same result:

joints = cmds.ls(selection=True, type='joint')
if not joints:
    print "hello user!...."
  • JointList is a list, and you can access each item in the list using slice notation. Don’t do this:
joint_name1 = str(JointList).replace("[u'jnt_", "").replace("']", "")

Do this:

joint_name1 = JointList[0].replace('jnt_', '')
  • You should very rarely need to select something before calling a function in maya. Things like parent can be passed arguments that tell it what to parent.
cmds.select(new_Group_name)
cmds.select(JointList, add=True)

#Parent group and joint
cmds.Parent()

Can be:

cmds.parent(new_Group_name, JointList)

Same thing with unparenting:

cmds.parent(new_Group_name, w=True)
  • Don’t use blanket try/expect statements. Having something that says “Error performing this action, unknowed reason.” doesn’t help anyone, least of all you. Try to only use try/expect statements when you know what errors you want to catch.

capper- Great advice!
Only thing is about print- print “foo” and print (“foo”) are actually different:
>>> foo
>>> (“foo”,)
Because print is a statement it treats the second ‘form’ as printing a tuple.
Nitpick but now you don’t need to make a stylistic argument, it is a black and white functional one :slight_smile:

That’s true, though I don’t think he was including a trailing comma was he? Either way a good distinction.