setDrivenKeyframe question

397 views
Skip to first unread message

Vitor Lôbo Ramos

unread,
Dec 16, 2009, 5:40:30 PM12/16/09
to python_inside_maya, vitaumm...@gmail.com
Good night
I'm having trouble making a setdriven key in python.
Well out, what I'm wanting is something very much like this:


addAttr -ln "Roll" -at double -min 0 -max 10 -dv 0 |nurbsCircle1;
setAttr -e-keyable true |nurbsCircle1.Roll;
setDrivenKeyframe -currentDriver nurbsCircle1.Roll pCube1.rotateX;
setAttr "nurbsCircle1.Roll" 10;
rotate -r -os 90 ;
setDrivenKeyframe -currentDriver nurbsCircle1.Roll pCube1.rotateX;

python would that be?

Are 2 objects. A circle and a cube.
In the circle, I create an attribute value to float default 0, min 0,
max 10. Therefore, I create a key Setdriven between the circle and the
cube. where the value 10, the cube rotates in the X axis 90 degrees.

I'm having a little difficulty in building the code.




Phil Sloggett

unread,
Dec 16, 2009, 6:05:53 PM12/16/09
to python_in...@googlegroups.com
I think the setDrivenKeyframe command in mel is a bit flexible like that - there are arguments for attribute but it also lets you pass the whole node+attribute as an object to the command. The python command might be a little less flexible? while I doubt it, I know for a fact that the following form works. In script, I also tend to avoid using commands like rotate as they get a bit redundant when you can pass appropriate values to the commands you want without modifying your scene.

cube = mc.polyCube()[0]
circle = mc.circle()[0]
mc.addAttr(circle,ln='Roll',at='double',min=0,max=10,dv=0,k=1) #note the k=1, makes the next setAttr line redundant.
mc.setDrivenKeyframe(cube,at='rotateX',cd=circle+'.Roll',dv=0,v=0) #by specifying 'driverValue' and 'value' we dont need to modify/
mc.setDrivenKeyframe(cube,at='rotateX',cd=circle+'.Roll',dv=10,v=90) #the objects' attributes the way you would in the GUI.

2009/12/17 Vitor Lôbo Ramos <vitaumm...@gmail.com>

Vitor Lôbo Ramos

unread,
Dec 16, 2009, 6:24:49 PM12/16/09
to python_inside_maya
Exactly. I'm trying to avoid any redundancy and without complex
methods. For this reason, it is very important and very helpful to
know the point of view of each in respect of each command.




On Dec 16, 8:05 pm, Phil Sloggett <philslogg...@gmail.com> wrote:
> I think the setDrivenKeyframe command in mel is a bit flexible like that -
> there are arguments for attribute but it also lets you pass the whole
> node+attribute as an object to the command. The python command might be a
> little less flexible? while I doubt it, I know for a fact that the following
> form works. In script, I also tend to avoid using commands like rotate as
> they get a bit redundant when you can pass appropriate values to the
> commands you want without modifying your scene.
>
> cube = mc.polyCube()[0]
> circle = mc.circle()[0]
> mc.addAttr(circle,ln='Roll',at='double',min=0,max=10,dv=0,k=1) #note the
> k=1, makes the next setAttr line redundant.
> mc.setDrivenKeyframe(cube,at='rotateX',cd=circle+'.Roll',dv=0,v=0) #by
> specifying 'driverValue' and 'value' we dont need to modify/
> mc.setDrivenKeyframe(cube,at='rotateX',cd=circle+'.Roll',dv=10,v=90) #the
> objects' attributes the way you would in the GUI.
>
> 2009/12/17 Vitor Lôbo Ramos <vitaummprima...@gmail.com>

Vitor Lôbo Ramos

unread,
Dec 16, 2009, 6:35:28 PM12/16/09
to python_inside_maya
Phil Sloggett

His method seemed very well resolved. Thank you for your help.

Vitor Lôbo Ramos

unread,
Dec 20, 2009, 4:26:07 PM12/20/09
to python_inside_maya

def tmirror():

b1 = controler
b2 = obj

cmds.setDrivenKeyframe( 'b2.tx', cd='b1.tx', dv=0,v=0 )
cmds.setDrivenKeyframe( 'b2.tx', cd='b1.tx', dv=20,v=-20 )
cmds.setDrivenKeyframe( 'b2.tx', cd='b1.tx', dv=-20,v=20 )

What am I doing wrong?

I want to create a simple setdrivenkey where the motion controls in
positions x, y, z, and this monitor.

Paul Molodowitch

unread,
Dec 20, 2009, 4:48:01 PM12/20/09
to python_in...@googlegroups.com
def tmirror():

  b1 = controler
  b2 = obj

  cmds.setDrivenKeyframe( 'b2.tx', cd='b1.tx', dv=0,v=0 )
  cmds.setDrivenKeyframe( 'b2.tx', cd='b1.tx', dv=20,v=-20 )
  cmds.setDrivenKeyframe( 'b2.tx', cd='b1.tx', dv=-20,v=20 )


Using the commands as you've given them, maya is looking for objects whose NAMES are 'b1' and 'b2'.  Your variables b1 and b2 are never even used.

You'd need to do something like this:

cmds.setDrivenKeyframe( b2 + '.tx', cd=b1+'.tx', dv=0,v=0 )

or, equivalently:

cmds.setDrivenKeyframe( '%s.tx' % b2, cd=('%s.tx' % b1), dv=0,v=0 )

(I'm assuming that the rest of your syntax here is correct... I haven't bothered to check it.)

- Paul
 
What am I doing wrong?

I want to create a simple setdrivenkey where the motion controls in
positions x, y, z, and this monitor.

Vitor Lôbo Ramos

unread,
Dec 20, 2009, 5:03:47 PM12/20/09
to python_inside_maya

For some strange reason, yet, not funcina.
The code below works perfectly without (def name ()).
Now does not work. Why?

cmds.setDrivenKeyframe( 'b2.ty', cd='b1.ty', dv=0,v=0 ) # functional

#But, with def

def teste():

b1 = controler
b2 = obj

cmds.setDrivenKeyframe( b2 + '.tx', cd=b1+'.tx', dv=0,v=0 ) # not
work


cmds.setDrivenKeyframe( '%s.tx' % b2, cd=('%s.tx' % b1), dv=0,v=0 )

# not work
cmds.setDrivenKeyframe( 'b2.tx', cd='b1.tx', dv=20,v=-20 ) # not
work

Vitor Lôbo Ramos

unread,
Dec 20, 2009, 5:07:31 PM12/20/09
to python_inside_maya
Correcting:

cmds.setDrivenKeyframe( 'name1.ty', cd='name2.ty', dv=0,v=0 ) #
functional


# But, with def

.......

When I try to organize in def, no functionality


On Dec 20, 7:03 pm, Vitor Lôbo Ramos <vitaummprima...@gmail.com>
wrote:

Paul Molodowitch

unread,
Dec 20, 2009, 11:47:08 PM12/20/09
to python_in...@googlegroups.com
Some questions:

1) What's the error you get?
2) Where are controler and obj defined?
3) What's the point of having b1 and b2, anyway? Why not just use controler and obj?

- Paul

2009/12/20 Vitor Lôbo Ramos <vitaumm...@gmail.com>

Vitor Lôbo Ramos

unread,
Dec 21, 2009, 12:45:13 AM12/21/09
to python_inside_maya
1 -) There is no error. But there is no action, function.
2 -) Noting that "obj" in this case is only a prefix
3 -) I tried to use commonly without controler = b1, b2 = obj (but
does not work) when you create a ref.

The intention here is just create a setdrivenkey between 2 objects.
Example: Driver and Control, Obj is Driven. I move the Controller
translateX 20, and move the obj translateX -20. With that, I key.

Exemple:

import maya.cmds as cmds

cmds.setDrivenKeyframe( 'obj.tx', cd='controler.tx', dv=0,v=0 ) # work
cmds.setDrivenKeyframe( 'obj.tx', cd='controler.tx', dv=20,v=-20 )#
work
cmds.setDrivenKeyframe( 'obj.tx', cd='controler.tx', dv=-20,v=20 )
#work


Using a: def rtest ():

cmds.setDrivenKeyframe( 'obj.tx', cd='controler.tx', dv=0,v=0 ) #
not work
cmds.setDrivenKeyframe( 'obj.tx', cd='controler.tx', dv=20,v=-20 )
# not work
cmds.setDrivenKeyframe( 'obj.tx', cd='controler.tx', dv=-20,v=20 )
# not work

the above methods also did not work .... what am I doing wrong?

Another method tested:

b1 = controler
b2 = obj

cmds.setDrivenKeyframe(b2,at='translateX', cd=b1, dv=0,v=0 ) # not
work

On Dec 21, 1:47 am, Paul Molodowitch <elron...@gmail.com> wrote:
> Some questions:
>
> 1) What's the error you get?
> 2) Where are controler and obj defined?
> 3) What's the point of having b1 and b2, anyway? Why not just use controler
> and obj?
>
> - Paul
>

> 2009/12/20 Vitor Lôbo Ramos <vitaummprima...@gmail.com>

Chad Dombrova

unread,
Dec 21, 2009, 1:14:39 AM12/21/09
to python_in...@googlegroups.com
after you defined the function, did you call it?

def foo()
cmds.someJunk()

foo() #<------ call the function

> --
> http://groups.google.com/group/python_inside_maya

Vitor Lôbo Ramos

unread,
Dec 21, 2009, 10:09:11 AM12/21/09
to python_inside_maya


a little question: When set a call, it does not run by "select all +
execute, enter a pad? I'm sure he had done it before and funcina.
Unless, that is isolated in codigos. I'm confused now.

The code has to work when I call the "test ()" on the command line
python.

Now the code works. However, only a restricted calling line def.

Vitor Lôbo Ramos

unread,
Dec 21, 2009, 11:53:18 AM12/21/09
to python_inside_maya
I tested the code on another machine and it worked. That is, the
problem is even in my maya. (Unfortunately, this happens)

Sorry the confusion Guys.

On Dec 21, 12:09 pm, Vitor Lôbo Ramos <vitaummprima...@gmail.com>

Reply all
Reply to author
Forward
0 new messages