blender 批量导入导出obj文件

批量导入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')

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值