Skip to content

Create ZHopOnTravel.py #20489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

GregValiant
Copy link
Collaborator

@GregValiant GregValiant commented Apr 6, 2025

I've always found Z-hops as a necessary evil, but rarely for an entire file.
This script allows the user to customize Z-hops in the Gcode for either particular layers, or a range of layers. The user can add hops to get over feather edges that might curl up, or infill that the nozzle might strike.

The main options are:

  • 'Layer List' which is a comma delimited list of individual layers ( Ex: "12,45,127")
  • 'Range of Layers' which would be a contiguous range of layers (Ex: Start at the beginning of layer 12 and continue to the end of layer 127) .

Other options are as you see here:
image

The script is compatible with:

  • Absolute and Relative Extrusion
  • Firmware Retraction
  • Extra Prime Amount >= 0
  • Adaptive Layers
  • G2/G3 arc moves are supported but are treated as straight line moves.

Cura travel settings:

  • If Z-hops are enabled in Cura there will sometimes be second higher hop. The "return to" height will be correct.
  • Compatible if retractions are enabled or not.

The setting "Add Z-hops to Infill Only" is limited as the script can only tell when the nozzle is printing infill. If the nozzle is traveling from a "Wall over there" to a "Wall over here" and crosses infill during the travel there would not be a Z-hop added.

The script is NOT compatible with:

  • Print Sequence = "One at a Time"

Example gcode for an added retraction and Z-hop (Extra prime amt = 0.5mm³ and absolute extrusion, z-hop = 0.50)

G1 X163.72 Y109.548 E558.95488
G1 F2100 E551.95488                     ; Retract
G0 F600 Z3.25                           ; Hop Up
G0 F10500 X88.4 Y115
G0 X88 Y115
G0 F600 Z2.75                           ; Hop Down
G92 E551.73969                          ; Extra prime adjustment
G1 F2100 E558.95488                     ; UnRetract
G1 F4500 X87.6 Y115 E558.9721

I don't know how many people use Cura for pellet feeders, but they can't retract and so this could be used to add Z-hops when required.

Type of change

  • [ X] New feature (non-breaking change which adds functionality)

Test Configuration:
Various versions of Cura

  • Operating System:
    Windows 10 Pro

Checklist:

  • [ X] My code follows the style guidelines of this project as described in UltiMaker Meta and Cura QML best practices
  • [ X] I have read the Contribution guide
  • [ X] I have commented my code, particularly in hard-to-understand areas
  • [ X] I have uploaded any files required to test this change

New script to customize Z-hops in a gcode file.
@github-actions github-actions bot added the PR: Community Contribution 👑 Community Contribution PR's label Apr 6, 2025
@GregValiant GregValiant requested a review from HellAholic April 6, 2025 15:25
Copy link
Contributor

github-actions bot commented Apr 6, 2025

Test Results

23 928 tests   23 926 ✅  47s ⏱️
     1 suites       2 💤
     1 files         0 ❌

Results for commit 64a1512.

♻️ This comment has been updated with latest results.

@GregValiant GregValiant requested a review from wawanbreton April 6, 2025 17:42
@wawanbreton
Copy link
Contributor

This is a good idea, we actually have some internal discussions to customize the z-hop depending on layer type (e.g. not on top layers), so in the meantime this provides a good solution.
For internal reference: CURA-12523

@GregValiant
Copy link
Collaborator Author

My original thought was to alter the Z-hops that Cura puts in. If the user was to set the "New Hop Height" to 0.00 over a certain layer range then that would negate the Cura hops for those layers. They could enter layers "13,25,66" and on those specific layers the Z-hop height would be their new value which could be 0.00 as easy as anything else. That idea goes back awhile to a script I called "AlterZHops".

Then a feature request here mentioned only hopping across Infill. I can't do that in post process (no model) but I could add hopping when printing the infill. That was easier to do when controlling all the hops, rather than simply altering the existing hops.

@GregValiant GregValiant added the PR: Post Processing ➕ Like adding beeps, more tunability or different Gcode pause at heights label Apr 15, 2025
Copy link
Member

@rburema rburema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually don't do these anymore, but as Erwan is busy-ish, I made some review-comments to hopefully help this along.

@GregValiant
Copy link
Collaborator Author

What is "Resolve Conversation"?

I'm going to do some more debugging on this just to make sure there are no "unexpected consequences" or a fat finger caused an inadvertent delete.
I'll make the new commit later today or tomorrow.
Thanks for the help.

Update per RBurema requested changes.
@GregValiant
Copy link
Collaborator Author

I haven't been able to break it so I've made a new commit with the changes.

@jellespijker jellespijker requested a review from Copilot April 24, 2025 21:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Changed the inserted "G0 F Z" lines to "G1 F Z" so they match the existing Cura syntax.
@GregValiant
Copy link
Collaborator Author

@HellAholic I made a commit based on feedback on the UM forum. The inserted Z-hop lines used "G0 F Z" and I have changed those to "G1 F Z" to match the Cura syntax.

Bug fix in line 505 that resulted in the first hop being the wrong Z.
@GregValiant
Copy link
Collaborator Author

I found a bug in line 505. It resulted in the first Z hop-up being wrong and effected the entire layer.

@GregValiant
Copy link
Collaborator Author

I found and fixed a bug that occurred when the "End Layer" was greater than the "Total Layer Count" of the print.

Bug fix for End_Layer when the entered layer > total layer count.

Update ZHopOnTravel.py

I'm not sure why git desktop did this.

Update ZHopOnTravel.py

I'm not sure why git desktop did this.

Bug fix

Bug fix for End_Layer when the entered layer > total layer count.
Bug fix for 'index_list' when using a layer list.  It now tracks the Z through the file rather than just the layers of interest.
@GregValiant
Copy link
Collaborator Author

Commit 7 is a bug fix of an initial design error.

Removed the Stashed Changes beginning and ends.

Update ZHopOnTravel.py

Add comments.
@GregValiant
Copy link
Collaborator Author

@HellAholic has there been any internal discussion regarding including or dropping this? There have been questions on a couple of forums.

@HellAholic
Copy link
Contributor

@GregValiant Nothing in terms of dropping. We do have a ticket for this to include it: CURA-12523

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Community Contribution 👑 Community Contribution PR's PR: Post Processing ➕ Like adding beeps, more tunability or different Gcode pause at heights
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants