Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the missing cube.obj #162

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading