用命令行参数的Blender Python脚本 [英] Python script with arguments for command line Blender

查看:2991
本文介绍了用命令行参数的Blender Python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的搅拌器和Python。我有我想搅拌机模型(.blend)批量渲染为多个图像的每个图像提供一些属性。

I'm new to blender and python. I have a blender model (.blend) that I want to batch-render as several images providing some properties for each image.

我写了一个python脚本与这些参数,是这样的:

I wrote a python script with those parameters, something like:

import bpy

pi = 3.14159265
fov = 50

scene = bpy.data.scenes["Scene"]

# Set render resolution
scene.render.resolution_x = 480
scene.render.resolution_y = 359

# Set camera fov in degrees
scene.camera.data.angle = fov*(pi/180.0)

# Set camera rotation in euler angles
scene.camera.rotation_mode = 'XYZ'
scene.camera.rotation_euler[0] = 0.0*(pi/180.0)
scene.camera.rotation_euler[1] = 0.0*(pi/180.0)
scene.camera.rotation_euler[2] = -30.0*(pi/180.0)

# Set camera translation
scene.camera.location.x = 0.0
scene.camera.location.y = 0.0
scene.camera.location.z = 80.0

于是我运行它像

blender -b marker_a4.blend --python "marker_a4.py" -o //out -F JPEG -x 1 -f 1 

然后例如,如果我尝试使用参数的Python脚本

Then for instance if I try to use arguments to the python script

...
import sys
...
fov = float(sys.argv[5])
...

和运行它:

blender -b marker_a4.blend --python "marker_a4.py" 80.0 -o //out -F JPEG -x 1 -f 1 

渲染一事无成,但我一开始得到这个消息。

The render gets done but i get this messages at start.

read blend: /home/roho/workspace/encuadro/renders/marker/model/marker_a4.blend
read blend: /home/roho/workspace/encuadro/renders/marker/model/80.0
Unable to open "/home/roho/workspace/encuadro/renders/marker/model/80.0": No such file or directory.
...

谁能告诉我什么造成的?我认为,搅拌机也分析,作为一个模型,但不明白为什么。后来我尝试更多的东西sofisticated的论点蟒蛇(argparse)解析,但它并没有在所有的工作。所以我想有可能是在这个级别奇怪的事情发生。

Can anybody tell me whats causing this? I think blender is also parsing that as a model but don't understand why. I later tried something more sofisticated for the argument parsing in python (argparse) but it did not work at all. So i'm thinking there might be something strange happening at this level.

谢谢!

推荐答案

我发现我一直在寻找的intially解决方案。

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

由于Junuxx说:你不能直接传递命令行参数在蟒蛇的这种情况下的......,但实际上,你可以将参数传递给蟒蛇但在另一种情况。

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.

于是方式做我想做的是渲染和直接保存里面的python脚本

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 ) 

该--python选项(或-P)必须在最后,你可以指定参数 - ,只是加载模型和运行脚本

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

感谢这个环节,我发现:
http://www.blender.org/forum/viewtopic ?.PHP T = 19102&安培;亮点=批渲染+

这篇关于用命令行参数的Blender Python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆