.. _3diax-makeprintable:
Partner Integrations: MakePrintable on 3DIAX
==================================================
3DIAX is designed to work with 3rd party services. One of our earliest partners is `Makeprintable `_. Go ahead and check them out, I'll wait.
.. image:: images/wait.gif
I'm glad you're back. `Makeprintable `_ takes 3D models and repairs any deficiencies in them to make them printable. Appropriate name, isn't it? Makeprintable works with 3DIAX and here's how we'll do it:
1 - Create an account on Makeprintable
2 - Create an API key on Makeprintable for use with 3DIAX
3 - Upload a model to 3DIAX
4 - Send the model through 3DIAX to Makeprintable
5 - Print!
Create an account with MakePrintable
------------------------------------
Creating an account with [Makeprintable](makeprintable.com) is pretty easy. Head over to `Makeprintable `_ and ask for an invitation. `Let's us know when you sign up `_ and we can speed up the process to get a username and password set up.
Create an API key on Makeprintable for use with 3DIAX
-----------------------------------------------------
We don't control the Makeprintable website, but I'll show you the steps for now. They may change at any time, so don't completely trust the images.
Head to `Makeprintable login `_. Login.
Click on 'Settings' that drops down from the menu with your name.
.. image:: images/makeprintable-settings.png
Then click on 'API keys'
.. image:: images/makeprintable-api-keys.png
From here you'll upload a model to 3DIAX
----------------------------------------
Uploading a model to 3DIAX is easy. You can see the :ref:`3diax-tutorial` for information on how to upload a model. Let's assume for the sake of this tutorial that you have uploaded a model and the URI for the model is https://data.authentise.com/model/aa186279-0d33-4369-9839-629bb90ceec7/.
I've actually uploaded a model there that you can use to follow along. It looks like this:
.. image:: images/logo-damaged.png
This model has a few simple errors that makes it renderable, but not printable. We're going to send it to `Makeprintable `_ to be repaired.
Send the model through 3DIAX to Makeprintable
---------------------------------------------
Now we're ready to send our model to `Makeprintable `_. We'll need to send a request to 3DIAX to do so on our behalf. It looks like this:
.. sourcecode:: javascript
POST https://data.authentise.com/model/aa186279-0d33-4369-9839-629bb90ceec7/transformations/
Content-Type: application/json
{
"type" : "makeprintable",
"parametersMakePrintable" : {
"name" : "my-repaired-file",
"wall_thickness" : 1,
"print_quality" : 'standard',
"pre_optimize" : 0,
"post_optimize" : 0,
"api_key" : "your-api-key",
}
}
The parameters above are Makeprintable-specific. You can see `their API docc `_ for information on what each parameter means. The request will respond with a ``Location`` header which will be the URL for a new model resource that was created. This model resource will get populated by makeprintable when your repair is complete.
In my case we have a ``Location`` header of https://data.authentise.com/model/c697f696-422e-4bf5-8fb1-52fe4c6d35c8/. You can immediately GET that resource to see the status of the repair:
.. sourcecode:: javascript
GET https://data.authentise.com/model/c697f696-422e-4bf5-8fb1-52fe4c6d35c8/
Content-Type: application/json
{
"analyses' : {"manifold': null},
"callback_method' : null,
"callback_url' : null,
"children' : [],
"content' : null,
"created' : "2015-07-10T22:42:55.032051',
"name' : "logo-damaged.stl',
"parents' : ["https://data.authentise.com/model/aa186279-0d33-4369-9839-629bb90ceec7/'],
"size' : {"x': null, "y': null, "z': null},
"snapshot' : null,
"status' : "not-uploaded',
"updated' : "2015-07-10T22:42:55.032051',
"upload-location' : "...",
}
This tells me that the fixed file is not yet uploaded so we don't know much about except the parent model that was used to generate it. We wait a bit and poll again and we'll see something more like this:
.. sourcecode:: javascript
GET https://data.authentise.com/model/c697f696-422e-4bf5-8fb1-52fe4c6d35c8/
Content-Type: application/json
{
"analyses" : {"manifold": true},
"callback_method" : null,
"callback_url" : null,
"children" : [],
"content" : "https://prod-hoth-data.s3.amazonaws.com:443/...",
"created" : "2015-07-10T22:42:55.032051",
"name" : "my-repaired-file",
"parents" : ["https://data.authentise.com/model/aa186279-0d33-4369-9839-629bb90ceec7/"],
"size": {
"x": 6.65513,
"y": 6.94019,
"z": 6.66039
},
"snapshot" : "https://data.authentise.com/model/f40b13dc-1254-45bc-9b64-af80198dac99/snapshot/77705565-bf1b-4987-8029-6a3f142ea85a/",
"status" : "processed",
"updated" : "2015-07-10T22:44:02.306002",
"upload-location" : null,
}
Here we see that the new file has been supplied to 3DIAX and is a proper manifold file (unlike our previous file). It has the name we provided it and we've calculated some dimensions and produced a snapshot. Here it is:
.. image:: images/logo-repaired.png
As you can see `Makeprintable `_ has repaired the gaping hole in my model as well as some other items that you couldn't see in our damaged logo.
.. image:: images/excited.gif
The code that I used to do this is below in Python, but it works just as well in any language you like since it's all just HTTP requests.
.. sourcecode:: python
#!/usr/bin/env python
import argparse
import pprint
import requests
import time
def _send_file_via_3diax(session, model_uri, api_key):
url = model_uri + "/transformation/"
payload = {
"transformations" : [{
'type' : 'makeprintable',
'parametersMakePrintable' : {
'name' : 'fixed-logo',
'wall_thickness' : 1,
'print_quality' : 'standard',
'pre_optimize' : 0,
'post_optimize' : 0,
'api_key' : api_key,
}
}]
}
response = session.post(url, json=payload)
assert response.status_code == 201, "Failed to send model: {}".format(response.content)
new_model = response.headers['Location']
status = None
while status != 'processed':
response = session.get(new_model)
assert response.status_code == 200
pprint.pprint(response.json())
print('-'*30)
time.sleep(2)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('model_uri', help='The model URI to use')
parser.add_argument('username', help='The username for DIAX')
parser.add_argument('password', help='The password for DIAX')
parser.add_argument('api_key', help='The api key for makeprintable')
args = parser.parse_args()
session = requests.Session()
payload = {
'username' : args.username,
'password' : args.password,
}
response = session.post('https://users.authentise.com/sessions/', json=payload)
assert response.status_code == 201, "Login failed: {}".format(response.content)
_send_file_via_3diax(session, args.model_uri, args.api_key)
if __name__ == '__main__':
main()