【发布时间】:2016-10-14 15:17:19
【问题描述】:
大家好,我是 python 初学者,我的代码有问题,我想从特定文件夹导入和读取所有 .BVH 文件,但程序只从文件夹中获取第一个文件。这是我的代码.我使用搅拌机进行可视化。
import bpy # This module gives access to blender data, classes, and functions
import os # This module provides a unified interface to a number of operating system functions.
import sys # This module provides a number of functions and variables that can be used to manipulate different parts of the Python runtime environment.
path = "C:\\Users\\PC\\Desktop\\Rotate Prototype\\filtered"
dir = os.listdir("C:\\Users\\PC\\Desktop\\Rotate Prototype\\filtered")
files = 0
for files in dir:
if files.lower().endswith('.bvh'):
try:
bpy.ops.object.delete() # Deletes the cube
bpy.ops.import_anim.bvh(filepath="C:\\Users\\PC\\Desktop\\Rotate Prototype\\filtered\\pick_001_3_fil_Take_001.bvh", axis_forward='-Z', axis_up='Y', filter_glob="*.bvh", target='ARMATURE', global_scale=1.0, frame_start=1, use_fps_scale=False, update_scene_fps=False, update_scene_duration=False, use_cyclic=False, rotate_mode='NATIVE') # We import a bvh file with the appropriate settings
bpy.context.scene.render.fps = 72 # We configure the frame rate
bpy.ops.export_anim.bvh(filepath="C:\\Users\\PC\\Desktop\\Rotate Prototype\\trolled\\haha.bvh", check_existing=True, filter_glob="*.bvh", global_scale=1.0, frame_start=1, frame_end=1515, rotate_mode='XYZ', root_transform_only=True) # We export the file with the appropriate settings
except:
print ("Couldn't open file")
files++
【问题讨论】:
-
我不认为 files++ 是有效的 python 代码。
-
你有什么问题?如果您遇到错误,请在错误中显示您的输出。
-
files++应该做什么?如果它计算导入的文件,它应该在 try 子句中缩进。无论如何python不允许++运营商所以使用files += 1 -
正如所写,看起来您实际上并没有打开/使用
for循环中的任何文件。 -
这不是错误...问题是代码只读取一个文件,我希望每个 bvh 文件都进行轮换等。关于命令文件 ++ 是的,我也不确定是否正确。