Skip to content

Commit

Permalink
fix gltf export
Browse files Browse the repository at this point in the history
  • Loading branch information
justbuchanan committed Oct 20, 2023
1 parent 649587e commit 06795fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions cq-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,14 @@ def main():
if outfile == None:
print(converted)
else:
with open(outfile, 'w') as file:
file.write(converted)
if isinstance(converted, str):
with open(outfile, 'w') as file:
file.write(converted)
elif isinstance(converted, (bytes, bytearray)):
with open(outfile, 'wb') as file:
file.write(converted)
else:
raise TypeError("Expected converted output to be str, bytes, or bytearray. Got '%s'" % type(converted).__name__)

except Exception:
out_tb = traceback.format_exc()
Expand Down
6 changes: 3 additions & 3 deletions cqcodecs/cq_codec_gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def convert(build_result, output_file=None, error_file=None, output_opts=None):
# Put the GLTF output into the temp file
# Check to see if we are dealing with an assembly or a single object
if type(build_result.first_result.shape).__name__ == "Assembly":
build_result.first_result.shape.save(temp_file, binary=False)
build_result.first_result.shape.save(temp_file)
else:
raise ValueError("GLTF export is only available for CadQuery assemblies at this time")

# Read the GLTF output back in
with open(temp_file, 'r') as file:
with open(temp_file, 'rb') as file:
gltf_str = file.read()

return gltf_str
return gltf_str

0 comments on commit 06795fb

Please sign in to comment.