Newbie scripting :).: motionPath, etc

Good day!

Attached is a photo of my attempts at doing a step by step coding project. The end result will be another part of a rigging UI of my own. This particular "function "(eventually a function), will attach joints and then an animation control to the userCurve.

You can see the error. I’m not sure what I’m missing. Do I have to have the mc.ls() command to select the user’s curve?

Thanks!

Sean

import maya.cmds as mc

locName =“userSet”
mc.spaceLocator(n=locName)

mc.pathAnimation(locName,c=“curve1”)

mc.disconnectAttr(motionPath1+".u")


Still haven’t found a solution, fyi.

The image you attached is to small for me to read.
also cmds.ls() doesn’t select anything, it lists items. cmds.select() is what you’d use to actually select something.
From the code snippet that you’ve pasted though, where does motionPath1 come from? If that is supposed to be the name of your motionpath try


from maya import cmds
locName = 'userSet'
locator = cmds.spaceLocator(n=locName)
motionPath = cmds.pathAnimation(locName, c='curve1')
cmds.discconectAttr(motionPath + '.u')

[QUOTE=R.White;31108]The image you attached is to small for me to read.
also cmds.ls() doesn’t select anything, it lists items. cmds.select() is what you’d use to actually select something.
From the code snippet that you’ve pasted though, where does motionPath1 come from? If that is supposed to be the name of your motionpath try


from maya import cmds
locName = 'userSet'
locator = cmds.spaceLocator(n=locName)
motionPath = cmds.pathAnimation(locName, c='curve1')
cmds.discconectAttr(motionPath + '.u')

[/QUOTE]

Here’s a “flow chart” of the script:

Mind you, there are some things that are just filler code until I figure out how I really want to code it, or learn to code it :).
’’’
Setup for facial curve with joint controls

setup window with:
Options:
1) how many locators which determine loop number
2) base name for curves, joints, etc.
3) loops
‘’’

import maya.cmds as mc

locNam=“userSet”

#create window UI

Create locator

mc.spaceLocator(n=locName)

Attach locator to motion path c=userCurve created by user, perhaps force user to select the curve

mc.pathAnimation(locName,c= “userCurve”)

No need to disconnect rotates, as they aren’t connected this way

Instead, break connections of uValue in the input channel of the motionPath(1)

mc.disconnectAttr()

Set value of uValue for each time of loop. index[0,.50,1.0] for 3 points on curve, index [0,.25,.50,.75,1.0]for 5 points

mc.setAttr()

create joint (Offset)

mc.joint()

Parent offset joint to locator

mc.parent(‘child’,‘parent’)

Zero out offset joint’s transforms 0,0,0

mc.setAttr(.tx = 0)
mc.setAttr(.ty = 0)
mc.setAttr(.tz = 0)

Create joint (Control)

mc.joint()

Parent control joint under offset joint

mc.Parent(‘child’, ‘parent’)

Create Nurbs curve(circle, sphere, whatever)

mc.sphere(ax =[0,1,0])

Parent sphere’s shape node under control joint created.

mc.Parent(‘nurbsSphereShape1’,‘joint’)

#commands
‘’’
pathAnimation( [objects] , [bank=boolean], [bankScale=float], [bankThreshold=angle], [curve=string], [endTimeU=time], [endU=float], [follow=boolean], [followAxis=string], [fractionMode=boolean], [inverseFront=boolean], [inverseUp=boolean], [name=string], [startTimeU=time], [startU=float], [upAxis=string], [useNormal=boolean], [worldUpObject=name], [worldUpType=string], [worldUpVector=[float, float, float]])
‘’’

So without the code, which seems to just be a distraction at the moment. Let me make sure I’m understanding what you’re trying to do.

You’ve got a curve, and want to attach a string of joints along that curve, evenly spaced.
And then create a shape of some kind, and then parent each joint to one of those shapes?

[QUOTE=R.White;31113]So without the code, which seems to just be a distraction at the moment. Let me make sure I’m understanding what you’re trying to do.

You’ve got a curve, and want to attach a string of joints along that curve, evenly spaced.
And then create a shape of some kind, and then parent each joint to one of those shapes?[/QUOTE]

Why is the code confusing? Ok, with that said, yes, a curve is created based on the shape of the “face”, or whatever area it is created from. Then locators are attached to the curve via the motion path. I wrote out the steps so it would make sense. To this point, all that I was having an issue with was the “break connection”. The uValue is in the input section of the channel box. There’s no direct command to do this like maybe mc.disconnectAttr().

The echo in the script editor shows a “CBdeleteConnection”, which isn’t a common that can be placed in a script, at least not that my googling research has found. Not sure how I’d get something like disconnectAttr() to work as the maya help docs aren’t real specific for inputs which is where uValue lives.

The code wasn’t confusing, it was broken, and distracting.
It wasn’t clear that you were having a problem with disconnectAttr, because you had syntax and name errors in both sets of code that you had posted.


import maya.cmds as mc

loc = mc.spaceLocator()
curve = mc.curve(p=[(0, 0, 0), (3, 5, 6), (5, 6, 7), (9, 9, 9)])
curve_shape = mc.listRelatives(curve)[0]

path = mc.pathAnimation(loc, c=curve)
# Removes the keyframe on path.uValue
mc.cutKey(path, attribute='uValue', option='keys')

Maybe this will help, its builds a curve, and a locator, adds the motion path, and then removes he keys on the path’s uValue attribute. disconnectAttr wasn’t going to work, because path.uValue wasn’t actually connected to anything.

Hey R.!
Thanks for the reply.

so here’s how someone helped me figure it out. They were able to use the disconnect command as you will see. I was confused however, why they didn’t work with the locator who actually has shows the uValue under the input in the channel editor of the locator and not the curve selected.

Much of the looping with change when I go down through my flowchart, e.g… the request at the ui prompts for # of points to be used on curve, that will determine the loop size as well as then placing indexes locName(0), locName(1), etc or locName[0] or whatever. Then of course then the joints that are added and parented under each, etc.

I put place holders in my code until I figured out each stage, and then eventually replace the single creation to a looped variety based on the user’s desired number of points.

I was going to post this response to let everyone know a solution had been found(not by me, but rather Adam Fatka), that works, but then noticed your post.

However, thank you for showing another command. I’ll have to look that one up.

My ignorant thought process was that since I can disconnectAttr for things like translates, rotates, etc, that I would be able to address the uValue under the input in the channel box the same way. My bad.

Thanks again!

'''
Setup for facial curve with joint controls

setup window with:
    Options:
    1) how many locators which determine loop number
    2) base name for curves, joints, etc.
    3) loops 
'''

import maya.cmds as mc

locName="userSet"
objSel = mc.ls(sl=True)
objShapeSel = mc.listRelatives(objSel, shapes = True)


#create window UI


# Create locator
mc.spaceLocator(n=locName)

# Attach locator to motion path c=userCurve created by user, perhaps force user to select the curve(loop generated base on # of selections to prevent duplicates)
motionPath=mc.pathAnimation(locName,objSel)

#Iterate through each selection...
for all in objShapeSel:
	
    # Determing the connection
    mPath = list(set(mc.listConnections(all, type = 'motionPath')))
    print mPath
    
    # locate all motion paths 
    for all_mPaths in mPath:
    	
    	# Break connections on the Motion Path's 'uValue' channel.
   		 mc.disconnectAttr((all_mPaths + '_uValue.output'), (all_mPaths + '.uValue'))

Awesome, glad you were able to get a solution going!