Unlocking the Power of Autodesk Model Derivatives API: Can You Use it with Models Stored in Your Own Database?
Image by Tate - hkhazo.biz.id

Unlocking the Power of Autodesk Model Derivatives API: Can You Use it with Models Stored in Your Own Database?

Posted on

If you’re an avid user of Autodesk’s software, you’re likely familiar with the Model Derivatives API. This powerful tool allows you to extract and manipulate 2D and 3D models, converting them into various formats for easier collaboration and analysis. But what if you want to take your model derivatives to the next level by storing them in your own database? Can you still use the Autodesk Model Derivatives API to unlock its full potential?

The Short Answer: Yes, You Can!

In this comprehensive guide, we’ll explore the ins and outs of using the Autodesk Model Derivatives API with models stored in your own database. We’ll delve into the benefits, requirements, and step-by-step instructions to get you started.

Benefits of Using Autodesk Model Derivatives API with Your Own Database

So, why would you want to store your models in your own database and use the Autodesk Model Derivatives API? Here are just a few compelling reasons:

  • Faster Performance**: By storing your models in your own database, you can reduce latency and improve performance, as you’re not dependent on Autodesk’s cloud-based storage.
  • Enhanced Security**: With your own database, you have full control over access and security, ensuring your sensitive models and data are protected.
  • Customization and Flexibility**: You can tailor your database to meet your specific needs, integrating the Autodesk Model Derivatives API in a way that suits your workflow.

Requirements for Using Autodesk Model Derivatives API with Your Own Database

Before diving into the setup process, make sure you meet the following requirements:

  1. Autodesk Account**: You need an active Autodesk account with a valid API key.
  2. Model Derivatives API Subscription**: Ensure you have a subscription to the Autodesk Model Derivatives API.
  3. compatible Database**: Your database must support the storage of 2D and 3D models in various formats (e.g., OBJ, STL, DWG).
  4. Programming Skills**: Familiarity with programming languages like Python, JavaScript, or C# is necessary for integrating the API.

Step-by-Step Instructions for Using Autodesk Model Derivatives API with Your Own Database

Now that you’ve met the requirements, let’s get hands-on:

Step 1: Set up Your Database

Create a new database or use an existing one that meets the requirements. For this example, we’ll use a PostgreSQL database.

CREATE TABLE models (
  id SERIAL PRIMARY KEY,
  name VARCHAR(50) NOT NULL,
  file BYTEA NOT NULL,
  format VARCHAR(10) NOT NULL
);

Step 2: Obtain an Autodesk API Key

Log in to your Autodesk account and navigate to the Autodesk Developer Portal. Create a new API key or use an existing one, making sure it’s enabled for the Model Derivatives API.

Step 3: Install the Autodesk API Client Library

Choose your preferred programming language and install the corresponding Autodesk API client library. For this example, we’ll use Python:

pip install autodesk-api

Step 4: Upload Models to Your Database

Use your preferred method to upload your 2D and 3D models to your database. For this example, we’ll use Python and the psycopg2 library:

import psycopg2

conn = psycopg2.connect(
  host="your_host",
  database="your_database",
  user="your_username",
  password="your_password"
)

cur = conn.cursor()

with open('model.obj', 'rb') as f:
  cur.execute("INSERT INTO models (name, file, format) VALUES (%s, %s, %s)", ('My Model', f.read(), 'obj'))

conn.commit()
cur.close()
conn.close()

Step 5: Authenticate with the Autodesk API

Use your API key to authenticate with the Autodesk API:

from autodesk.api import Client

client = Client()
client.authentication.authenticate_by_client_id('your_api_key')

Step 6: Use the Model Derivatives API with Your Database

Now it’s time to extract derivatives from your models stored in your database. For this example, we’ll extract a 2D thumbnail from a 3D model:

from autodesk.api.derivatives import DerivativesApi

derivatives_api = DerivativesApi(client)

model_id = 1  # Replace with the ID of your model in the database
model_format = 'obj'

# Get the model from your database
cur.execute("SELECT file FROM models WHERE id = %s", (model_id,))
model_data = cur.fetchone()[0]

# Create a new derivative
derivative_input = {
  'input': {
    'urn': f"urn:adsk.objects:os.object:{model_id}::{model_format}"
  },
  'output': {
    'formats': [
      {
        'type': 'thumbnail',
        'width': 256,
        'height': 256
      }
    ]
  }
}

response = derivatives_api.create_derivative(derivative_input)
derivative_id = response.urn

# Download the derivative
derivative_data = derivatives_api.get_derivative(derivative_id).body

# Store the derivative in your database
cur.execute("INSERT INTO derivatives (model_id, format, file) VALUES (%s, %s, %s)", (model_id, 'png', derivative_data))
conn.commit()
cur.close()
conn.close()

Conclusion

In this comprehensive guide, we’ve demonstrated how to use the Autodesk Model Derivatives API with models stored in your own database. By following these steps, you can unlock the full potential of the API, enjoying faster performance, enhanced security, and customization.

Remember to explore the Autodesk Model Derivatives API documentation for more information on its capabilities and limitations. Happy coding!

Keyword Summary
Autodesk Model Derivatives API A powerful tool for extracting and manipulating 2D and 3D models.
Models stored in own database Storing models in your own database offers faster performance, enhanced security, and customization.

Note: The code snippets provided are for illustration purposes only and may require modifications to work with your specific database and setup.Here are the 5 Questions and Answers about using Autodesk Model Derivatives API with models stored in your own database:

Frequently Asked Question

Got questions about using Autodesk Model Derivatives API with your own database? We’ve got answers!

Can I use Autodesk Model Derivatives API with my own database?

Yes, you can use Autodesk Model Derivatives API with your own database. The API allows you to upload and manage your own models, and then access them programmatically. You can store your models in your own database and then use the API to generate derivatives, such as 2D and 3D thumbnails, STEP files, and more.

Do I need to store my models in Autodesk’s cloud storage to use the Model Derivatives API?

No, you don’t need to store your models in Autodesk’s cloud storage to use the Model Derivatives API. You can store your models in your own database or file system, and then use the API to upload and manage them programmatically.

How do I authenticate with the Model Derivatives API when using my own database?

You can authenticate with the Model Derivatives API using an authentication token, which you can obtain through Autodesk’s authentication service. You’ll need to register your application and obtain a client ID and client secret, and then use these credentials to obtain an access token.

Can I use the Model Derivatives API with multiple databases or file systems?

Yes, you can use the Model Derivatives API with multiple databases or file systems. The API is designed to be flexible and scalable, so you can use it with multiple data sources and storage systems.

What are the benefits of using the Model Derivatives API with my own database?

Using the Model Derivatives API with your own database gives you more control over your data and models, and allows you to integrate the API with your existing workflows and systems. You can also use the API to automate tasks and workflows, and to generate derivatives on demand.