Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/cq_cli/cqcodecs/cq_codec_stl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def convert(build_result, output_file=None, error_file=None, output_opts=None):
if output_opts and "angularDeflection" in output_opts:
angularDeflection = output_opts["angularDeflection"]

use_ascii = True
if output_opts and "binary" in output_opts:
use_ascii = not output_opts["binary"]

# 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
Expand All @@ -30,7 +34,7 @@ def convert(build_result, output_file=None, error_file=None, output_opts=None):
result = result.val()

# Put the STL output into the temp file
result.exportStl(temp_file, linearDeflection, angularDeflection, True)
result.exportStl(temp_file, linearDeflection, angularDeflection, use_ascii)

# Read the STL output back in
with open(temp_file, "rb") as file:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_stl_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,24 @@ def test_stl_codec_assembly_to_file(tmp_path):
assert exitcode == 0
content = out_path.read_bytes()
assert content[:5] == b"solid"


def test_stl_codec_binary():
"""
Tests exporting to binary stl format.
"""
test_file = helpers.get_test_file_location("cube.py")

command = [
sys.executable,
"src/cq_cli/main.py",
"--codec",
"stl",
"--infile",
test_file,
"--outputopts",
"binary:True",
]
out, err, exitcode = helpers.cli_call(command)

assert out[:5] != b"solid"