feat: Add hidden layer support and improve positioning stability

- Hidden layers are now automatically skipped during G-code generation
- Layers with display:none, sodipodi:insensitive, or hidden via eye icon are excluded
- Added is_layer_hidden() method to check layer visibility
- Updated README.md with hidden layer notice and settling delay parameter
- Improved positioning by maintaining settling delay feature

This allows users to keep reference/construction layers in their files without
affecting the generated G-code output.
This commit is contained in:
devdesk
2025-12-08 21:13:15 +02:00
parent f42d9a35dd
commit e47714c8a3
2 changed files with 32 additions and 2 deletions

View File

@@ -22,6 +22,8 @@ Restart Inkscape and you're done. if you are just changing the `.py` you dont ha
![XY Plotter tool panel](img/GcodePanelByLOD.jpeg)
**Note:** Hidden layers (eye icon disabled in Inkscape) are automatically skipped during G-code generation.
| Name | Definition | Default | Gcode Result |
|---|---| --- | --- |
| **Drawing On Command** | Gcode commande to lower down the Z-axis | `M3` | `M3 S1000` |
@@ -29,8 +31,9 @@ Restart Inkscape and you're done. if you are just changing the `.py` you dont ha
| **Pen Up Travel speed** | Travel speed with Pen Up | `3000` | `G1 F3000` |
| **Pen Down Travel speed** | Travel speed when drawing | `1500` | `G1 F1500` |
| **Pen Active Power** | command value to lower the pen | `1000` | `M3 S1000` |
| **Pen On Delay** | Delay after moving and before drawing | `0,1` | `G4 P0.1` |
| **Pen Off Delay** | Delay after drawing and before moving | `0,2` | `G4 P0.2` |
| **Settling Delay** | Delay after movement to allow mechanical settling | `0.15` | `G4 P0.15` |
| **Pen On Delay** | Delay after pen-down before drawing | `0.2` | `G4 P0.2` |
| **Pen Off Delay** | Delay after drawing before pen-up | `0.2` | `G4 P0.2` |
| **X Offset** | X-axis offset for plotter start position | `180` | All X coordinates shifted by offset value |
| **Y Offset** | Y-axis offset for plotter start position | `0` | All Y coordinates shifted by offset value |
| **Passes** | Number of Passes | | |

View File

@@ -1137,6 +1137,7 @@ class LaserGcode(inkex.Effect):
self.paths = {}
self.orientation_points = {}
self.layers = [self.document.getroot()]
self.hidden_layers = set()
self.Zcoordinates = {}
self.transform_matrix = {}
self.transform_matrix_reverse = {}
@@ -1150,6 +1151,10 @@ class LaserGcode(inkex.Effect):
self.selected_hack[i.get("id")] = i
if i.tag == inkex.addNS("g", 'svg') and i.get(inkex.addNS('groupmode', 'inkscape')) == 'layer':
self.layers += [i]
# Check if layer is hidden
if self.is_layer_hidden(i):
self.hidden_layers.add(i)
print_("Skipping hidden layer: '%s'" % i.get(inkex.addNS('label', 'inkscape')))
recursive_search(i, i)
elif i.get('gcodetools') == "Gcodetools orientation group":
points = self.get_orientation_points(i)
@@ -1178,6 +1183,23 @@ class LaserGcode(inkex.Effect):
recursive_search(self.document.getroot(), self.document.getroot())
def is_layer_hidden(self, layer):
"""Check if a layer is hidden based on Inkscape visibility settings"""
# Check style attribute for display:none
style = layer.get('style', '')
if 'display:none' in style.replace(' ', ''):
return True
# Check sodipodi:insensitive attribute (layer locked/hidden)
if layer.get(inkex.addNS('insensitive', 'sodipodi')) == 'true':
return True
# Check inkscape:groupmode and style combination
if layer.get('display') == 'none':
return True
return False
def get_orientation_points(self, g):
items = g.getchildren()
items.reverse()
@@ -1341,6 +1363,11 @@ class LaserGcode(inkex.Effect):
print_(("self.layers=", self.layers))
print_(("paths=", paths))
for layer in self.layers:
# Skip hidden layers
if layer in self.hidden_layers:
print_("Skipping hidden layer in gcode generation: '%s'" % layer.get(inkex.addNS('label', 'inkscape')))
continue
if layer in paths:
print_(("layer", layer))
p = []