Skip to content
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

GCode filenames with percent sign (%) in the filename causes timelapse screenshot saving to fail. #4365

Closed
pvince opened this issue Jan 9, 2022 · 3 comments · Fixed by #4366
Labels
approved Issue has been approved by the bot or manually for further processing bug Issue describes a bug done Done but not yet released grabbed Grabbed by someone from the community to be implemented/fixed
Milestone

Comments

@pvince
Copy link

pvince commented Jan 9, 2022

What were you doing?

When a filename has "%" characters in it, timelapses will not be created. Octoprint.log logs the following error message each time it tries to capture a snapshot:

2022-01-08 18:48:33,257 - octoprint.events - ERROR - Got an exception while sending event ZChange (Payload: {'new': -10.0, 'old': 10.0}) to <bound method ZTimelapse._on_z_change of <octoprint.timelapse.ZTimelapse object at 0x9e7c2350>>
Traceback (most recent call last):
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/events.py", line 203, in _work
    listener(event, payload)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/timelapse.py", line 873, in _on_z_change
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/timelapse.py", line 693, in capture_image
    self._capture_dir,
TypeError: not enough arguments for format string

Line 693 of timelapse.py is:

filename = os.path.join(
self._capture_dir,
_capture_format.format(prefix=self._file_prefix) % self._image_number,
)

I added a debug line immediately before this one to output the variables involved, that resulted in this log statement:

octoprint.timelapse - INFO - capture_dir: /home/pi/.octoprint/timelapse/tmp, capture_format: {prefix}-%d.jpg, prefix: CE3PRO upload
s_files_880895_tree_crown_loop_012 3D Max PLA lw 0.4mm lh 0.12mm if 5% ext1 210.0C bed 60.0C_20220108202600, image_number: 0

Note the value of prefix is CE3PRO upload s_files_880895_tree_crown_loop_012 3D Max PLA lw 0.4mm lh 0.12mm if 5% ext1 210.0C bed 60.0C_20220108202600.

This is because in Cura I am using a plugin called 'Gcode Filename Format Plus' which by default sets the filename to [abbr_machine] [base_name]2 [brand] [material] lw [line_width]mm lh [layer_height]mm if [infill_sparse_density]% ext1 [material_print_temperature]C bed [material_bed_temperature]C

When the first part of Line 693 resolves: _capture_format.format(prefix=self._file_prefix) we end up with the string:
CE3PRO upload s_files_880895_tree_crown_loop_012 3D Max PLA lw 0.4mm lh 0.12mm if 5% ext1 210.0C bed 60.0C_20220108202600-%d.jpg

When Python attempts to format that string to replace the %d, it finds itself with two candidates, % and %d but it only has one input parameter self._image_number

I suspect the fix for this would be to insert the image number first, then replace the prefix.

For now, I have worked around the issue by updating the Gcode Filename Format Plus to ommit the percent sign.

What did you expect to happen?

Timelapse screenshots to be taken, and the timelapse to be gneerated.

What happened instead?

OctoPrint generates an error at each ZChange event. (see above for error)

Did the same happen when running OctoPrint in safe mode?

I tracked down the issue in the source code, so I did not try in safe mode.

Version of OctoPrint

OctoPrint 1.7.2 Python 3.7.3 OctoPi 0.18.0

Printer model & used firmware incl. version

Ender 3 Pro w/ GTT SKR Mini v2.0. Custom Marlin 2.0.9.3

Browser and version of browser, operating system running browser

Firefox 95.0.2

System Info Bundle

octoprint-systeminfo-20220108132352.zip

Link to contents of Javascript console in the browser

N/A

Screenshot(s)/video(s) showing the problem:

I have read the FAQ
.

@github-actions github-actions bot added the triage This issue needs triage label Jan 9, 2022
@jneilliii jneilliii added approved Issue has been approved by the bot or manually for further processing bug Issue describes a bug and removed triage This issue needs triage labels Jan 9, 2022
@jneilliii
Copy link
Contributor

Confirmed bug, I'm able to reproduce. I suspect this is related to the recent feature of allowing special characters in filenames that was not possible previously. Thank for the detailed report @pvince

@jneilliii
Copy link
Contributor

Thinking changing _capture_format = "{prefix}-%d.jpg" to _capture_format = "{prefix}-{image_number}.jpg" and _capture_format.format(prefix=self._file_prefix) % self._image_number, to _capture_format.format(prefix=self._file_prefix, image_number=self._image_number), would potentially resolve this issue. Of course would have to adjust throughout all references.

@jneilliii jneilliii added the grabbed Grabbed by someone from the community to be implemented/fixed label Jan 9, 2022
@jneilliii
Copy link
Contributor

Initial testing seems to be positive. One thing I noticed while looking at this is the _capture_glob wasn't being used for the _render function, which I think it should have been versus _capture_format. Will submit PR shortly once this test render completes.

jneilliii added a commit to jneilliii/OctoPrint that referenced this issue Jan 9, 2022
… snapshots and rendering the timelapse. encodes % for format replacement in both the ffmpeg command line and while taking snapshots. OctoPrint#4365
@cp2004 cp2004 linked a pull request Jan 9, 2022 that will close this issue
10 tasks
@jneilliii jneilliii added the pr pending A pull request addressing this has been submitted but not yet merged label Jan 13, 2022
@foosel foosel added this to the 1.8.0 milestone Jan 17, 2022
@jneilliii jneilliii added the done Done but not yet released label Feb 11, 2022
@cp2004 cp2004 removed the pr pending A pull request addressing this has been submitted but not yet merged label Feb 25, 2022
@foosel foosel closed this as completed in 6430b23 May 17, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Issue has been approved by the bot or manually for further processing bug Issue describes a bug done Done but not yet released grabbed Grabbed by someone from the community to be implemented/fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants