我想自动将catia文件转换为.fbx或.obj。我可以使用以下代码将.stl转换为.obj:
Python代码:
import bpy
import sys
argv = sys.argv
argv = argv[argv.index("--") + 1:] # get all args after "--"
stl_in = argv[0]
obj_out = argv[1]
#Importing the file
bpy.ops.import_mesh.stl(filepath=stl_in, axis_forward='-Z', axis_up='Y')
#Exporting the file
bpy.ops.export_scene.obj(filepath=obj_out, axis_forward='-Z', axis_up='Y')
批量发布:
@echo off
set PATH=C:\Program Files\Blender Foundation\Blender
set FILENAME=object.stl
set TARGET=object.obj
blender --background --python convert_stl_to_obj.py -- %FILENAME% %TARGET%
并且它完美地工作,但是使用相同的代码将wrl写入obj或fbx是行不通的:
Python代码:
import bpy
import sys
argv = sys.argv
argv = argv[argv.index("--") + 1:] # get all args after "--"
wrl_in = argv[0]
obj_out = argv[1]
bpy.ops.import_scene.x3d(filepath=wrl_in, axis_forward='-Z', axis_up='Y')
bpy.ops.export_scene.obj(filepath=obj_out, axis_forward='-Z', axis_up='Y')
批处理:
@echo off
set PATH=C:\Program Files\Blender Foundation\Blender
set FILENAME=assemblage.wrl
set TARGET=assemblage.obj
blender --background --python convert_wrl_to_obj.py -- %FILENAME% %TARGET%
我不明白为什么,我从搅拌机那里得到了错误
找到捆绑的python:C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ python错误:数组长度不匹配(得到108, 预期更多)错误:回溯(最近一次调用最后一次):文件 " C:\ Program Files \ Blender 基金会\搅拌机\ 2.77 \脚本\插件\ io_scene _x3d__init __。py",第81行,执行中 return import_x3d.load(context,** keywords)File" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ addons \ io_scene _x3d \ import_x3d.py",第3597行,在加载中 global_matrix = global_matrix,File" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ addons \ io_scene _x3d \ import_x3d.py",第3494行,在load_web3d中 importShape(bpyscene,node,ancestry,global_matrix)文件" C:\ Program Files \ Blender 基金会\搅拌机\ 2.77 \脚本\插件\ io_scene 导入形状中的_x3d \ import_x3d.py",第3118行 bpydata = geom_fn(geom,ancestry,bpyima)文件" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ addons \ io_scene _x3d \ import_x3d.py",第1950行,在importMesh_IndexedFaceSet中 bpymesh.vertices.foreach_set(" normal",co)RuntimeError:设置数组的内部错误
位置:C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ modules \ bpy \ o ps.py:189
Traceback(最近一次调用最后一次):File" C:\ Program Files \ Blender 基金会\搅拌机\ 2.77 \脚本\插件\ io_scene _x3d__init __。py",第81行,执行中 return import_x3d.load(context,** keywords)File" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ addons \ io_scene _x3d \ import_x3d.py",第3597行,在加载中 global_matrix = global_matrix,File" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ addons \ io_scene _x3d \ import_x3d.py",第3494行,在load_web3d中 importShape(bpyscene,node,ancestry,global_matrix)文件" C:\ Program Files \ Blender 基金会\搅拌机\ 2.77 \脚本\插件\ io_scene 导入形状中的_x3d \ import_x3d.py",第3118行 bpydata = geom_fn(geom,ancestry,bpyima)文件" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ addons \ io_scene _x3d \ import_x3d.py",第1950行,在importMesh_IndexedFaceSet中 bpymesh.vertices.foreach_set(" normal",co)RuntimeError:设置数组的内部错误
位置:C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ modules \ bpy \ o ps.py:189
位置:C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ modules \ bpy \ o \ nps.py:189错误: 回溯(最近一次调用最后一次):文件" C:\ Program Files \ Blender 基金会\搅拌机\ 2.77 \脚本\插件\ io_scene _x3d__init __。py",第81行,执行中 return import_x3d.load(context,** keywords)File" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ addons \ io_scene _x3d \ import_x3d.py",第3597行,在加载中 global_matrix = global_matrix,File" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ addons \ io_scene _x3d \ import_x3d.py",第3494行,在load_web3d中 importShape(bpyscene,node,ancestry,global_matrix)文件" C:\ Program Files \ Blender 基金会\搅拌机\ 2.77 \脚本\插件\ io_scene 导入形状中的_x3d \ import_x3d.py",第3118行 bpydata = geom_fn(geom,ancestry,bpyima)文件" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ addons \ io_scene _x3d \ import_x3d.py",第1950行,在importMesh_IndexedFaceSet中 bpymesh.vertices.foreach_set(" normal",co)RuntimeError:设置数组的内部错误
位置:C:\ Program Files \ Blender Foundation \ Traceback(最新版本 最后打电话):
文件"",第2行,在文件中 " C:\ Users \ abadie-moreau \ Documents \ Migration Catia to Unity \ Migration_STL_ to_Obj \ convert_wrl_to_obj \ convert_wrl_to_obj.py", 第10行,在 bpy.ops.import_scene.x3d(filepath = wrl_in,axis_forward =' -Z',axis_up =' Y')文件" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ modules \ bpy \ ops .py",第189行,in 的呼叫 ret = op_call(self.idname_py(),None,kw)RuntimeError:错误:Traceback(最近一次调用最后一次):File" C:\ Program Files \ Blender 基金会\搅拌机\ 2.77 \脚本\插件\ io_scene _x3d__init __。py",第81行,执行中 return import_x3d.load(context,** keywords)File" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ addons \ io_scene _x3d \ import_x3d.py",第3597行,在加载中 global_matrix = global_matrix,File" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ addons \ io_scene _x3d \ import_x3d.py",第3494行,在load_web3d中 importShape(bpyscene,node,ancestry,global_matrix)文件" C:\ Program Files \ Blender 基金会\搅拌机\ 2.77 \脚本\插件\ io_scene 导入形状中的_x3d \ import_x3d.py",第3118行 bpydata = geom_fn(geom,ancestry,bpyima)文件" C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ addons \ io_scene _x3d \ import_x3d.py",第1950行,在importMesh_IndexedFaceSet中 bpymesh.vertices.foreach_set(" normal",co)RuntimeError:设置数组的内部错误
位置:C:\ Program Files \ Blender Foundation \ Blender \ 2.77 \ scripts \ modules \ bpy \ o ps.py:189
...截断Blender退出
如果有人知道我做错了什么,我会非常高兴。
感谢您的时间!