fix: load default config on initial load

This commit is contained in:
Ian Chua
2026-07-16 12:57:59 +08:00
parent a15dcdfb3f
commit b6f98d9592
13 changed files with 60 additions and 103 deletions
+7 -9
View File
@@ -7,12 +7,6 @@
# author = "OrcaSlicer"
# version = "0.01"
# type = "slicing-pipeline"
#
# [tool.orcaslicer.plugin.settings]
# thickness_mm = "0.3"
# point_distance_mm = "0.8"
# fuzz_holes = "1"
# skip_first_layer = "1"
# ///
"""Fuzzy Slices -- the fuzzy-skin effect applied at slice time.
@@ -44,6 +38,7 @@ Polygon.as_array()/set_points numpy path would be the faster route.
"""
import math
import random
import json
import orca
@@ -55,9 +50,9 @@ _DEFAULTS = {
}
def _params(ctx):
def _params(self):
try:
src = dict(ctx.params)
src = json.loads(self.get_config())
except (AttributeError, TypeError):
src = {}
out = {}
@@ -111,11 +106,14 @@ class FuzzySlices(orca.slicing.SlicingPipelineCapabilityBase):
def get_name(self):
return "Fuzzy Slices"
def get_default_config(self):
return _DEFAULTS
def execute(self, ctx):
if ctx.step != orca.slicing.Step.posSlice or ctx.object is None:
return orca.ExecutionResult.success()
p = _params(ctx)
p = _params(self)
if p["thickness_mm"] <= 0.0 or p["point_distance_mm"] <= 0.0:
return orca.ExecutionResult.success("Fuzzy Slices: zero thickness/point distance, nothing to do")
+14 -11
View File
@@ -7,9 +7,6 @@
# author = "OrcaSlicer"
# version = "0.01"
# type = "slicing-pipeline"
#
# [tool.orcaslicer.plugin.settings]
# stamp_text = "processed by the OrcaSlicer G-code Stamp plugin"
# ///
"""G-code Stamp -- the post-processing half of the slicing-pipeline plugin.
@@ -19,7 +16,7 @@ exported G-code file -- NOT from Print::process(). So unlike the geometry steps
(posSlice, posPerimeters, ...) there is no live slicing graph here: ctx.print and
ctx.object are None. Instead the context carries ctx.gcode_path (the working G-code
file on disk, edited IN PLACE), ctx.host ("File", "OctoPrint", ...) and
ctx.output_name (the final file name). ctx.params and ctx.config_value() still work.
ctx.output_name (the final file name). self.get_config() still works.
This sample inserts a single comment line near the top of the file. Because the same
capability class can also implement the geometry steps, one plugin can transform slices
@@ -30,21 +27,27 @@ separate working copy), and its output is not reflected in the G-code preview --
viewer maps the pre-post-process file.
"""
import orca
import json
_DEFAULT_STAMP = "processed by the OrcaSlicer G-code Stamp plugin"
_DEFAULTS = {
"stamp_text": "processed by the OrcaSlicer G-code Stamp plugin",
}
def _stamp_text(ctx):
def _stamp_text(self):
try:
text = dict(ctx.params).get("stamp_text", _DEFAULT_STAMP)
except (AttributeError, TypeError):
text = _DEFAULT_STAMP
return str(text).replace("\n", " ").strip() or _DEFAULT_STAMP
text = json.loads(self.get_config())["stamp_text"]
except (AttributeError, TypeError, ValueError, KeyError):
text = _DEFAULTS["stamp_text"]
return str(text).replace("\n", " ").strip() or _DEFAULTS["stamp_text"]
class GCodeStamp(orca.slicing.SlicingPipelineCapabilityBase):
def get_name(self):
return "G-code Stamp"
def get_default_config(self):
return _DEFAULTS
def execute(self, ctx):
# Only act at the post-process seam; at every geometry step this is a no-op.
@@ -53,7 +56,7 @@ class GCodeStamp(orca.slicing.SlicingPipelineCapabilityBase):
if not ctx.gcode_path:
return orca.ExecutionResult.success("G-code Stamp: no gcode_path, nothing to do")
comment = "; " + _stamp_text(ctx) + " (host=" + (ctx.host or "?") + ")\n"
comment = "; " + _stamp_text(self) + " (host=" + (ctx.host or "?") + ")\n"
# Edit the exported G-code in place: keep the original first line first (some flavors
# expect a specific leading line), then insert the stamp right after it.
+20 -2
View File
@@ -25,21 +25,39 @@ A surface may split into several islands or vanish when shrunk; both are handled
No numpy required: the whole edit is expressed with the host geometry classes.
"""
import json
import orca
INSET_MM = 1.0
_DEFAULTS = {
"inset_mm": 1.0, # inward offset applied to every slice
}
def _inset_mm(self):
try:
return float(json.loads(self.get_config())["inset_mm"])
except (AttributeError, TypeError, ValueError, KeyError):
return _DEFAULTS["inset_mm"]
class InsetEverySlice(orca.slicing.SlicingPipelineCapabilityBase):
def get_name(self):
return "Inset Every Slice"
def get_default_config(self):
return _DEFAULTS
def execute(self, ctx):
if ctx.step != orca.slicing.Step.posSlice or ctx.object is None:
return orca.ExecutionResult.success()
inset_mm = _inset_mm(self)
if inset_mm <= 0.0:
return orca.ExecutionResult.success("Inset: zero inset, nothing to do")
# Millimeters -> scaled integer units via the *live* scale (never hardcode 1e6).
inset_scaled = int(round(INSET_MM / orca.slicing.unscale(1)))
inset_scaled = int(round(inset_mm / orca.slicing.unscale(1)))
regions_touched = 0
for layer in ctx.object.layers():
+7 -11
View File
@@ -7,13 +7,6 @@
# author = "OrcaSlicer"
# version = "0.02"
# type = "slicing-pipeline"
#
# [tool.orcaslicer.plugin.settings]
# twist_deg_per_mm = "1.0"
# taper_per_mm = "0.0"
# wobble_ampl_mm = "0.0"
# wobble_period_mm = "20.0"
# min_scale = "0.05"
# ///
"""Twistify -- twist/taper/wobble any model at slice time.
@@ -36,7 +29,7 @@ settings table above). The first object layer is untouched (z_rel = 0), so bed
adhesion is unaffected.
"""
import math
import json
import orca
_DEFAULTS = {
@@ -48,9 +41,9 @@ _DEFAULTS = {
}
def _params(ctx):
def _params(self):
try:
src = dict(ctx.params)
src = json.loads(self.get_config())
except (AttributeError, TypeError):
src = {}
out = {}
@@ -79,12 +72,15 @@ def _layer_params(z_rel, mm_to_scaled, p):
class Twistify(orca.slicing.SlicingPipelineCapabilityBase):
def get_name(self):
return "Twistify"
def get_default_config(self):
return _DEFAULTS
def execute(self, ctx):
if ctx.step != orca.slicing.Step.posSlice or ctx.object is None:
return orca.ExecutionResult.success()
p = _params(ctx)
p = _params(self)
if _is_identity(p):
return orca.ExecutionResult.success("Twistify: identity parameters, nothing to do")