简体   繁体   English

Blender脚本-导入Collada文件并将其另存为.blend

[英]Blender Scripting - Import Collada file and save it as .blend

Right now, I have a script in python that converts a collada (.dae) file into a blender file (.blend). 现在,我在python中有一个脚本,可将collada(.dae)文件转换为Blender文件(.blend)。

In the command Line: 在命令行中:

C:\Program Files\Blender Foundation\Blender>blender.exe --background --python c:\Users\c.diaz\Desktop\convert_collada_to_blend.py -- c:\Users\c.diaz\Desktop
\Maya.dae -- c:\Users\c.diaz\Desktop\Result.blend

My script: 我的剧本:

import bpy
import sys

argv = sys.argv
argv = argv[argv.index("--") + 1:] # get all args after "--"

dae_in = argv[0]
blend_out = argv[1]

bpy.ops.wm.collada_import(filepath=dae_in)
bpy.ops.render.render()
bpy.ops.wm.save_mainfile(filepath=blend_out)

After executing the command, I get a lot of output indicating that It's actually doing something. 执行完命令后,我得到很多输出,表明它实际上在做某事。 However, at the end of the process, I don't know where the result file is being saved. 但是,在过程结束时,我不知道结果文件保存在哪里。

Any Help From you guys, I'll appreciate it. 大家的帮助,我们将不胜感激。

Look for a file named -- in the current directory when you enter the command, in the temp directory, or possibly the same dir as blender.exe. 输入命令时,在当前目录中,在temp目录中,或者可能与blender.exe相同的目录中,找到一个名为--的文件。

The location of the temp directory may vary, try 临时目录的位置可能有所不同,请尝试

import tempfile
print(tempfile.gettempdir())

You use argv = argv[argv.index("--") + 1:] to get the args after the first '--' which includes the extra '--' between the two paths that you are expecting to be used. 您可以使用argv = argv[argv.index("--") + 1:]来获得第一个'-'之后的args,其中第一个'-'在您期望使用的两条路径之间包括多余的'-'。 The second of these is what you are assigning to blend_out 第二个是您要分配给blend_out

I expect the command you want to use is 我希望您要使用的命令是

C:\Program Files\Blender Foundation\Blender\blender.exe --background
--python c:\Users\c.diaz\Desktop\convert_collada_to_blend.py
-- c:\Users\c.diaz\Desktop\Maya.dae c:\Users\c.diaz\Desktop\Result.blend

Also of note is your use of bpy.ops.render.render() , this doesn't save the rendered image (assuming you have a camera setup). 还要注意的是您对bpy.ops.render.render() ,这不会保存渲染的图像(假设您已经设置了摄像头)。 Use bpy.ops.render.render(write_still=True) to have the rendered image saved to disk. 使用bpy.ops.render.render(write_still=True)将渲染的图像保存到磁盘。 You may also want to set bpy.context.scene.render.filepath to specify where the image is saved. 您可能还需要设置bpy.context.scene.render.filepath来指定保存图像的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM