Skip to content

Commit

Permalink
cleaning tutorials (#180)
Browse files Browse the repository at this point in the history
* 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] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jgomez720 and github-actions[bot] authored Jan 18, 2024
1 parent 2491c45 commit e24f391
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tutorials/beginner_tutorial/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand Down
30 changes: 19 additions & 11 deletions tutorials/beginner_tutorial/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,43 @@
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())
output_file.close()
return body


convertCubetoSTL()
convertOBJtoSTL()
2 changes: 1 addition & 1 deletion tutorials/conversion_obj_step/output.step
Git LFS file not shown

0 comments on commit e24f391

Please sign in to comment.