0

I'm trying to store render settings and other settings in a txt-file. Sadly I was not able to find a proper solution on google.

Is there an accurate way get the settings, store them in a file and put them back in an other file?

Example, store this:

bpy.context.scene.render.engine = 'BLENDER_EEVEE'

bpy.context.scene.eevee.taa_render_samples = 45

bpy.context.scene.eevee.use_motion_blur = False

And get it back in another file.

Duarte Farrajota Ramos
  • 59,425
  • 39
  • 130
  • 187
Andi
  • 741
  • 3
  • 11
  • https://gifguide2code.com/2016/10/08/python-how-to-put-blender-data-into-a-text-file/

    https://blenderartists.org/t/bpy-ops-text-open-use-and-access-data-of-the-read-text-file/512901

    https://blender.stackexchange.com/questions/34018/python-script-that-reads-text-file-containing-coordinates-and-creates-a-path-cur

    – fmotion1 Oct 21 '20 at 09:10
  • 1
    https://blender.stackexchange.com/a/134620/15543 – batFINGER Oct 21 '20 at 09:14
  • I've seen that before, but it's not what I'm looking for. As you can see in the Example, it's not just about storing numbers. The second question is, how can I ask blender for the whole lines of code above. If there is a way for that, I can maybe store the code-lines as strings and then work with that somehow. – Andi Oct 21 '20 at 09:20
  • There is nothing about a txt-file, storing informations and getting them back in another blend-file out of the txt-file. – Andi Oct 21 '20 at 09:53
  • 1
    Is this regarding my comment re the presets system? https://docs.blender.org/api/current/bpy.types.Menu.html#preset-menus which is used to both create a text file of selected properties and read and set from it. Pertaining to the example link would change obj = bpy.context.object to scene = bpy.context.scene and work from there. Could you please edit code markdown into question. – batFINGER Oct 21 '20 at 11:15
  • Related and Possible duplicate https://blender.stackexchange.com/questions/74979/how-to-create-a-preset – batFINGER Oct 21 '20 at 11:23
  • Well... I'm working on my first addon - that's maybe why I'm confused. The link you shared https://blender.stackexchange.com/questions/134613/can-python-operator-presets-be-shared-between-operators/134620#134620 is exactly what I'm looking for. But I cant see, where the txt. file gets written to a directory. I know commands like "with open(file_to_open,'w') as file" or similar, but there is nothing like thtat. Which commands exactly store the preset_values? Sorry for that beginner-question... – Andi Oct 30 '20 at 10:55
  • Ping: @batFINGER – unwave Nov 01 '20 at 07:08
  • 1
    Run bpy.utils.script_paths("presets") in console. Shows the root of the presets path. The I/O is done for us. – batFINGER Nov 01 '20 at 07:38

1 Answers1

4

To set settings:

import bpy
import json

my_txt = ''' { "render": { "engine": "BLENDER_EEVEE" }, "eevee": { "taa_render_samples": 45, "use_motion_blur": false } } '''

render_settings = json.loads(my_txt)

for section in render_settings.keys(): for name, value in render_settings[section].items(): setattr(getattr(bpy.context.scene, section), name, value)

To get primitive settings:

import bpy
import inspect

primitive_types = {int, str, float, bool}

section = bpy.context.scene.render

def is_valid(i): if i[0].startswith('_'): return False if not type(i[1]) in primitive_types: return False if section.is_property_readonly(i[0]): return False return True

settings = inspect.getmembers(section, lambda i: not(inspect.isroutine(i))) settings = dict([i for i in settings if is_valid(i)])

for name, value in settings.items(): print(name, value)

unwave
  • 1,643
  • 5
  • 14
  • That looks great. I guess I need to learn a lot about json - without that knowledge, I'm not realy able to understand the script. Thank you both for the help! – Andi Oct 21 '20 at 12:00