Hi all.
I’m currently working on an addon (very specialized) and I’ve set up some input fields in the Tool shelf (a set of folder locations), and default values are read from a config file. I’ve also created a button so that the user can change those folder locations in Blender and save them to the config file.
In my register function I have this:
config_file = open(config_filepath, 'r')
config_from_file = json.load(config_file)
(plus something to write a new file if it doesn’t exist)
Property definition:
bpy.types.Scene.fPath = bpy.props.StringProperty(name='', description = 'Some path', default=config_from_file['PathKeyName'])
I have another class deriving from Panel, and in its Draw function I have this input field (among other things):
row3 = layout.row()
col3 = row3.column(align = True)
col3.prop(context.scene, 'fPath')
And to save its value to the config file:
row4 = layout.row()
col4 = row4.column(align = True)
col4.operator('object.save_settings', icon = 'FILE_TICK')
I also have a SaveSettings class whose execute function includes this:
config_file = open(config_filepath, 'w')
new_config = { 'PathKeyName' : context.scene.fPath}
json.dump(new_config, config_file, indent=4, sort_keys=True)
config_file.close()
It mostly works. If I start Blender, the values are correctly read from the config file. If I change the values in the Tool shelf and click the Save button, they get written to the file. Let’s say I change the path from c:\PathOld to c:\PathNew
The problem is that if I start a new .blend file, the value still shows PathOld, even though PathNew is in the config file. If I restart Blender, it then does say PathNew. It would seem that the config file is only being read when the program starts. Does anyone know if I can modify the addon to make Blender re-read the config file without the user having to restart the program?