Henrik
Posts: 7
Joined: Sat Dec 09, 2023 4:36 am

Layer change script problems for the bambu p1s

I am struggling to make post layer scripts work.
I want the machine to do a nozzle wipe after a certain number of layers, but right now I am trying to make it work after every layer.

I have found some code on bambu related forums, asked chatgpt for assistance and tried some with a p1s system.
Currently I am using this code, but it is not behaving as I would like.

; Layer Change Script

; Save current position
M114 ; Report current position


; Now add the Z-hop to avoid collision
G91 ; Set relative positioning
G1 Z1.0 F300 ; Move Z axis up by 1.0mm

; Move to wipe position
G90 ; Set absolute positioning
G1 X60 Y265 F15000 ; Move to nozzle wipe position

; Nozzle wipe procedure
G92 E0 ; Zero extruder
G1 E-0.5 F300 ; Retract filament
G1 X100 F5000 ; Wipe right
G1 X70 F15000 ; Wipe left
G1 X100 F5000 ; Wipe right
G1 X70 F15000 ; Wipe left
G1 X100 F5000 ; Wipe right
G1 X70 F15000 ; Wipe left
G1 X60 F5000 ; Clearance

; Restore previous position
G91 ; Set relative positioning
G1 Z-1.0 F300 ; Move Z axis down by 1.0mm

; Manually insert the position reported by M114 here
; Example: If M114 reported X120 Y150 Z10
G90 ; Set absolute positioning
;G1 X[last_x] Y[last_y] Z[last_z] F15000 ; Move back to previous print position (THIS BIT DOESNT WORK)

; Continue printing
__________________________________

Since the remeber last position thing doesnt work properly, the nozzle moves down in z directly after the last script command and travels back to the intended printposition while extruding as interpret it. I have destroyed one platform already so a but more careful with testing now.

Any advice on how to alter this code to work as intended?
Attachments
travel moves.png
S3D-Taylor
Posts: 41
Joined: Tue Jun 20, 2023 10:55 am

Re: Layer change script problems for the bambu p1s

Try using the variables:
[previous_position_x]
[previous_position_y]
[previous_position_z]
Henrik
Posts: 7
Joined: Sat Dec 09, 2023 4:36 am

Re: Layer change script problems for the bambu p1s

Thank you Taylor, that improved the situation. The script looks like it now correctly can recall the previous position, but it still wants to do some funky stuff before it has started printing the first feature on the first layer. The blue extrude line happens when the first layer starts and it has taken 0,0,0 as the previous position. I was under the impression the post layer script would be applied to after the first layer was printed.

I tried adding {if layer_num > 0} to the start and {endif} to the bottom of the layer change script, but it didnt change anything.
Also tried layer number 1 just in case.

How can I prevent the code to want to the the scrape-extrude over the platform before starting the intended first feature?

Is there a way in S3d to implement every n-number of layers scripting or would that require a separate python postprocess script or executable that S3D could call under postprocessing scripts?

Henrik
Attachments
travel moves2.png
S3D-Taylor
Posts: 41
Joined: Tue Jun 20, 2023 10:55 am

Re: Layer change script problems for the bambu p1s

I would recommend using the following Layer Change scripts for your purposes, here are two variants:
To execute it at layers above 1:
{IF "[current_layer_number] > 1”}; Place nozzle cleaning command here

To execute it every 50 layers:
{IF "([current_layer_number] % 50) == 0"}; Place nozzle cleaning command here

However, if you would like to post process something more complex with a python script in the future, you can put something similar in the post processing script, the syntax should be the same as native terminal commands:
py [output_dir]/myPythonScript.py "[output_filepath]"
Henrik
Posts: 7
Joined: Sat Dec 09, 2023 4:36 am

Re: Layer change script problems for the bambu p1s

OK, that certainly made difference and the start problems are gone, but the script is also bringing new strange things to the visuals that I don't understand. Completely removing the script takes those new problems away. The script is currently like this (lower process):


{BLOCKIF "[current_layer_number] > 1”}
{BLOCKIF "{EVAL "[current_layer_number]%10"} == 0"}

; Save current position
M114 ; Report current position
G91 ; Set relative positioning
G1 Z1.0 F300 ; Move Z axis up by 1.0mm to avoid collision
G90 ; Set absolute positioning
M400 ; Wait for all moves to finish
G1 X[previous_position_x] Y[previous_position_y] Z[previous_position_z] ; Store the current position in custom variables

; Move to wipe position
G1 X60 Y265 F15000 ; Move to nozzle wipe position

; Move to wipe position
G90 ; Set absolute positioning
G1 X60 Y265 F15000 ; Move to nozzle wipe position

; Nozzle wipe procedure
G92 E0 ; Zero extruder
G1 E-0.5 F300 ; Retract filament
G1 X100 F5000 ; Wipe right
G1 X70 F15000 ; Wipe left
G1 X100 F5000 ; Wipe right
G1 X70 F15000 ; Wipe left
G1 X100 F5000 ; Wipe right
G1 X70 F15000 ; Wipe left
G1 X60 F5000 ; Clearance

; Restore previous position
G91 ; Set relative positioning
G1 Z-1.0 F300 ; Move Z axis down by 1.0mm


; Manually insert the position reported by M114 here
; Example: If M114 reported X120 Y150 Z10
G90 ; Set absolute positioning
G1 X[previous_position_x] Y[previous_position_y] Z[previous_position_z] F15000 ; Move back to previous print position


; Continue printing

{ENDBLOCKIF}
{ENDBLOCKIF}

It does skip full layers, and it also introduces some strange effect of cutting very small perimeters short as seen in the small holes.
How can the script affect this?
Attachments
skipped layers.png
cut short outer perimeters.png
Henrik
Posts: 7
Joined: Sat Dec 09, 2023 4:36 am

Re: Layer change script problems for the bambu p1s

I am trying to test new things but can't understand why adding in-between layer scripting affects the features of the layers themselves.
Anyone else seen this type of behavior?
S3D-Taylor
Posts: 41
Joined: Tue Jun 20, 2023 10:55 am

Re: Layer change script problems for the bambu p1s

Ah I see where the problem is. In your last few lines you've returned to the previous Z position, which makes it skip a layer since you've put them in the Post Layer Change Script.

Basically this is what was happening before:
G1 Z10 ; layer change
; your nozzle cleaning script
G1 X[previous_position_x] Y[previous_position_y] Z[previous_position_z](This was 9.8) F15000
; resume printing, but at layer height of 9.8 instead of 10

I would suggest putting them in the Pre Layer Change script instead, so the behavior would be:
; your nozzle cleaning script
G1 X[previous_position_x] Y[previous_position_y] Z[previous_position_z](9.8) F15000 ; Move back to previous print position
G1 Z10 ; layer change
; resume printing at the correct height
Henrik
Posts: 7
Joined: Sat Dec 09, 2023 4:36 am

Re: Layer change script problems for the bambu p1s

Changing to the pre layer script does work, and it seems the behavior is as expected then.
But the other error that mentioned persists.

At least in the visual representation of the code, there are alot of gaps in the perimeters when the script is present.
This is not there when the layer change script is deleted.

What is happening here? How can this be affected by the script?
Attachments
missing permimeter parts2.png

Return to “Troubleshooting and Bug Reports”