-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter_service.py
More file actions
55 lines (45 loc) · 1.73 KB
/
plotter_service.py
File metadata and controls
55 lines (45 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from contextlib import redirect_stderr, redirect_stdout
import io
def plot(ad, filepath, layer=0, model_number=4):
"""Plot an SVG file, optionally restricted to a single numbered layer."""
ad.plot_setup(filepath)
ad.options.mode = "plot"
ad.options.model = model_number
ad.options.auto_rotate = False
ad.options.reordering = 0
ad.options.check_limits = True
ad.options.clip_to_page = True
if layer > 0:
ad.options.mode = "layers"
ad.options.layer = layer
ad.plot_run()
ad.options.mode = "manual"
ad.options.manual_cmd = "disable_xy"
ad.plot_run()
def preview_plot(ad, filepath, layer=0):
"""Run a preview pass and return the captured AxiDraw output text."""
output_buffer = io.StringIO()
previous_preview = getattr(ad.options, 'preview', False)
previous_report_time = getattr(ad.options, 'report_time', False)
previous_mode = getattr(ad.options, 'mode', None)
previous_layer = getattr(ad.options, 'layer', None)
try:
with redirect_stdout(output_buffer), redirect_stderr(output_buffer):
ad.plot_setup(filepath)
if layer > 0:
ad.options.mode = "layers"
ad.options.layer = layer
ad.options.preview = True
ad.options.report_time = True
ad.plot_run()
finally:
ad.options.preview = previous_preview
ad.options.report_time = previous_report_time
if previous_mode is not None:
ad.options.mode = previous_mode
if previous_layer is not None:
ad.options.layer = previous_layer
output = output_buffer.getvalue().strip()
if not output:
output = 'Preview completed with no output.'
return output