From e24f391858ae8f8be0fce721d6f3a44c0c1930c9 Mon Sep 17 00:00:00 2001 From: Josh Gomez <114548659+jgomez720@users.noreply.github.com> Date: Thu, 18 Jan 2024 15:26:02 -0700 Subject: [PATCH] cleaning tutorials (#180) * cleaning tutorials * Updating script outputs * update python script * LOOK ON MY REFORMAT, YE MIGHTY, AND DESPAIR! * Updating script outputs * update the convert.py script with more comments * LOOK ON MY REFORMAT, YE MIGHTY, AND DESPAIR! * Updating script outputs --------- Co-authored-by: github-actions[bot] --- tutorials/beginner_tutorial/convert.js | 2 +- tutorials/beginner_tutorial/convert.py | 30 ++++++++++++++--------- tutorials/conversion_obj_step/output.step | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/tutorials/beginner_tutorial/convert.js b/tutorials/beginner_tutorial/convert.js index 1042c4e..1ccf48f 100644 --- a/tutorials/beginner_tutorial/convert.js +++ b/tutorials/beginner_tutorial/convert.js @@ -13,7 +13,7 @@ async function convertOBJtoSTEP() { for (const key in response.outputs) { if (response.outputs.hasOwnProperty(key)) { const output = response.outputs[key]; - const outputFilePath = "./output.step"; + const outputFilePath = "./gear.step"; console.log(`Saving output to ${outputFilePath}`); diff --git a/tutorials/beginner_tutorial/convert.py b/tutorials/beginner_tutorial/convert.py index 6f550ec..01ceeed 100644 --- a/tutorials/beginner_tutorial/convert.py +++ b/tutorials/beginner_tutorial/convert.py @@ -9,30 +9,38 @@ from kittycad.types import Unset -# Create a new client with your token parsed from the environment variable -# KITTYCAD_API_TOKEN -def convertCubetoSTL(): +# Create a new function to convert an OBJ file to an STL file. +def convertOBJtoSTL(): + # Create a new client with your token parsed from the environment variable (KITTYCAD_API_TOKEN) client = ClientFromEnv(timeout=500, verify_ssl=True) - # Convert a file from OBJ to STL. + # Read in the contents of the file. - file = open("./cube.obj", "rb") + file = open("./dodecahedron.obj", "rb") content = file.read() file.close() + + # Call the create_file_conversion function with the required parameters: client, body, src_format, and output_format. + result: Optional[Union[Error, FileConversion]] = create_file_conversion.sync( - client=client, - body=content, - src_format=FileImportFormat.OBJ, - output_format=FileExportFormat.STL, + client=client, # The client you created above. + body=content, # The contents of the file you read in. + src_format=FileImportFormat.OBJ, # The format of the file you read in. + output_format=FileExportFormat.STL, # The format you want to convert to. ) + + # Check if the result is an error or None. if isinstance(result, Error) or result is None: raise Exception("There was a problem") + body: FileConversion = result if isinstance(body.outputs, Unset): raise Exception("Expected outputs to be set") + + # Loop through the outputs and save them to a file. outputs: Dict[str, Base64Data] = body.outputs for _, output in outputs.items(): - output_file_path = "./output.stl" + output_file_path = "./dodecahedron.stl" print(f"Saving output to {output_file_path}") output_file = open(output_file_path, "wb") output_file.write(output.get_decoded()) @@ -40,4 +48,4 @@ def convertCubetoSTL(): return body -convertCubetoSTL() +convertOBJtoSTL() diff --git a/tutorials/conversion_obj_step/output.step b/tutorials/conversion_obj_step/output.step index 6a93c9e..2950ec7 100644 --- a/tutorials/conversion_obj_step/output.step +++ b/tutorials/conversion_obj_step/output.step @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2f876b70ca4e28474fd60310507bf4e263ea8fa9e003ea042c0b7468be345692 +oid sha256:36ad5d5187395437a0b9c37de70e511a3d126a375a013ef9616c43d1f1209ac2 size 504538