Ok,
First, I did say this was my first code. Secondly, I guess I don’t know how else to ask for help.
I posted the code as I had written it. The comments, I put in there for me to keep track of what steps I am performing, I was even instructed to do that from various tutorials as instructors. I even read where they said just the opposite of what you said, comments are great for people to read code, I guess from your comments, I was instructed incorrectly.
I didn’t want to put the other code, as there is a whole process, as it’s not part of the issue. I wanted to explain the entire process thinking that would assist someone in understanding where I was going with it, instead of putting a vague one line of code and saying, “Help me, I don’t know what to do.” Can’t seem to win here.
So let me rephrase the best that I can, as you can see, I don’t understand many of the workings of Maya which can lead to a lack of better communications. I’ve been told this is how I will learn to troubleshoot, without a good solid foundation of coding. HA. I digress.
Here we go.
The intended result of this whole code is, to take curves on a facial mesh, and attach 2 forms of joints, offsets and controls. This is based on the Digital Tutors/Pluralsight course:
https://app.pluralsight.com/library/courses/joint-based-facial-rigging-maya-1133/table-of-contents
He manually goes through and:
[ol]
[li]creates the curve first.
[/li][li]creates a locator.
[/li][li]creates a motion path, attaching locator to the curve
[/li][li]manually breaks the connection on the locator’s input(in the channel box), u.Value that has a key set on it.
[/li][li]manually enters a value between 0 and 1, for each locator he creates, e.g. locators = 0, .33, .66, .99{actually 1]
[/li][li]then parents a joint to each locator, and then another parent under that joint.
[/li][/ol]
The rest isn’t necessary at this point, as I haven’t been able to break the uValue connection. Well, I actually did with:
# Delete the key set for uValue
mc.cutKey(theMoPath, attribute='uValue', option='keys')
(indentation is because of where it sits in the code)
I’ll paste my entire code, at the bottom with create window, etc. Just so you can see it all, if that helps to make sense.
The problem with the cutKey method is, when it deletes the key set, it causes other issues with the uValue; it no longer goes from 0-1, but 0-whatever and it’s not the curve length. So to avoid causing other issues, I need to find another way of disconnecting the uValue from the locator, without deselecting the locator selected at that time.
I’ve done a
con=mc.listConnections(theLoc,c=True,t="motionPath")
But it returns only:
[u’pre_object1_loc.specifiedManipLocation’, u’motionPath1’]
[u’pre_object2_loc.specifiedManipLocation’, u’motionPath2’]
[u’pre_object3_loc.specifiedManipLocation’, u’motionPath3’]
[u’pre_object4_loc.specifiedManipLocation’, u’motionPath4’]
when I input 4 :).
Ok. I think that’s it.
import maya.cmds as mc
# Declare variables
mainName = None
jntName = None
cvWin = None
cvAmt = None
mySel = None
spcLoc = []
# Get curve selected
def makeSelection():
mySel = mc.ls(selection=True)
#return name of selected objects
return mySel
usrSel = makeSelection()
# Create Window for UI(eventually a function)
if mc.window("cvWin", ex=True):
mc.deleteUI("cvWin", window=True)
mc.window("cvWin",t="Facial Curve",w=100, s=False)
mc.columnLayout("c_layout", adj =True)
mc.separator()
mc.text("Define Main Name")
mc.separator()
fieldLocPrfx = mc.textFieldGrp(l="Name of prefix:")
fieldMainName = mc.textFieldGrp(l="Name of object:")
fieldCvAmt = mc.textFieldGrp(l="Number of points:")
mc.separator()
mc.text("Please select your curve.")
mc.separator()
mc.button("Create", bgc=[0,0,1], c="moPathGen()")
mc.separator()
mc.showWindow("cvWin")
usrSel = makeSelection()
# Define moPathGen
def moPathGen():
# Query user field entries
usrPrefix = mc.textFieldGrp(fieldLocPrfx,q=True,text=True)
usrMainName = mc.textFieldGrp(fieldMainName,q=True,text=True)
usrPoints = mc.textFieldGrp(fieldCvAmt,q=True,text=True)
# for loop to create locator(s)
for i in range(1,int(usrPoints)+1):
# create locator(s)
theLoc = mc.spaceLocator(n = '{}_{}{}_loc'.format(usrPrefix, usrMainName, i))
# Add locator to list name, spcLoc[].
spcLoc.append(theLoc)
# attach locator(s) to moPath
theMoPath = mc.pathAnimation(theLoc,usrSel)
# Store connection
con=mc.listConnections(theLoc,c=True,t="motionPath")
#con = mc.listConnections(theLoc, c=True)
print con
# Delete the key set for uValue
# mc.cutKey(theMoPath, attribute='uValue', option='keys')
# disconnectAttr
# mc.disconnectAttr(theMoPath.uValue)
# call function points_along_curve to generate from list
points_along_curve(number_of_points = int(usrPoints))
# create the offset joints
mc.joint(n = '{}_{}{}_offset_Jnt'.format(usrPrefix, usrMainName, i))
# create the control joints
mc.joint(n = '{}_{}{}_control_Jnt'.format(usrPrefix, usrMainName, i))
def points_along_curve(number_of_points = 0):
##User input determines uValues along the curve
if number_of_points == 0:
return None
uValues = [0.0]
if number_of_points ==1:
print "Please enter a value greater than 1."
return uValues
for pt in range(1,number_of_points):
uValues.append(float(pt) * (1.0/(number_of_points-1)))
return uValues