批量导入obj文件
import bpy
import os
import pathlib
obj_root = pathlib.Path('G:/GLTF/SLH_DB/CJXData/CJXTiles/Data/')
txt = os.path.join(obj_root, 'Tile_Export.txt')
with open(txt, 'rt') as f:
for line in f:
target_file = os.path.join(obj_root, line[0:len(line)-1], line[0:len(line)-1] + '.obj')
bpy.ops.wm.obj_import(filepath=target_file, forward_axis='Y', up_axis='Z')
f.close
批量导出obj文件
import bpy
import os
import pathlib
obj_root = pathlib.Path('D:/temp/Data')
def make_path(url):
# 创建保存路径
if not os.path.exists(url): # 判断存储文件路径是否存在,不存在就自动创建
os.makedirs(url)
scene = bpy.context.scene
for ob in scene.objects:
bpy.ops.object.select_all(action='DESELECT')
# make the current object active and select it
bpy.context.view_layer.objects.active = ob
ob.select_set(True)
# make sure that we only export meshes
target_file = os.path.join(obj_root, ob.name, ob.name + '.obj')
if ob.type == 'MESH' and ob.name!= 'Plane':
# 创建保存路径
make_path(os.path.join(obj_root, ob.name))
# export the currently selected object to its own file based on its name
bpy.ops.wm.obj_export(filepath=target_file, export_selected_objects=True, forward_axis='Y', up_axis='Z')

1990

被折叠的 条评论
为什么被折叠?



