-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcq_codec_svg.py
More file actions
29 lines (22 loc) · 1.01 KB
/
cq_codec_svg.py
File metadata and controls
29 lines (22 loc) · 1.01 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
import os
from cadquery import exporters
import cq_cli.cqcodecs.codec_helpers as helpers
def convert(build_result, output_file=None, error_file=None, output_opts=None):
# Create a temporary file to put the STL output into
temp_dir = helpers.temp_dir()
temp_file = os.path.join(temp_dir.path, "temp_svg.svg")
# The exporters will add extra output that we do not want, so suppress it
with helpers.suppress_stdout_stderr():
# There should be a shape in the build results
result = build_result.results[0].shape
# If the build result is an assembly, we have to make it a compound before trying to export it as SVG
if type(result).__name__ == "Assembly":
result = result.toCompound()
# Put the STEP output into the temp file
exporters.export(
result, temp_file, exporters.ExportTypes.SVG, opt=output_opts,
)
# Read the STEP output back in
with open(temp_file, "r") as file:
step_str = file.read()
return step_str