def storage_get_data(self, node_dict): # this check and function call is needed to allow loading node trees directly # from a .blend in order to export them via create_dict_of_tree if not self.node_dict or not self.node_dict.get(hash(self)): self.make_new_locals() storage = self.node_dict[hash(self)]['sockets'] ui_info = storage['snlite_ui'] node_dict['snlite_ui'] = [] print(ui_info) for _, info in enumerate(ui_info): mat_name = info['mat_name'] node_name = info['node_name'] bl_idname = info['bl_idname'] if bl_idname == 'ShaderNodeRGBCurve': data = get_rgb_curve(mat_name, node_name) print(data) data_json_str = json.dumps(data) node_dict['snlite_ui'].append(data_json_str) includes = storage['includes'] if includes: node_dict['includes'] = {} for k, v in includes.items(): node_dict['includes'][k] = v
def storage_get_data(self, node_dict): ui_info = self.node_dict[hash(self)]['sockets']['snlite_ui'] node_dict['snlite_ui'] = [] print(ui_info) for _, info in enumerate(ui_info): mat_name = info['mat_name'] node_name = info['node_name'] bl_idname = info['bl_idname'] if bl_idname == 'ShaderNodeRGBCurve': data = get_rgb_curve(mat_name, node_name) print(data) data_json_str = json.dumps(data) node_dict['snlite_ui'].append(data_json_str)
def load_from_json(self, node_data: dict, import_version: float): ''' Scripted Node will no longer create alternative versions of a file. If a scripted node wants to make a file called 'inverse.py' and the current .blend already contains such a file, then for simplicity the importer will not try to create 'inverse.001.py' and reference that. It will instead do nothing and assume the existing python file is functionally the same. If you have files that work differently but have the same name, stop. ''' params = node_data.get('params') if params: script_name = params.get('script_name') script_content = params.get('script_str') with self.sv_throttle_tree_update(): texts = bpy.data.texts if script_name and not (script_name in texts): new_text = texts.new(script_name) new_text.from_string(script_content) elif script_name and (script_name in texts): # This was added to fix existing texts with the same name but no / different content. if texts[script_name].as_string() == script_content: self.debug( "SN skipping text named `%s' - their content are the same", script_name) else: self.info( "SN text named `%s' already found in current, but content differs", script_name) new_text = texts.new(script_name) new_text.from_string(script_content) script_name = new_text.name self.info('SN text named replaced with %s', script_name) self.script_name = script_name self.script_str = script_content self.load() # this check and function call is needed to allow loading node trees directly # from a .blend in order to export them via create_dict_of_tree if not self.node_dict or not self.node_dict.get(hash(self)): self.make_new_locals() storage = self.node_dict[hash(self)]['sockets'] ui_info = storage['snlite_ui'] node_data['snlite_ui'] = [] print(ui_info) for _, info in enumerate(ui_info): mat_name = info['mat_name'] node_name = info['node_name'] bl_idname = info['bl_idname'] if bl_idname == 'ShaderNodeRGBCurve': data = get_rgb_curve(mat_name, node_name) print(data) data_json_str = json.dumps(data) node_data['snlite_ui'].append(data_json_str) includes = storage['includes'] if includes: node_data['includes'] = {} for k, v in includes.items(): node_data['includes'][k] = v