-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,42 @@ | ||
from typing import Dict, Optional, Union | ||
|
||
from typing import Any, List, Optional, Tuple, Union | ||
Check failure on line 1 in tutorials/beginner_tutorial/convert.py GitHub Actions / ruffRuff (F401)
Check failure on line 1 in tutorials/beginner_tutorial/convert.py GitHub Actions / ruffRuff (F401)
Check failure on line 1 in tutorials/beginner_tutorial/convert.py GitHub Actions / ruffRuff (F401)
Check failure on line 1 in tutorials/beginner_tutorial/convert.py GitHub Actions / ruffRuff (F401)
Check failure on line 1 in tutorials/beginner_tutorial/convert.py GitHub Actions / ruffRuff (F401)
|
||
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 | ||
Check failure on line 7 in tutorials/beginner_tutorial/convert.py GitHub Actions / ruffRuff (F811)
|
||
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: | ||
Check failure on line 27 in tutorials/beginner_tutorial/convert.py GitHub Actions / ruffRuff (E711)
|
||
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() |