[英]Control blender from python script outside of blender
i have a GUI made in pyside that render a blender file.我有一个用 pyside 制作的 GUI,可以渲染一个搅拌机文件。 This GUI have a resolution options to control this before render scene.... i have this code in PyCharm, i need to run this code without open blender.
这个 GUI 在渲染场景之前有一个分辨率选项来控制它。我在 PyCharm 中有这个代码,我需要在没有打开搅拌器的情况下运行这个代码。
if resolutionWidth != 0:
bpy.context.scene.render.resolution_x = resolutionWidth
if resolutionHeight != 0:
bpy.context.scene.render.resolution_y = resolutionHeight
# Override Resolution Scale
#SCALE = batchRender_UI.resolution_scaleUI()
if SCALE != 0:
bpy.context.scene.render.resolution_percentage = SCALE
You can run a blender's python script without opening blender's GUI in background from command line.您可以运行搅拌机的 python 脚本,而无需从命令行在后台打开搅拌机的 GUI。 Go to directory where blender is installed, open terminal/cmd over there and type following command -
Go 到安装搅拌机的目录,在那里打开终端/cmd并输入以下命令 -
blender -b -P path/to/your/script.py
The flag -b tells blender to run in background.标志 -b 告诉搅拌机在后台运行。 -P tells to run a python script using blender's python.
-P 告诉使用搅拌机的 python 运行 python 脚本。 If you want to open blender's GUI and run py script then run the following code:
如果要打开搅拌机的 GUI 并运行 py 脚本,请运行以下代码:
blender -P path/to/your/script.py
While running as subprocess use the following code:作为子进程运行时,使用以下代码:
import subprocess
subprocess.run(['blender', '-b', '-P', 'path/to/your/script.py'])
In case you want more interactive control over Blender, you can build Blender as a python module .如果您想对 Blender 进行更多交互控制,您可以将 Blender 构建为 python 模块。
This is a build option to be able to import blender into python and access its modules.
这是一个构建选项,能够将搅拌机导入 python 并访问其模块。 [...] This is mainly limited to features which can be usable in background mode, so you cant for instance do OpenGL preview renders.
[...] 这主要限于可在后台模式下使用的功能,因此您不能例如执行 OpenGL 预览渲染。
Be aware that since Blender uses a copyleft license , depending on how you want to use and distribute your app, this may or may not be acceptable.请注意,由于 Blender 使用copyleft 许可证,这取决于您希望如何使用和分发您的应用程序,这可能会或可能不会被接受。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.