Skip to content

Commit cd5a346

Browse files
author
Charlie83
committed
Add binary option to stl codec
1 parent 7827c56 commit cd5a346

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/cq_cli/cqcodecs/cq_codec_stl.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def convert(build_result, output_file=None, error_file=None, output_opts=None):
1818
if output_opts and "angularDeflection" in output_opts:
1919
angularDeflection = output_opts["angularDeflection"]
2020

21+
use_ascii = True
22+
if output_opts and "binary" in output_opts:
23+
use_ascii = output_opts["binary"]
24+
2125
# The exporters will add extra output that we do not want, so suppress it
2226
with helpers.suppress_stdout_stderr():
2327
# There should be a shape in the build results
@@ -30,7 +34,7 @@ def convert(build_result, output_file=None, error_file=None, output_opts=None):
3034
result = result.val()
3135

3236
# Put the STL output into the temp file
33-
result.exportStl(temp_file, linearDeflection, angularDeflection, True)
37+
result.exportStl(temp_file, linearDeflection, angularDeflection, use_ascii)
3438

3539
# Read the STL output back in
3640
with open(temp_file, "rb") as file:

tests/test_stl_codec.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,23 @@ def test_stl_codec_assembly_to_file(tmp_path):
164164
assert exitcode == 0
165165
content = out_path.read_bytes()
166166
assert content[:5] == b"solid"
167+
168+
def test_stl_codec_binary():
169+
"""
170+
Tests exporting to binary stl format.
171+
"""
172+
test_file = helpers.get_test_file_location("cube.py")
173+
174+
command = [
175+
sys.executable,
176+
"src/cq_cli/main.py",
177+
"--codec",
178+
"stl",
179+
"--infile",
180+
test_file,
181+
"--outputopts",
182+
"binary:True",
183+
]
184+
out, err, exitcode = helpers.cli_call(command)
185+
186+
assert out[:5] != b"solid"

0 commit comments

Comments
 (0)