Python script with arguments for command line Blender

孤街醉人 提交于 2019-11-30 12:41:50
roho

I found the solution for what I was looking for intially.

As Junuxx said "You can't pass command line arguments directly to python in this situation..." but you actually CAN pass arguments to python but in another situation.

So the way to do what i want is to RENDER AND SAVE DIRECTLY INSIDE the python script

import sys

fov = float(sys.argv[-1])   
...
# Set Scenes camera and output filename 
bpy.data.scenes["Scene"].render.file_format = 'PNG'
bpy.data.scenes["Scene"].render.filepath = '//out'

# Render Scene and store the scene 
bpy.ops.render.render( write_still=True ) 

The --python option (or -P) has to be at the end and you can specify arguments with -- and just load the model and run the script.

> blender -b "demo.blend" -P script.py -- 50

Credit to this link I found: http://www.blender.org/forum/viewtopic.php?t=19102&highlight=batch+render

You can't pass command line arguments directly to python in this situation, because they are interpreted as arguments for blender. A way around this is to set environment variables and then call blender/python, like this (assuming you're on Windows - the same thing is possible on other OSs, but with different syntax)

set arg1='foo' & set arg2='bar' & python envvar.py

Note: no spaces adjacent to the equals signs!

In the python script I called envvar.py, you can use os.getenv() to access these variables

import os
print 'arg1 = ', os.getenv('arg1')
print 'arg2 = ', os.getenv('arg2')

Output:

arg1 = 'foo'
arg2 = 'bar'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!