大家好,我是python的初学者,我的代码有问题,我想从一个特定的文件夹导入并读取所有的.BVH文件,但是程序只从文件夹。这里是我的代码。我使用blender进行可视化。在
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++
你没有在for循环中使用实际的文件。你每次都使用相同的硬编码路径。在
也许你想要像下面这样的东西?在
我将
files
重命名为file_path
,以便更好地表示该变量中的内容。然后我在对import_anim.bvh
的调用中使用了该值,然后在对export_anim.bvh
的调用中再次使用了该值。(在那里,我将"_exported.bvh"
附加到文件名的末尾。我不太确定你想做什么。)您使用
files
来计算和保持每次迭代中的当前文件路径。在迭代中,您不需要将当前文件路径输入到import_anim
,而是使用硬编码的文件路径。 另外,++
不是有效语法。在相关问题 更多 >
编程相关推荐