Writing returned values to plot a graph

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  07 July 2013
Writing returned values to plot a graph

Hi there,

I have a script which returns Euler angles of a specific joint at the frame which the script is run at. What I am wanting to do is run this script throughout the animation to plot the returned Euler angles for every frame over time.

import maya.cmds as cmd
from vectors import Matrix

localHips = Matrix( cmd.getAttr( 'BVH:Hips.matrix' ) )
localUpLeg = Matrix( cmd.getAttr( 'BVH:RightUpLeg.matrix' ) )
localLeg = Matrix( cmd.getAttr( 'BVH:RightLeg.matrix' ) )
localFoot = Matrix( cmd.getAttr( 'BVH:RightFoot.matrix' ) )
localHeel = Matrix( cmd.getAttr( 'BVH:RightFootHeel.matrix' ) )
localEnd = Matrix( cmd.getAttr( 'BVH:RightFootHeel_End.matrix' ) )

worldHips = Matrix( cmd.getAttr( 'BVH:Hips.worldMatrix' ) )
worldUpLeg = Matrix( cmd.getAttr( 'BVH:RightUpLeg.worldMatrix' ) )
worldLeg = Matrix( cmd.getAttr( 'BVH:RightLeg.worldMatrix' ) )
worldFoot = Matrix( cmd.getAttr( 'BVH:RightFoot.worldMatrix' ) )
worldHeel = Matrix( cmd.getAttr( 'BVH:RightFootHeel.worldMatrix' ) )
worldEnd = Matrix( cmd.getAttr( 'BVH:RightFootHeel_End.worldMatrix' ) )

eulerXYZ = localFoot.ToEulerXYZ( degrees=True )

print eulerXYZ

This is the script, which returns
[8.089659570923553 -7.1246470579741645 0.30448006832249608]

How might I go about plotting these angles (or 1 of these angles e.g. rotateZ) over say 160 frames? Perhaps write them to an xml file or something?


  07 July 2013
just in case you're an engineer and not an animator or possibly don't know maya very well I'll get this out of the way;
There's already a built-in UI for that, called the graph editor, shows a plotted curve of selected nodes animated attributes over time, attributes like rotation.

If you just said "no shit, I want something else that the graph editor doesn't do", then;
yes you could write the data to a text file, cvs, xml, etc, see python docs on Input and Output.
Incidentally you could also just query the graph editor for this info all at once instead of getting it one tick at a time.
  07 July 2013
Hi palohman, thanks for replying.

Yes I'm familiar with Maya and the graph editor. The trouble with this for what I want is that it only plots the values which are displayed in the channel box/attribute editor.

What I am wanting to plot is something which isn't in there. I have a script which computes the Euler angles by decomposing the transformation matrix of a given node - in this case, the ankle joint of a character. The script however calculates this for the frame that it is run, and what I want is for each frame of the animation to be calculated and the results written to a text file (ideally xml) so that I can use the results to plot a graph.

I would presume the code given in the previous post (or at least the last line of it) needs putting into a loop so that it runs for each frame of the animation and writes this to a text file. The problem is I'm no programmer by any stretch of the imagination and don't have a clue how to go about this.

Hope that makes sense, and somebody will be able to help me out

  07 July 2013
myFile = filePath+fileName
f = open(myFile ,'a')
for i in range(startTime,endTime):
    cmds.currentTime(i) # sets the time to that frame
    info = getSomeInfo()

if you want to use the playback range to define the start/end time
startTime = int( cmds.playbackOptions( q=True, minTime=True ) )
endTime = int( cmds.playbackOptions( q=True, maxTime=True ) )
  07 July 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 04:29 AM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.