Reputation: 11
I am trying to print out the xyz coordinates over time of a series of animating locators (named tracker1, tracker2, etc). I need to reconvert the locator's xyz data into a text file so I can then bring it into an alternate tracking program. I know that what I need to do on a base level is run a mel or python script to print out the xyz data in a complete list within the script editor, but am having trouble with syntax. The text file itself I can take care of, and I do not need a compiling script for all the locators at once either, though that would be great. Any idea how to do this?
Revised:
Ok so here is what we have right now.
We are using this script, and successfully generating the xyz values for a single frame.
Example: item name "tracker1",
frame: frame "1"
Script:
for ($item in `ls -sl`){
$temp=`xform -q -t -ws $item `;
print ($temp[0]+" "+$temp[1]+" "+$temp[2]+"\n");};
0.1513777615 22.7019734 176.3084331
Thing is, we need this xyz information for every frame in the sequence (frames 1-68).
Thanks in advance
Upvotes: 1
Views: 1034
Reputation: 95
I wrote in Python, this can record all selected objects' translate attr at every frame,
and write in to a .txt
file.
start
frame and end
frame was defined by time slider's playback range.
# .txt file path where you want to save, for example C:/trackInfo.txt
outPath = 'C:/trackInfo.txt'
# start time of playback
start = cmds.playbackOptions(q= 1, min= 1)
# end time of playback
end = cmds.playbackOptions(q= 1, max= 1)
#locators list
locList = cmds.ls(sl= 1)
if len(locList) > 0:
try:
# create/open file path to write
outFile = open(outPath, 'w')
except:
cmds.error('file path do not exist !')
# info to write in
infoStr = ''
# start recoard
for frame in range(int(start), int(end + 1)):
# move frame
cmds.currentTime(frame, e= 1)
# if you need to add a line to write in frame number
infoStr += str(frame) + '\n'
# get all locators
for loc in locList:
# if you need to add a line to write in locator name
infoStr += loc + '\n'
# get position
pos = cmds.xform(loc, q= 1, t= 1, ws= 1)
# write in locator pos
infoStr += str(pos[0]) + ' ' + str(pos[1]) + ' ' + str(pos[2]) + ' ' + '\n'
# file write in and close
outFile.write(infoStr)
outFile.close()
else:
cmds.warning('select at least one locator')
currentTime
cmdMel:
currentTime -e $frame
Python:
cmds.currentTime(frame, e= 1)
for loop
and set start, end frame numberMel:
// in your case
int $start = 1;
int $end = 68;
for( $frame = $start; $frame < $end + 1; $frame++ ){
currentTime -e $frame;
// do something...
}
Python:
# in your case
start = 1
end = 68
for frame in range(start, end + 1):
cmds.currentTime(frame, e= 1)
# do something...
Upvotes: 2