{"id":15913069,"url":"https://github.com/drgfreeman/gcodepause","last_synced_at":"2025-04-03T03:16:32.054Z","repository":{"id":130571085,"uuid":"200725919","full_name":"DrGFreeman/GCodePause","owner":"DrGFreeman","description":"Add pause(s) at specific layer height(s) in 3D printing GCODE","archived":false,"fork":false,"pushed_at":"2019-12-17T04:45:41.000Z","size":19,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-08T17:14:36.892Z","etag":null,"topics":["3d-printer","3d-printing","3d-printing-gcode","custom-gcode","g-code","gcode","pause"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DrGFreeman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-05T20:43:05.000Z","updated_at":"2024-04-24T22:12:28.000Z","dependencies_parsed_at":"2023-04-06T10:00:47.647Z","dependency_job_id":null,"html_url":"https://github.com/DrGFreeman/GCodePause","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrGFreeman%2FGCodePause","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrGFreeman%2FGCodePause/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrGFreeman%2FGCodePause/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrGFreeman%2FGCodePause/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DrGFreeman","download_url":"https://codeload.github.com/DrGFreeman/GCodePause/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246927844,"owners_count":20856198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["3d-printer","3d-printing","3d-printing-gcode","custom-gcode","g-code","gcode","pause"],"created_at":"2024-10-06T16:22:56.081Z","updated_at":"2025-04-03T03:16:31.960Z","avatar_url":"https://github.com/DrGFreeman.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GCodePause python package\n\nAdd pauses at specific layer heights in 3D printing G-code.\n\nBy Julien de la Bruère-Terreault (drgfreeman@tuta.io)\n\n## Installation\n\nThe *gcodepause* package can be installed using pip:\n\n```\npip install git+https://github.com/DrGFreeman/GCodePause.git\n```\n\nOr from sources:\n\n```\npython setup.py install\n```\n\n## Usage\n\nPauses can be added to a .gcode file using the `gcodepause.GCodeFile` class as demonstrated in the example below:\n\n```python\nfrom gcodepause import GCodeFile\n\n# Create a GCodeFile instance from the source .gcode file\ngcode = GCodeFile('source.gcode')\n\n# Add a pause at the begining of layer at height of 4.6mm (z).\n#   Raise the print head 25mm (z_offset) and move the\n#   print head to X,Y coordinates 125, 200 (x_pause, y_pause).\ngcode.insert_pause(z=4.6, z_offset=25, x_pause=125, y_pause=200,\n                   message='Message to display')\n\n# Write the modified G-code to a new file\ngcode.write('modified.gcode')\n```\n\nAlternatively, pauses can be defined in a .yaml file. Given a .yaml file *pauses.yaml* with the following content:\n\n```yaml\n# pauses.yaml\n4.2: # Pause at layer height of 4.2mm\n  z_offset: 20\n  x_pause: 125\n  y_pause: 200\n  message: Message for 4.2\n  \n7: # Pause at layer height of 7mm\n  z_offset: 15\n  x_pause: 10.5\n  y_pause: 10.5\n  message: Message for 7.0\n```\nThe following code will insert pauses at the begining of the layers at heights of 4.2mm and 7mm with the respective associated parameters and save the modified gcode into a file named *source_pause.gcode*:\n\n```python\nfrom gcodepause import GCodeFile\n\ngcode = GCodeFile('source.gcode')\n\n# Add pauses as specified in the .yaml file\ngcode.insert_pause_from_yaml('pauses.yaml')\n\n# Write the modified G-code to a new file using the default name\n# \u003coriginal_name\u003e_pause.gcode\ngcode.write()\n```\n\nThe diff function below shows the lines added into *source_pause.gcode*:\n\n```\n$ diff source.gcode source_pause.gcode\n21907a21908,21914\n\u003e ;BEGIN_PAUSE\n\u003e G91    ; Put in relative mode\n\u003e G1 Z20    ; Raise hot end by 20mm\n\u003e G90    ; Put back in absolute mode\n\u003e G1 X125 Y200    ; Move the X \u0026 Y away from the print\n\u003e M0 Message for 4.2    ; Pause and wait for the user\n\u003e ;END_PAUSE\n35010a35018,35024\n\u003e ;BEGIN_PAUSE\n\u003e G91    ; Put in relative mode\n\u003e G1 Z15    ; Raise hot end by 15mm\n\u003e G90    ; Put back in absolute mode\n\u003e G1 X10.5 Y10.5    ; Move the X \u0026 Y away from the print\n\u003e M0 Message for 7.0    ; Pause and wait for the user\n\u003e ;END_PAUSE\n```\n\nThe `GCodeFile` object has different attributes and additional methods that can be helpful:\n\nThe `.layers` attribute contains an `OrderedDict` of the different layers and their respective line number in the current state of the gcode (zero indexed):\n\n```python \n\u003e\u003e\u003e gcode.layers\nOrderedDict([(0.2, 46),\n             (0.4, 1139),\n             (0.6, 2237),\n             (0.8, 3334),\n             ...\n             (16.6, 80939),\n             (16.8, 81018),\n             (17.0, 81096),\n             (17.2, 81173)])\n```\n\nThe `.pauses` attribute contains an `OrderedDict` of the different pauses and their respective start and end line numbers in the current state of the gcode (zero indexed):\n\n```python \n\u003e\u003e\u003e gcode.pauses\nOrderedDict([(4.2, (21907, 21913)), (7.0, (35017, 35023))])\n```\n\nThe `.remove_pause(height)` method removes the pause at the specified height (if present):\n\n```python \n\u003e\u003e\u003e gcode.remove_pause(4.2)\n\u003e\u003e\u003e gcode.pauses\nOrderedDict([(7.0, (35010, 35016))])\n```\n\nFinally, the `.pauses_template` attribute contains a list of the lines that will be inserted into the gcode to instruct the printer to pause:\n\n```python\n\u003e\u003e\u003e gcode.pause_template\n[';BEGIN_PAUSE\\n',\n 'G91    ; Put in relative mode\\n',\n 'G1 Z{z_offset:.4g}    ; Raise hot end by {z_offset:.4g}mm\\n',\n 'G90    ; Put back in absolute mode\\n',\n 'G1 X{x_pause:.4g} Y{y_pause:.4g}    ; Move the X \u0026 Y away from the print\\n',\n 'M117 {message}    ; Diplay message to user\\n',\n 'M0     ; Pause and wait for the user\\n',\n ';END_PAUSE\\n']\n```\n\n## Pause G-code\n\nThe G-code inserted for each pause will first move the print head to the speficied coordinates using [`G1`](https://www.reprap.org/wiki/G-code#G0_.26_G1:_Move) commands (in relative mode for Z and absolute for X \u0026 Y). Then, a [`M117`](https://www.reprap.org/wiki/G-code#M117:_Display_Message) command is issued to display the pause message to the user. Finally, a [`M0`](https://www.reprap.org/wiki/G-code#M0:_Stop_or_Unconditional_stop) command is issued to pause the print until resumed by the user.\n\nThese commands will be properly interpreted by printers running Marlin or RepRap firmware. Compatibility with other firmware should be verified [here](https://www.reprap.org/wiki/G-code).\n\n## Notes\n\n1. If no layer exist at the specified pause `z` value, a warning will be issued and the pause will be inserted at the next (higher) layer.\n1. If the specified pause `z` value exceeds the height of the last layer, a warning will be issued and the pause will not be added.\n1. It is recommended to avoid moving the print head at the limits of the printer bed during the pause as this may trigger limit switches or cause mechanical contacts, potentially resulting in a horizontal offset in the print at the location of the pause(s).\n1. To detect the layer changes in the G-code, the parser looks for a comment line with the layer height (e.g. `;4.2` for the layer at 4.2mm) at the begining of the layer change. Ensure that the slicer includes this line at the begining of each layer change. In [PrusaSlicer](https://www.prusa3d.com/prusaslicer/), this is included by default under *Printer Settings -\u003e Custom G-code -\u003e Before layer change G-code* (third line below). Other slicers should also allow the inclusion of custom G-code before the layer change.\n\n```\n;BEFORE_LAYER_CHANGE\nG92 E0.0\n;[layer_z]\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrgfreeman%2Fgcodepause","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrgfreeman%2Fgcodepause","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrgfreeman%2Fgcodepause/lists"}