Skip to content

Commit 86eb6eb

Browse files
committed
Bug-fix in bracket recognition
Correct bracket recognition iin single line snippets implemented. Readme updated and corrected
1 parent de15e78 commit 86eb6eb

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

PyGcode.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,13 @@ def copy_rename(old_file_name, new_file_name):
160160
for s in fin:
161161
if s.lstrip().startswith(pattern + ':'):
162162
fout.write("''')\n")
163-
fout.write(s.replace(pattern+':','').strip()+'\n')
163+
line = s.replace(pattern+':','').strip() +'\n'
164+
165+
line = re.sub('<~\(', '{', line)
166+
line = re.sub('\)~>', '}', line)
167+
line = re.sub('<\(', '[', line)
168+
line = re.sub('\)>', ']', line)
169+
fout.write(line)
164170
fout.write("print('''")
165171
elif s.lstrip().startswith(pattern+'<'):
166172
fout.write("''')\n")

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ You will need python 3 to run this script ([Python 3 Download](https://www.pytho
1515
e.g.
1616
`python PyGcode.py -ext _py.gcode -o benchy.gcode`
1717

18-
In PrusaSlicer the postprocessing script can be provided as a bat file where the created gcode is passed as an argument. In Windows you can use the batch file `RunPyGcode.bat` that contains the python command.
18+
In PrusaSlicer the postprocessing script can be provided as a bat file where the created gcode is passed as an argument. In Windows you can use the batch file `RunPyGcode.bat` that contains the command.
1919

20-
`python %~dp0\PyGcode.py -ext _py.gcode -o %1`
20+
python "%~dp0\PyGcode.py" -ext _py.gcode -o %1`
21+
pause`
2122

22-
where `%~dp0` is the path of the PyGcode.py file and `%1` is the path to the exported g-code file.
23+
where `%~dp0` is the relative path to the PyGcode.py file and `%1` is the path to the exported g-code file.
2324

2425
## Including python code
2526

@@ -41,9 +42,9 @@ A single line code starts with the following pattern:
4142

4243
;Python:
4344

44-
followed by a python command
45+
followed by a python command ('<(' and ')>' replace square brackets)
4546

46-
;Python: temperatures = [a for a in range(195, 220, 5)]
47+
;Python: temperatures = <(a for a in range(195, 220, 5))>
4748

4849
### Multi-line code block
4950

RunPyGcode.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
python %~dp0\PyGcode.py -ext _py.gcode -o %1
1+
python "%~dp0\PyGcode.py" -ext _py.gcode -o %1
22
pause

0 commit comments

Comments
 (0)