Yes! Sketchfab is a popular platform for publishing, sharing, and discovering 3D, VR, and AR content. It allows users to upload 3D models, view them in a browser, and embed them in websites. Sketchfab is widely used by artists, game developers, architects, and educators.
Sketchfab also provides an API (Application Programming Interface) that lets developers interact with Sketchfab programmatically. With the API, you can:
The API uses RESTful endpoints and requires authentication (usually via an API key). You can find the official documentation and details on how to use it on Sketchfab’s Developer Portal.
Do you have a specific question about Sketchfab or its API? For example:
Yes! Rhino Python refers to the use of the Python scripting language within Rhinoceros 3D (commonly called Rhino), a popular 3D modeling software. Rhino provides a powerful Python scripting interface through RhinoScriptSyntax and the rhino3dm library, allowing users to automate tasks, create custom tools, and extend Rhino’s functionality.
RhinoScriptSyntax
rhino3dm
Integration with Grasshopper
Automation
Here’s a basic example of creating a sphere in Rhino using Python:
pythonimport rhinoscriptsyntax as rs # Create a sphere with radius 5 at the origin sphere_id = rs.AddSphere([0, 0, 0], 5) rs.ObjectColor(sphere_id, (255, 0, 0)) # Color it red
EditPythonScript or use the PythonScript command.Are you looking to automate something in Rhino, or do you have a specific task in mind? I can help with code snippets, best practices, or troubleshooting!
Absolutely! To upload .obj files to Sketchfab using Python, you’ll need to:
.obj file along with any required metadata.Below is a step-by-step script to achieve this. Make sure you have the required libraries installed:
bashpip install requests tomli
pythonimport os import requests import tomli from pathlib import Path # 1. Load Sketchfab API credentials and TOML descriptor SKETCHFAB_API_TOKEN = "your_sketchfab_api_token" # Replace with your token TOML_PATH = "path/to/your/descriptor.toml" # Path to your TOML file OBJ_DIR = "path/to/your/obj/files" # Directory containing OBJ files # 2. Read the TOML descriptor def load_toml(toml_path): with open(toml_path, "rb") as f: return tomli.load(f) # 3. Upload a single OBJ file to Sketchfab def upload_to_sketchfab(obj_path, metadata): url = "https://api.sketchfab.com/v3/models" headers = { "Authorization": f"Token {SKETCHFAB_API_TOKEN}", "Content-Type": "multipart/form-data", } files = { "modelFile": open(obj_path, "rb"), } data = { "name": metadata.get("name", Path(obj_path).stem), "description": metadata.get("description", ""), "tags": metadata.get("tags", []), "isPublished": metadata.get("isPublished", False), } response = requests.post(url, headers=headers, files=files, data=data) return response.json() # 4. Main function def main(): descriptor = load_toml(TOML_PATH) obj_files = [f for f in os.listdir(OBJ_DIR) if f.endswith(".obj")] for obj_file in obj_files: obj_path = os.path.join(OBJ_DIR, obj_file) model_name = Path(obj_file).stem metadata = descriptor.get(model_name, {}) result = upload_to_sketchfab(obj_path, metadata) print(f"Uploaded {obj_file}: {result.get('uid', 'Failed')}") if __name__ == "__main__": main()
TOML Descriptor: The script reads a TOML file that describes each model (e.g., name, description, tags).
Example descriptor.toml:
toml[model1] name = "My Model 1" description = "A 3D model of a chair" tags = ["furniture", "chair"] isPublished = true [model2] name = "My Model 2" description = "A 3D model of a table" tags = ["furniture", "table"] isPublished = false
Sketchfab API: The script uses the Sketchfab API to upload each .obj file, along with metadata from the TOML file.
Output: It prints the Sketchfab model UID for each successful upload.
.obj files and a descriptor.toml file in the specified paths.Let me know if you need help customizing the script or setting up the TOML file! Would you like to add more features, like error handling or progress tracking?
Using Python scripts from Grasshopper (the visual programming interface for Rhino) is a powerful way to automate tasks, including uploading models to Sketchfab. Here’s how you can integrate the Sketchfab upload script into Grasshopper:
You’ll use the Python component in Grasshopper to run your script. Here’s how to set it up:
The script needs to be slightly modified to work within Grasshopper’s environment. Grasshopper’s Python component uses the ghpythonlib library and has access to Rhino’s geometry and file system.
pythonimport os import requests import ghpythonlib.components as ghcomp import tomli from pathlib import Path # 1. Inputs (connected to Grasshopper sliders or panels) obj_path = str(obj_path) # Path to OBJ file (input from Grasshopper) toml_path = str(toml_path) # Path to TOML descriptor (input from Grasshopper) api_token = "your_sketchfab_api_token" # Replace with your token # 2. Read the TOML descriptor def load_toml(toml_path): with open(toml_path, "rb") as f: return tomli.load(f) # 3. Upload to Sketchfab def upload_to_sketchfab(obj_path, metadata): url = "https://api.sketchfab.com/v3/models" headers = { "Authorization": f"Token {api_token}", "Content-Type": "multipart/form-data", } files = { "modelFile": open(obj_path, "rb"), } data = { "name": metadata.get("name", Path(obj_path).stem), "description": metadata.get("description", ""), "tags": metadata.get("tags", []), "isPublished": metadata.get("isPublished", False), } response = requests.post(url, headers=headers, files=files, data=data) return response.json() # 4. Main function def main(): descriptor = load_toml(toml_path) model_name = Path(obj_path).stem metadata = descriptor.get(model_name, {}) result = upload_to_sketchfab(obj_path, metadata) return result.get("uid", "Failed") # 5. Output upload_result = main()
Add File Path components:
.obj file and the descriptor.toml file.obj_path and toml_path inputs of the Python component.Add a Panel for Output:
upload_result output to display the Sketchfab model UID or error message.try-except blocks to handle errors (e.g., file not found, API errors).requests and tomli are installed in Rhino’s Python environment.Would you like help setting up the Grasshopper file or troubleshooting the script? Let me know how you’d like to proceed!