Skip to content

Commit 0461d0e

Browse files
Charlie-83Charlie83
andauthored
Add binary option to stl codec (#45)
Co-authored-by: Charlie83 <dev@charlie83.com>
1 parent 7827c56 commit 0461d0e

2 files changed

Lines changed: 26 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 = not 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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,24 @@ 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+
169+
def test_stl_codec_binary():
170+
"""
171+
Tests exporting to binary stl format.
172+
"""
173+
test_file = helpers.get_test_file_location("cube.py")
174+
175+
command = [
176+
sys.executable,
177+
"src/cq_cli/main.py",
178+
"--codec",
179+
"stl",
180+
"--infile",
181+
test_file,
182+
"--outputopts",
183+
"binary:True",
184+
]
185+
out, err, exitcode = helpers.cli_call(command)
186+
187+
assert out[:5] != b"solid"

0 commit comments

Comments
 (0)