我试图打印出一系列动画定位器(名为tracker1,tracker2等)随时间推移的xyz坐标。我需要将定位器的xyz数据重新转换为文本文件,以便我可以将其带入备用跟踪程序。我知道我需要在基础级别上运行一个mel或python脚本,在脚本编辑器中的完整列表中打印出xyz数据,但是语法有问题。我可以处理文本文件本身,我也不需要同时为所有定位器编译脚本,尽管这样会很棒。知道怎么做吗?
经修订的:
好的,这就是我们现在所拥有的
我们正在使用这个脚本,并成功生成单帧的xyz值
示例:项目名称“tracker1”,
框架:框架“1”
脚本:
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
事情是,我们需要序列中每一帧的xyz信息(第1-68帧) 提前致谢
答案 0 :(得分:2)
我在 Python 中写道,这可以在每一帧记录所有选定对象'translate attr ,
和写入.txt
文件。
start
帧和end
帧由时间滑块的播放范围定义。
# .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
cmd 梅尔:
currentTime -e $frame
的Python:
cmds.currentTime(frame, e= 1)
for loop
并设置开始,结束帧编号梅尔:
// 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...