diff --git a/core/nodeslicer/nodes.py b/core/nodeslicer/nodes.py index 653c5c7..0ab1642 100644 --- a/core/nodeslicer/nodes.py +++ b/core/nodeslicer/nodes.py @@ -82,19 +82,28 @@ class SLICENODE_PrusaslicerConf(SliceNode): cls._cache = LocalCache() return cls._cache + def ensure_profiles_loaded(self): + cache = self.get_cache() + if not cache.profiles: + # Use a path relative to the addon directory + import os + addon_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + profiles_path = os.path.join(addon_dir, "profiles", "prusaslicer") + if os.path.isdir(profiles_path): + cache.load([profiles_path]) + + if self.printer_id != 'NONE': + cache.evaluate_compatibility({self.printer_id}, set(cache.vendors)) + def update_profiles(self, context): cache = self.get_cache() - if not cache.profiles and self.config_path: - abs_path = bpy.path.abspath(self.config_path) - if os.path.isdir(abs_path): - cache.load([abs_path]) - if self.printer_id != 'NONE': cache.evaluate_compatibility({self.printer_id}, set(cache.vendors)) notify_tree_changed(self, context) def get_printers(self, context): + self.ensure_profiles_loaded() cache = self.get_cache() items = [('NONE', "None", "No printer selected", 'NONE', 0)] for i, (k, p) in enumerate(cache.printer_profiles.items(), 1): @@ -102,6 +111,7 @@ class SLICENODE_PrusaslicerConf(SliceNode): return items def get_filaments(self, context): + self.ensure_profiles_loaded() cache = self.get_cache() items = [('NONE', "None", "No filament selected", 'NONE', 0)] @@ -122,6 +132,7 @@ class SLICENODE_PrusaslicerConf(SliceNode): return items def get_prints(self, context): + self.ensure_profiles_loaded() cache = self.get_cache() items = [('NONE', "None", "No print selected", 'NONE', 0)] @@ -166,12 +177,6 @@ class SLICENODE_PrusaslicerConf(SliceNode): def get_print_enum(self): return self._get_enum_idx(self.get_prints(None), self.print_id) def set_print_enum(self, value): self._set_enum_idx(self.get_prints(None), value, 'print_id') - config_path: NfStringProperty( - name="Profiles", - subtype='DIR_PATH', - update=update_profiles - ) # pyright: ignore[reportInvalidTypeForm] - printer_enum: NfEnumProperty( name="Printer", items=get_printers, @@ -198,13 +203,14 @@ class SLICENODE_PrusaslicerConf(SliceNode): def draw_buttons(self, context, layout): assert layout - layout.prop(self, "config_path") + self.ensure_profiles_loaded() layout.prop(self, "printer_enum") if self.printer_id != 'NONE': layout.prop(self, "filament_enum") layout.prop(self, "print_enum") def evaluate_output(self, socket_name: str, **_kwargs) -> Any: + self.ensure_profiles_loaded() if self.printer_id == 'NONE' or self.filament_id == 'NONE' or self.print_id == 'NONE': return None @@ -910,10 +916,10 @@ class SLICENODE_PrinterList(SliceNode): def _refresh(self): import json - if not self.config_path: + if not self.printers_json_path: return - abs_path = bpy.path.abspath(self.config_path) + abs_path = bpy.path.abspath(self.printers_json_path) if not os.path.exists(abs_path): return @@ -950,13 +956,13 @@ class SLICENODE_PrinterList(SliceNode): def update_config(self, context): self._refresh() - config_path: NfStringProperty(name="Config File", default="", subtype='FILE_PATH', update=update_config) # pyright: ignore[reportInvalidTypeForm] + printers_json_path: NfStringProperty(name="Config File", default="", subtype='FILE_PATH', update=update_config) # pyright: ignore[reportInvalidTypeForm] def init(self, context): pass def draw_buttons(self, context, layout): - layout.prop(self, "config_path") # pyright: ignore[reportOptionalMemberAccess] + layout.prop(self, "printers_json_path") # pyright: ignore[reportOptionalMemberAccess] def evaluate_output(self, socket_name: str, **_kwargs) -> Any: self._refresh() diff --git a/core/nodeslicer/tree.py b/core/nodeslicer/tree.py index 86f883c..7afe305 100644 --- a/core/nodeslicer/tree.py +++ b/core/nodeslicer/tree.py @@ -41,11 +41,8 @@ def get_referenced_objects(node, visited=None): _is_updating = False _tree_changed = False -@persistent -def depsgraph_update_handler(scene, depsgraph): - global _is_updating, _tree_changed - if _is_updating: - return +def tree_update_handler(scene, depsgraph): + global _tree_changed # Names of objects that have changed updated_object_names = {update.id.name for update in depsgraph.updates if isinstance(update.id, bpy.types.Object)} @@ -92,6 +89,14 @@ def depsgraph_update_handler(scene, depsgraph): finally: _is_updating = False +@persistent +def depsgraph_update_handler(scene, depsgraph): + global _is_updating, _tree_changed + if _is_updating: return + + tree_update_handler(scene, depsgraph) + + @register_class class SLICETREE_NodeTree(NodeTree): bl_idname = "SLICETREE_NodeTree" diff --git a/tests/2.4.5.ini b/profiles/prusaslicer/2.4.5.ini similarity index 100% rename from tests/2.4.5.ini rename to profiles/prusaslicer/2.4.5.ini diff --git a/profiles/prusaslicer/Link to Configs b/profiles/prusaslicer/Link to Configs new file mode 120000 index 0000000..ed2b4cb --- /dev/null +++ b/profiles/prusaslicer/Link to Configs @@ -0,0 +1 @@ +/home/nicolas/Workspace/Design Projects/3d Print Library/Configs \ No newline at end of file