From ef83cda9d7bab0834ba18a07ab1c017a90db87b9 Mon Sep 17 00:00:00 2001 From: lf94 Date: Tue, 9 Jan 2024 16:10:56 -0500 Subject: [PATCH 1/2] Add the missing cube.obj --- tutorials/beginner_tutorial/cube.obj | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tutorials/beginner_tutorial/cube.obj diff --git a/tutorials/beginner_tutorial/cube.obj b/tutorials/beginner_tutorial/cube.obj new file mode 100644 index 0000000..a71ccfd --- /dev/null +++ b/tutorials/beginner_tutorial/cube.obj @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0f6f06e56c43fb873068030ee3caa41dcda9aafe48bd3faf654f7bc3e3f6277 +size 696 From fa8e61663a9e4979ab581a2986ac985141877a66 Mon Sep 17 00:00:00 2001 From: lf94 Date: Tue, 9 Jan 2024 20:58:02 -0500 Subject: [PATCH 2/2] Use the more up to date script for convert.py --- tutorials/beginner_tutorial/convert.py | 31 +++++++++----------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/tutorials/beginner_tutorial/convert.py b/tutorials/beginner_tutorial/convert.py index b8677e1..25ff0bd 100644 --- a/tutorials/beginner_tutorial/convert.py +++ b/tutorials/beginner_tutorial/convert.py @@ -1,51 +1,42 @@ -from typing import Dict, Optional, Union - +from typing import Any, List, Optional, Tuple, Union from kittycad.api.file import create_file_conversion from kittycad.client import ClientFromEnv from kittycad.models import Error, FileConversion -from kittycad.models.base64data import Base64Data from kittycad.models.file_export_format import FileExportFormat from kittycad.models.file_import_format import FileImportFormat +from kittycad.models.error import Error from kittycad.types import Unset +from kittycad.models.base64data import Base64Data +from typing import Dict -# Create a new client with your token parsed from the environment variable: -# KITTYCAD_API_TOKEN. - - -def convertOBJtoSTL(): +# Create a new client with your token parsed from the environment variable +# KITTYCAD_API_TOKEN +def convertCubetoSTL(): client = ClientFromEnv(timeout=500, verify_ssl=True) - # Convert a file from OBJ to STL. # Read in the contents of the file. - file = open("./dodecahedron.obj", "rb") + file = open("./cube.obj", "rb") content = file.read() file.close() - result: Optional[Union[Error, FileConversion]] = create_file_conversion.sync( client=client, body=content, src_format=FileImportFormat.OBJ, output_format=FileExportFormat.STL, ) - - if isinstance(result, Error) or result is None: + if isinstance(result, Error) or result == None: raise Exception("There was a problem") - body: FileConversion = result - if isinstance(body.outputs, Unset): raise Exception("Expected outputs to be set") - outputs: Dict[str, Base64Data] = body.outputs - + for _, output in outputs.items(): output_file_path = "./output.stl" print(f"Saving output to {output_file_path}") output_file = open(output_file_path, "wb") output_file.write(output.get_decoded()) output_file.close() - return body - -convertOBJtoSTL() +convertCubetoSTL()