简体   繁体   中英

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).

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.

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. The second of these is what you are assigning to 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). Use bpy.ops.render.render(write_still=True) to have the rendered image saved to disk. You may also want to set bpy.context.scene.render.filepath to specify where the image is saved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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