def execute(self, context): mod_name = context.scene.custom_tree_load_params_input # Delete old module if it exists, forcing Python to load the new file if mod_name in sys.modules: del sys.modules[mod_name] importlib.invalidate_caches( ) # Make sure Python doesn't import from __pycache__ mod = importlib.import_module(mod_name) params = tree_param.TreeParam(mod.params).params scene = context.scene for name, value in params.items(): if name in ['leaf_shape', 'shape', 'blossom_shape']: if value == 0 and name == 'leaf_shape': value = 8 # default value = str(value) try: setattr(scene, 'tree_{}_input'.format(name), value) except TypeError as ex: exception = str(ex).replace( 'TypeError: bpy_struct: item.attr = val: ', '') print('TreeGen :: Error while loading preset "{}": {}'.format( name, exception)) # Pre-fill render output path with relevant name scene.render_output_path_input = os.path.sep.join( (_get_addon_path_details()[2], 'parametric', 'tree_params', mod_name.split('.')[-1].replace('.py', '') + '_render.png')) return {'FINISHED'}
def execute(self, context): mod_name = context.scene.custom_tree_load_params_input mod = __import__(mod_name, fromlist=['']) params = tree_param.TreeParam(mod.params).params scene = context.scene for name, value in params.items(): if name in ['leaf_shape', 'shape', 'blossom_shape']: if value == 0 and name == 'leaf_shape': value = 8 # default value = str(value) try: setattr(scene, 'tree_{}_input'.format(name), value) except TypeError as ex: exception = str(ex).replace('TypeError: bpy_struct: item.attr = val: ', '') print('TreeGen :: Error while loading preset "{}": {}'.format(name, exception)) return {'FINISHED'}