5

i have a GUI made in pyside that render a blender file. 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.

enter image description here

    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

2 Answers 2

5

You can run a blender's python script without opening blender's GUI in background from command line. Go to directory where blender is installed, open terminal/cmd over there and type following command -

blender -b -P path/to/your/script.py

The flag -b tells blender to run in background. -P tells to run a python script using blender's python. If you want to open blender's GUI and run py script then run the following code:

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'])
Sign up to request clarification or add additional context in comments.

2 Comments

This worked perfectly for me: blender -P path/to/your/script.py. How can I add arguments to my python script?
Try blender -P path/to/your/script.py -- arg0 arg1 arg2
0

In case you want more interactive control over Blender, you can build Blender as a python module.

This is a build option to be able to import blender into python and access its modules. [...] This is mainly limited to features which can be usable in background mode, so you cant for instance do OpenGL preview renders.

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.