Skip to content

Commit

Permalink
Add the missing cube.obj (#162)
Browse files Browse the repository at this point in the history
* Add the missing cube.obj

* Use the more up to date script for convert.py

---------

Co-authored-by: lf94 <[email protected]>
  • Loading branch information
lf94 and lf94 authored Jan 10, 2024
1 parent 7a9e8e7 commit 3d8ac7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
31 changes: 11 additions & 20 deletions tutorials/beginner_tutorial/convert.py
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

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

tutorials/beginner_tutorial/convert.py:1:20: F401 `typing.Any` imported but unused

Check failure on line 1 in tutorials/beginner_tutorial/convert.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

tutorials/beginner_tutorial/convert.py:1:20: F401 `typing.Any` imported but unused

Check failure on line 1 in tutorials/beginner_tutorial/convert.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

tutorials/beginner_tutorial/convert.py:1:25: F401 `typing.List` imported but unused

Check failure on line 1 in tutorials/beginner_tutorial/convert.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

tutorials/beginner_tutorial/convert.py:1:25: F401 `typing.List` imported but unused

Check failure on line 1 in tutorials/beginner_tutorial/convert.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

tutorials/beginner_tutorial/convert.py:1:41: F401 `typing.Tuple` imported but unused

Check failure on line 1 in tutorials/beginner_tutorial/convert.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

tutorials/beginner_tutorial/convert.py:1:41: F401 `typing.Tuple` imported but unused
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

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F811)

tutorials/beginner_tutorial/convert.py:7:35: F811 Redefinition of unused `Error` from line 4

Check failure on line 7 in tutorials/beginner_tutorial/convert.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F811)

tutorials/beginner_tutorial/convert.py:7:35: F811 Redefinition of unused `Error` from line 4
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

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E711)

tutorials/beginner_tutorial/convert.py:27:47: E711 Comparison to `None` should be `cond is None`

Check failure on line 27 in tutorials/beginner_tutorial/convert.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E711)

tutorials/beginner_tutorial/convert.py:27:47: E711 Comparison to `None` should be `cond is 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()
3 changes: 3 additions & 0 deletions tutorials/beginner_tutorial/cube.obj
Git LFS file not shown

0 comments on commit 3d8ac7e

Please sign in to comment.