大家好,我是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++
您没有在for循环中使用实际文件。您每次都使用相同的硬编码路径。
也许您想要类似以下的内容?
我改名为files
,file_path
以更好地表示该变量中的内容。然后,我在调用中使用了该值import_anim.bvh
,然后在调用中再次使用了该值export_anim.bvh
。(在"_exported.bvh"
该文件名的末尾添加了我的名字。我不确定自己要做什么。)
for file_path in dir:
if file_path.lower().endswith('.bvh'):
try:
bpy.ops.object.delete() # Deletes the cube
# We import a bvh file with the appropriate settings
bpy.ops.import_anim.bvh(filepath=file_path,
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')
bpy.context.scene.render.fps = 72 # We configure the frame rate
# We export the file with the appropriate settings
bpy.ops.export_anim.bvh(
filepath=file_path + '_exported.bvh',
check_existing=True, filter_glob="*.bvh",
global_scale=1.0, frame_start=1, frame_end=1515,
rotate_mode='XYZ', root_transform_only=True)
except:
print ("Couldn't open file")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句