Bug Report: Custom "After Layer Change G-code" Inserted Before Z Move Instead of After #1936

Open
opened 2026-04-05 21:27:47 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @gmakedonski on 10/11/2025

Is there an existing issue for this problem?

  • I have searched the existing issues

OrcaSlicer Version

2.3.1

Operating System (OS)

macOS

OS Version

macOS 14.5

Additional system information

In Orca Slicer, the custom G-code specified in the "After layer change G-code" field (under Printer Settings > Custom G-code) is being inserted before the Z-axis movement that raises the print head to the new layer height. This contradicts the expected behavior, where "after layer change" should place the custom code after the actual layer change has occurred—i.e., after the Z move, when the printer is at the new layer height and ready to start extruding the next layer.
The layer change is typically marked by the Z move (e.g., G1 ... Z30 F6000), as this is the point where the printer physically transitions to the new layer. However, the generated G-code places the custom "after" code before this Z move, effectively running it while still at the previous layer's height. This can cause issues with commands that rely on being at the correct height, such as extrusions, pauses, or other height-dependent operations.
This behavior persists even when the custom code is explicitly set to run after the layer change.

Printer

Custom Large concrete driven by Duet3D

How to reproduce

Open Orca Slicer and create or load a printer profile.
In Printer Settings > Custom G-code (enable Expert mode if needed):
Set "After layer change G-code" to something like:
G4 S20
G1 E15
Slice a multi-layer model (e.g., a simple cube with height > one layer).
Export the G-code and inspect the output around a layer change

Actual results

G1 X422.435 Y641.909 E3.11711
G1 X425.997 Y637.738 E3.11709
G1 X428.647 Y635.475 E1.98046
;LAYER_CHANGE
;Z:30
;HEIGHT:15
;BEFORE_LAYER_CHANGE
;30
M42 P1 S1
G4 S3
M42 P1 S0
G92 E0

;AFTER_LAYER_CHANGE
;30
G1 E15
G4 S20
;_SET_FAN_SPEED_CHANGING_LAYER
G1 X430.168 Y634.176 Z30 F6000
G1 F3000
G1 X434.844 Y631.31 E3.11716
G1 X439.912 Y629.211 E3.11705
G1 X445.245 Y627.931 E3.1171
G1 X451.302 Y627.454 E3.45308
G1 X850.124 Y627.454 E226.65417

Expected results

The custom "After layer change G-code" should appear after the Z move command, like this:
M42 P1 S0
G92 E0

;_SET_FAN_SPEED_CHANGING_LAYER

G1 X430.168 Y634.176 Z30 F6000
;AFTER_LAYER_CHANGE
;30
G1 E15
G4 S20

G1 F3000
G1 X434.844 Y631.31 E3.11716
G1 X439.912 Y629.211 E3.11705
G1 X445.245 Y627.931 E3.1171

Project file & Debug log uploads

SAKSIA_50x50x60.3mf.zip

Checklist of files to include

  • Log file
  • Project file

Anything else?

Possible Fix
Adjust the G-code generation logic to insert the ;AFTER_LAYER_CHANGE comment and associated custom code after the Z move command in the output file.

*Originally created by @gmakedonski on 10/11/2025* ### Is there an existing issue for this problem? - [x] I have searched the existing issues ### OrcaSlicer Version 2.3.1 ### Operating System (OS) macOS ### OS Version macOS 14.5 ### Additional system information In Orca Slicer, the custom G-code specified in the "After layer change G-code" field (under Printer Settings > Custom G-code) is being inserted before the Z-axis movement that raises the print head to the new layer height. This contradicts the expected behavior, where "after layer change" should place the custom code after the actual layer change has occurred—i.e., after the Z move, when the printer is at the new layer height and ready to start extruding the next layer. The layer change is typically marked by the Z move (e.g., G1 ... Z30 F6000), as this is the point where the printer physically transitions to the new layer. However, the generated G-code places the custom "after" code before this Z move, effectively running it while still at the previous layer's height. This can cause issues with commands that rely on being at the correct height, such as extrusions, pauses, or other height-dependent operations. This behavior persists even when the custom code is explicitly set to run after the layer change. ### Printer Custom Large concrete driven by Duet3D ### How to reproduce Open Orca Slicer and create or load a printer profile. In Printer Settings > Custom G-code (enable Expert mode if needed): Set "After layer change G-code" to something like: G4 S20 G1 E15 Slice a multi-layer model (e.g., a simple cube with height > one layer). Export the G-code and inspect the output around a layer change ### Actual results G1 X422.435 Y641.909 E3.11711 G1 X425.997 Y637.738 E3.11709 G1 X428.647 Y635.475 E1.98046 ;LAYER_CHANGE ;Z:30 ;HEIGHT:15 ;BEFORE_LAYER_CHANGE ;30 M42 P1 S1 G4 S3 M42 P1 S0 G92 E0 ;AFTER_LAYER_CHANGE ;30 G1 E15 G4 S20 ;_SET_FAN_SPEED_CHANGING_LAYER G1 X430.168 Y634.176 Z30 F6000 G1 F3000 G1 X434.844 Y631.31 E3.11716 G1 X439.912 Y629.211 E3.11705 G1 X445.245 Y627.931 E3.1171 G1 X451.302 Y627.454 E3.45308 G1 X850.124 Y627.454 E226.65417 ### Expected results The custom "After layer change G-code" should appear after the Z move command, like this: M42 P1 S0 G92 E0 ;_SET_FAN_SPEED_CHANGING_LAYER G1 X430.168 Y634.176 Z30 F6000 ;AFTER_LAYER_CHANGE ;30 G1 E15 G4 S20 G1 F3000 G1 X434.844 Y631.31 E3.11716 G1 X439.912 Y629.211 E3.11705 G1 X445.245 Y627.931 E3.1171 ### Project file & Debug log uploads [SAKSIA_50x50x60.3mf.zip](https://github.com/user-attachments/files/22867147/SAKSIA_50x50x60.3mf.zip) ### Checklist of files to include - [ ] Log file - [x] Project file ### Anything else? Possible Fix Adjust the G-code generation logic to insert the ;AFTER_LAYER_CHANGE comment and associated custom code after the Z move command in the output file.
MrUnknownDE added the bugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbugbug labels 2026-04-05 21:29:04 +02:00
Sign in to join this conversation.
No Label bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug bug
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/OrcaSlicer#1936