在macos中不用打开blender软件将blend模型批量导出obj
版块:Blender
发表于:2025-08-21
创建一个新的shell脚本 export_all_v4.sh
#!/bin/bash
# 设置目录路径
BLEND_DIR="/Users/zhangbo/Desktop/Blende卡通元宇宙科技网络智能产品图标3D模型PNG设计素材25款/BLEND"
# 切换到目标目录
cd "$BLEND_DIR"
# 遍历所有.blend文件
for blend_file in *.blend; do
if [ -f "$blend_file" ]; then
echo "正在处理: $blend_file"
# 获取不含扩展名的文件名
filename="${blend_file%.blend}"
# 使用Blender命令行模式处理文件
/Applications/Blender.app/Contents/MacOS/Blender \
"$blend_file" \
--background \
--python-expr "
import bpy
import os
# 启用OBJ插件
try:
bpy.ops.preferences.addon_enable(module='io_scene_obj')
except:
pass
# 获取文件名
filename = bpy.path.basename(bpy.data.filepath).replace('.blend', '')
obj_path = os.path.join(os.path.dirname(bpy.data.filepath), filename + '.obj')
# 选择所有对象
bpy.ops.object.select_all(action='SELECT')
# 尝试导出
try:
# Blender 4.x 新版导出器
bpy.ops.wm.obj_export(
filepath=obj_path,
export_selected_objects=False,
export_uv=True,
export_normals=True,
export_materials=True
)
print(f'导出成功: {obj_path}')
except:
try:
# 旧版导出器
bpy.ops.export_scene.obj(
filepath=obj_path,
use_selection=False,
use_materials=True,
use_uvs=True,
use_normals=True
)
print(f'导出成功(旧版): {obj_path}')
except Exception as e:
print(f'导出失败: {e}')
"
echo "完成处理: $blend_file"
echo "---"
fi
done
echo "所有文件处理完成!"执行步骤:
1.保存上述脚本为 export_all_v4.sh,放在某个文件夹或桌面上
2.打开终端,执行以下:
将放export_all_v4.sh文件的父级目录拖到“cd ”空格后面,例如:
cd /Users/blender/Desktop/blmodel
回车
3.在终端中给脚本添加执行权限:
chmod +x export_all_v4.sh
4.运行脚本:
./export_all_v4.sh




