3
$\begingroup$

I know that I can change render settings with e.g. C.scene.render.resolution_x, but I have the values I want stored in one of these:

enter image description here

I don't know what they're called, I'd call them something like "custom property presets" but it seems like those words have different meanings in the Python API.

I know they're not in the .blend file themselves, so I assume there's some way to read them from the API that handles system-wide preferences. I'm looking to be able to do something like:

C.scene.render.resolution_x = C.preferences.output.format.presets['HDTV 1080p'].resolution_x
$\endgroup$

1 Answer 1

4
$\begingroup$

TL;DNR: You cant use them that way. But look at blender/presets.py to see how you could use them.

Using Blender's presets in Python is a tutorial that goes into details on how you can use presets for your own add-ons.

You are correct that the presets are separate from the Blend file. Each preset is stored with the add-on in its own python file. In the case of the UI, the presets are stored with the UI code, in the directory where you installed blender in the scripts/startup/scripts/presets directory. The specific presets you are looking for are in the render subdirectory. Here's an example, taken from HDTV_1080p.py:

bpy.context.scene.render.resolution_x = 1920
bpy.context.scene.render.resolution_y = 1080
bpy.context.scene.render.resolution_percentage = 100
bpy.context.scene.render.pixel_aspect_x = 1
bpy.context.scene.render.pixel_aspect_y = 1
bpy.context.scene.render.fps = 24
bpy.context.scene.render.fps_base = 1

As you can see, the preset file is a collection of assignment statements.

To access a preset, you would need to read in and execute the python file of the same name. The code from the Blender UI that does this can be found here.

$\endgroup$
1
  • $\begingroup$ Oh well this works too! Since the presets are just a Python script I should be able to run them with --python on the command line. Thanks for the pointer! $\endgroup$ Commented Mar 6, 2022 at 1:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .