This commit is contained in:
Nicolas Predella 2026-05-21 19:28:59 +03:00
parent c9dbf0eb1d
commit a476d9fb33
2 changed files with 11 additions and 9 deletions

View file

@ -98,12 +98,12 @@ class SLICENODE_PrusaslicerConf(SliceNode):
if os.path.isdir(profiles_path): if os.path.isdir(profiles_path):
cache.load([profiles_path]) cache.load([profiles_path])
if self.printer_id != 'NONE': if self.printer_id != '':
cache.evaluate_compatibility({self.printer_id}, set(cache.vendors)) cache.evaluate_compatibility({self.printer_id}, set(cache.vendors))
def update_profiles(self, context): def update_profiles(self, context):
cache = self.get_cache() cache = self.get_cache()
if self.printer_id != 'NONE': if self.printer_id != '':
cache.evaluate_compatibility({self.printer_id}, set(cache.vendors)) cache.evaluate_compatibility({self.printer_id}, set(cache.vendors))
notify_tree_changed(self, context) notify_tree_changed(self, context)
@ -112,6 +112,7 @@ class SLICENODE_PrusaslicerConf(SliceNode):
self.ensure_profiles_loaded() self.ensure_profiles_loaded()
cache: LocalCache = self.get_cache() cache: LocalCache = self.get_cache()
items: list[str] = [p.id for k, p in cache.printer_profiles.items() if edit_text.lower() in p.id.lower()] items: list[str] = [p.id for k, p in cache.printer_profiles.items() if edit_text.lower() in p.id.lower()]
items.sort()
return items return items
def search_conf(self, edit_text: str, conf_type: str) -> list[str]: def search_conf(self, edit_text: str, conf_type: str) -> list[str]:
@ -124,6 +125,7 @@ class SLICENODE_PrusaslicerConf(SliceNode):
profiles: list[Profile] = printer.compatible_filament_profiles if conf_type == "filaments" else printer.compatible_print_profiles profiles: list[Profile] = printer.compatible_filament_profiles if conf_type == "filaments" else printer.compatible_print_profiles
items: list[str] = [p.id for p in profiles if edit_text.lower() in p.id.lower()] items: list[str] = [p.id for p in profiles if edit_text.lower() in p.id.lower()]
items.sort()
return items return items
def search_filaments(self, _context, edit_text) -> list[str]: def search_filaments(self, _context, edit_text) -> list[str]:
@ -132,9 +134,9 @@ class SLICENODE_PrusaslicerConf(SliceNode):
def search_prints(self, _context, edit_text) -> list[str]: def search_prints(self, _context, edit_text) -> list[str]:
return self.search_conf(edit_text, conf_type="prints") return self.search_conf(edit_text, conf_type="prints")
printer_id: NfStringProperty(name="Printer", default='NONE', update=update_profiles, search=search_printers) # pyright: ignore[reportInvalidTypeForm] printer_id: NfStringProperty(name="Printer", default='', update=update_profiles, search=search_printers) # pyright: ignore[reportInvalidTypeForm]
filament_id: NfStringProperty(name="Filament", default='NONE', search=search_filaments) # pyright: ignore[reportInvalidTypeForm] filament_id: NfStringProperty(name="Filament", default='', search=search_filaments) # pyright: ignore[reportInvalidTypeForm]
print_id: NfStringProperty(name="Print", default='NONE', search=search_prints) # pyright: ignore[reportInvalidTypeForm] print_id: NfStringProperty(name="Print", default='', search=search_prints) # pyright: ignore[reportInvalidTypeForm]
def init(self, context): def init(self, context):
self.add_output("SLICESOCK_PrusaslicerConf", "Config") self.add_output("SLICESOCK_PrusaslicerConf", "Config")
@ -143,13 +145,13 @@ class SLICENODE_PrusaslicerConf(SliceNode):
assert layout assert layout
self.ensure_profiles_loaded() self.ensure_profiles_loaded()
layout.prop(self, "printer_id") layout.prop(self, "printer_id")
if self.printer_id != 'NONE': if self.printer_id != '':
layout.prop(self, "filament_id") layout.prop(self, "filament_id")
layout.prop(self, "print_id") layout.prop(self, "print_id")
def evaluate_output(self, socket_name: str, **_kwargs) -> Any: def evaluate_output(self, socket_name: str, **_kwargs) -> Any:
self.ensure_profiles_loaded() self.ensure_profiles_loaded()
if self.printer_id == 'NONE' or self.filament_id == 'NONE' or self.print_id == 'NONE': if self.printer_id == '' or self.filament_id == '' or self.print_id == '':
return None return None
cache = self.get_cache() cache = self.get_cache()
@ -1382,7 +1384,7 @@ class SLICENODE_PrusaslicerSlice(SliceNode):
overrides=writer_overrides overrides=writer_overrides
) )
binary_gcode_value = conf_writer.config_dict['binary_gcode'] binary_gcode_value = conf_writer.config_dict.get('binary_gcode', '0')
conf_writer.config_dict['binary_gcode'] = '0' conf_writer.config_dict['binary_gcode'] = '0'
# Prepare 3mf path # Prepare 3mf path

View file

@ -42,7 +42,7 @@ def get_gcode_name_from_metadata(gcode: str, default: str = "output") -> str:
if parts_match: if parts_match:
try: try:
gcode_info = json.loads(parts_match.group(1)) gcode_info = json.loads(parts_match.group(1))
names: list[str] = [str(v['name'].split(".")[0]) for v in gcode_info['objects']] names: list[str] = [str(v['name'].split(" id:")[0]) for v in gcode_info['objects']]
counts = Counter(names) counts = Counter(names)
return "-".join(f"{c}x{n}" if c > 1 else n for n, c in counts.items()) return "-".join(f"{c}x{n}" if c > 1 else n for n, c in counts.items())
except: except: