-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Create PurgeLinesAndUnload.py #20013
base: main
Are you sure you want to change the base?
Conversation
This script has 4 options. Add Purge Lines will draw lines left, right, top, or bottom of the build plate and either fill length of half length. If a print takes up the entire width then the purge lines could be moved to the bottom.
@HellAholic the "Move around to the print start" function is something that came up in a post a while ago. I did account for cases where Cura adds the "Move to prime tower" line at the end of the startup. The script will add an orthogonal move to an edge before the actual move to the prime tower location. |
I'll take a look to see if I can update the code style. Will also try to play around with the current iteration to first get a grasp on how things work and what the output looks like. Might be a slow burner but it's on my todo list 👍 |
Changed 'Execute' procedure per suggestion. Add 'G10' firmware retraction support to 'Adjust Starting E'.
I went with the purge everything approach and it started working, something else I had in the background was interfering with the script. Update: |
Aloha, The slice result preview "should" in theory be simple enough, just have to figure out where I need to poke in the code to make it move. I think reloading the changed gcode is the doable part, but loading back to the original does not sound like a feasible option.
That should also be doable, but it requires some changes to the qml, adding a getter to the python with a pyqtsignal and such, and reading the description in a try/except to handle scripts without a description.
|
I hate unexpected bugs. The expected ones are much better. |
Wow. I have been integrating the "Disallowed Areas" into the code. There wasn't a lot of breakage, but there are more variable names to deal with (and there was already a lot). I'll go through your suggestions and make the changes and then push another commit. |
It might also be an idea to use enum strings, doesn't even need to be linked to the string value it can be an int, but to keep it as close to the current implementation as possible:
makes it easier to work with strings in the comparisons and also reduces the chance of making a typo, also helps with autocomplete xD You can also do the calculations for some values and store them in the self, since it's being passed along to the different functions, that will reduce the number of variables you need to pass with each function call. TLDR: |
Although it's a bit of a rare usecase to reload a gcode and run a post processing script on it, since the information regarding the post processing is already in at the end of header of the gcode file it should be possible to allow for running additional post processing without re-running the same scripts that already were executed on the gcode.
|
In the next week or two I'm going to tear this down and put it back together. It's working, but with the changes I've hacked in for the Prime Tower move and the Disallowed Areas it's turned into spaghetti code. It's pretty bad when even I can't stand it. So take a break. I'll add a new commit when I get done changing it. |
@HellAholic |
Hey Greg, |
Added a "quick purge" option before the actual unload to insure the filament is free to pull back. Made adjustments for "Machine Disallowed Areas". Added some comments. Re-ordered some of the code.
There it is. New and improved. One of the printers I used for the Disallowed Areas was a UM3. It has 6 areas defined and because I used a simple method of determining the "useable space" as a rectangle (rather than the actual shape), it ends up pushing the purge lines towards the print. There aren't many printers with the problem though, so the warning message I added should (hopefully) be sufficient. |
Ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, second opinion of a Cura Dev is also needed. :)
Any line with an "E" in it that does not specifically state which tool will be for the active extruder. That's why I didn't go any further into it. The "purge lines" don't have a retraction so the retract_amount doesn't come up. The purge lines would seem to be tool independent. The one thing I do see is that if there is a "Nozzle switch retraction distance" then it might not get accounted for at the start. In that case I don't know how the printer would know where the end of the filament is without the prime blob or something. We start to get into a lot more combinations of things. Since much of the start of a print on a UM machine is within the firmware, I can't check it out. |
So all of that is handled in FW for the UM printers, priming and such, no need to go that deep.
Outside of this, I don't think it's necessary to worry too much about the FW settings in UM machines, I used it as an example to showcase why we might need to consider the nozzle offset X/Y and allowing for extruder selection by user. |
I understand. If we are starting with T1 then the offset needs to be applied and the possibility of some other different parameters is there. |
Alright, I give...Where is "initial_extruder_nr" stored? |
Thanks for that. Are these statements true? I'm currently dealing with "Y" offsets and it is making my head hurt. "X" offsets seems to be working fine BUT I have made the assumption that the above statements are in fact true (at least for UM machines). Another assumption I've made is that any X offset will be a positive number, but the text boxes for offsets will allow negative numbers. |
"Right Extruder" and "Left Extruder" in case of the UM printers is used as position, since you can use different extruder variants in left or right position on the head, so you need the reference to where the Extruder of Type A is placed (left position or right position). That allows you to make the extruder variant definitions themselves position agnostic. left extruder will be equal to saying T0, right extruder will be the same as saying T1
For the negative/positive value, it will sort itself out, meaning:
|
I didn't change that warning message. Regardless of the extruder number, if there are purge lines in the Startup they are going to be commented out. Here is the script with the extruder offsets considered. I added a function at the bottom that determines the values for the "initial extruder". Whether a print starts with T0 or T1 makes no difference and the proper values are applied. I'm getting on a motorcycle and getting out of here. Have fun. |
Not gonna poke at it too much xD You're pretty much on point.
to
Since you're returning the num it will be assigned to self.init_extruder_nr in line 203 so no need for assigning it here. Have fun and ride safe. |
"I would use the initial extruder number for getting the nozzle offset still rather than defaulting to 1" On a dual-head printer with "side-by-side" nozzles - one of the nozzles must always have an offset. If the "primary" nozzle is T1, then the code (as written) should probably exit with a message. It might be possible to evaluate "T0 offset vs. T1 offset" and make a decision as to which one to use (and I'll think about that) but that seems a very small selection set of printers that would be defined that way. I suppose it would be possible to have "T0 Xoffset = -12.5" and "T1 Xoffset = 12.5" but I've never seen that. Changing from the hard coded "extruder[1]" to "extruder[num]" would keep the offsets from loading when T0 starts the print but that would allow "T0" to make it all the way to the right extents of the bed which would not be possible with hotends on a common printhead. My thinking is that: If there are offsets, they will be listed under T1, and those offsets are always in play regardless of which nozzle is in use. |
I get your point, without going into a multitude of checks it's not possible to do. Some machines can move with both extruders in the entire build plate area and others have physical limitations (S3 vs Method for example). |
I recall a post you made a couple of months ago where you indicated you were in favor of adding it directly to the engine rather than as a post-processor. An alternative would be to change this to an Extension/Plugin. The settings wouldn't be out of place in "Bed Adhesion". With the additions of the disallowed areas and tool offsets, it has grown in scope. As a post-processor (or plugin) it could be a stop-gap until changes are made to the engine. With the code in the Engine, a definite plus is that it would show up in the preview without having to load the gcode file. People would see right away if their Purge Line location was interfering with something else on the build plate (Prime Tower, brim, etc.). I'll continue the debugging today but I haven't seen any issues and certainly no show-stoppers. I did add "kick-outs" to both "Add Purge Lines" and "Circle around to..." if the particular printer has offsets assigned to T0. |
One change you made that I don't care for very much involves the end location of the "wipe" move at the end of the purge. It requires a close examination of the gcode preview to see that travel move at Y=35 and it would be hard for most people to notice it if it was in fact a problem and ran across the footprint of their print. You just know that someone will complain. |
I don't think you mean the ones with the purge_str += bit.
|
You can adjust the distance from the edge of the build plate, currently set to 5 based on the original code. |
Added consideration for Disallowed Areas and Tool Offsets. This also includes a lot of variables moved into "self".
I didn't get that fancy.
That creates this:
I just pushed a commit on this. |
Timing is everything...Reddit |
Loaded the new commit & sliced on my E3 S1 Pro. G-code looks good & seems to be functioning as expected in the PrusaSlicer G-code viewer with the Purge Lines on the Front Edge & Circle around to layer start enabled. I'll be doing a print tomorrow so can test it in the real world. |
I can't comment on the coding side & best practice but I've done several small prints with this commit on my simple setup & didn't experience any functional issues |
- variable names updated to reflect their use more clearly - removed obsolete if/else for move (the length of the list will be always 2)
Looks good.
and line 358 is deleted. That moves the comment from the end of data[1]) to the beginning of the travel section. Fits better I think.
I'll add a commit with that change. On another slightly different topic: |
Change the comment line location from the end of data[1] to the first line of the "moves". Update PurgeLinesAndUnload.py Move the "start from" comment from the end of data[1] to the first line of the "moves" list. Update PurgeLinesAndUnload.py Change the comment line location from the end of data[1] to the first line of the "moves".
df2068a
to
28f8e2a
Compare
I have a ticket open for that in the backlog, should be in before the next release. That includes making the travel move an optional move so it can be active / inactive and should always listen to the Layer Start X and Layer Start Y regardless of all other elements (prime tower position). |
Description
This script has 4 options.
Add Purge Lines:
Will draw lines left, right, top, or bottom of the build plate and either full length of half length. If a print takes up the entire width then the purge lines could be moved to the bottom.
Circle Around To Layer Start:
Creates an orthogonal tool path that moves the nozzle around the periphery of the build plate before moving in to the Layer Start location. This keeps strings from dragging across the print location on the build plate.
Adjust Starting E Location:
Cura adds a retraction after the StartUp Gcode. If there is also a retraction within the StartUp Gcode (or when using Add Purge Lines) it causes a double retraction. This option will change that "G1 E-" line to a "G92 E" so the filament location within the nozzle can be adjusted to provide for an exact start to the skirt/brim/raft.
Unload FIlament at Print End:
Adds an unload sequence of G1 E commands to back the filament out of the hot end and out of the extruder. Works well with long-tube bowden printers.
The script supports:
Absolute and Relative extrusion
Rectangular and Elliptic beds
Origin-At-Center whether True or False.
Disallowed Areas
Settings
Type of change
How Has This Been Tested?
I've been using this script for a year.
Test Configuration:
Dell Laptop 16mb of RAM
Windows 10 Pro
Cura versions 4.13.1 and up.
Checklist: