Important!
The 3D print API is shutting down on January 15, 2017. See our end of life notice for more information.
Repair a Mesh¶a>
This tutorial describes a typical workflow of print preparation endpoints; from importing a mesh, analyzing it, and repairing it, to slicing it and generating a printable file that you can submit to a 3D printer.
Note that the print preparation endpoints in this tutorial are asynchronous and initiate tasks that run in the background, rather than halting execution of your program. The response returns a task id
that you need to use to call the GET tasks/:id endpoint, which retreives the new object. For further details, see the GET tasks/:id endpoint.
See our open source interactive Repair sample app to experiment with a working example of this tutorial. You can follow each stage of the workflow on a console locatated below the sample UI. To access the open source sample code, see https://github.com/spark3dp/forge-webapp-samples.
Before You Begin¶
- Register an app and acquire an OAuth token.
- Upload a file to the Forge Object Storage Service (OSS), as described in the file upload tutorial.
Step 1: Import a Mesh¶
Select a file that you uploaded to OSS, and convert it into a Forge mesh using the POST meshes/import endpoint.
Request¶
Replace the Authorization
bearer token with your token, the file_id
parameter with the file’s URN, and the name
parameter with the name of the file.
curl -v 'https://developer.api.autodesk.com/ps/v1/geom/meshes/import'
-X 'POST'
-H 'Authorization: Bearer WmzXZq9MATYyfrnOFpYOE75sL5dh'
-H 'Content-Type: application/json'
-d '
{
"file_id": "urn:adsk.objects:os.object:testprintbucket/stlfile.stl",
"name": "frog"
}
'
Response¶
The endpoint returns a task id
that you need to use to call the GET tasks/:id endpoint.
{
"id": "697d7d42-c0ae-42d3-b570-e621cad15fa1",
"progress": 0.189,
"status": "running",
"task_update_time": "2016-05-15T08:23:33.134Z"
}
Request¶
Call the GET tasks/:id endpoint iteratively, passing the task id
parameter, until the task is complete (i.e., when the status
is done
).
curl -v 'https://developer.api.autodesk.com/ps/v1/print/tasks/697d7d42-c0ae-42d3-b570-e621cad15fa1'
-X 'GET'
-H 'Authorization: Bearer WmzXZq9MATYyfrnOFpYOE75sL5dh'
The example shows the response of a completed task.
The result
object in the response contains the mesh object with details about the imported mesh.
{
"id": "697d7d42-c0ae-42d3-b570-e621cad15fa1",
"progress": 1,
"status": "done",
"task_update_time": "2015-03-19T22:51:51.725Z",
"result": {
"id": "533c4fdf-fd2f-4a31-a644-f5a89c8534d3",
"name": "frog",
"geom": {
"bounding_box": {
"max": [
15.000805854797363,
11.30075454711914,
0.9872254729270935
],
"min": [
-15.00112152099609,
-11.301037788391113,
-0.9879794716835022
]
},
"has_uvs": false,
"num_triangles": 7192,
"num_vertices": 3594
},
"transform": [
[
1,
0,
0,
0
],
[
0,
1,
0,
0
],
[
0,
0,
1,
0
]
],
"analyzed": false,
"visual_file_id": 17711849
}
}
Step 2: Analyze the Mesh¶
Check whether the model has any faults (holes, duplicate triangles, degenerate triangles, etc.) by calling the POST meshes/analyze endpoint.
Note that the response returns a task id
that you need to use to call the GET tasks/:id endpoint. See Step 1 for more details. When the task is complete, the GET tasks/:id endpoint returns the mesh object with details about the analyzed mesh.
POST meshes/analyze Request¶
curl -v 'https://developer.api.autodesk.com/ps/v1/geom/meshes/analyze'
-X 'POST'
-H 'Authorization: Bearer pLETl872BI4xnnVsk0DH4pgfpnYp'
-H 'Content-Type: application/json'
-d '
{
"id": "8f7ef44b-d4ef-41c8-8ded-a0c9d0999e55"
}
'
GET tasks/:id Response¶
The example shows the response of a completed task.
The result
object in the response contains the mesh object with details about the imported mesh.
{
"id": "d21e0d6a-2ce4-43bc-a1e3-ce1bb8fdb7e2",
"progress": 1,
"status": "done",
"task_update_time": "2015-03-18T16:57:52.755Z",
"result": {
"id": "8f7ef44b-d4ef-41c8-8ded-a0c9d0999e55",
"name": "image_damaged",
"geom": {
"num_vertices": 10046,
"num_triangles": 20081,
"has_uvs": false
},
"transform": [
[
1,
0,
0,
0
],
[
0,
1,
0,
0
],
[
0,
0,
1,
3
]
],
"analyzed": true,
"problems": [
{
"triangles": [
{
"v0": [
5.918893814086914,
33.73568344116211,
9.202703475952148
],
"v1": [
5.848534107208252,
33.87462615966797,
9.152109146118164
],
"v2": [
5.913722991943359,
33.85252380371094,
9.214763641357422
]
}
],
"type": "duplicate_triangles"
}
]
}
}
Step 3: Repair the Mesh¶
If defects were detected you can fix them using the POST meshes/repair endpoint. The types of defects that are fixed include:
- holes: an incomplete mesh surface
- degenerate triangles: triangles with zero area
- duplicate triangles: triangles with the same vertices
- non-manifold vertices: a vertex adjacent to more than two untwinned edges, or a vertex adjacent to more than two triangles at the same edge
- inconsistently oriented triangles: a triangle edge adjacent to another triangle with the opposite orientation
Note that the response returns a task id
that you need to use to call the GET tasks/:id endpoint. See Step 1 for more details. When the task is complete, the GET tasks/:id endpoint returns the mesh object with details about the repaired mesh.
POST meshes/repair Request¶
curl -v 'https://developer.api.autodesk.com/ps/v1/geom/meshes/repair'
-X 'POST'
-H 'Authorization: Bearer 076wXnfCIWrUjUDHV5lHDk9K0thE'
-H 'Content-Type: application/json'
-d '
{
"id": "92624c41-7501-477a-bf22-87578d7fdf82",
"all": true
}
'
GET tasks/:id Response¶
The example shows the response of a completed task.
The result
object in the response contains the mesh object with details about the repaired mesh.
{
"id": "d21e0d6a-2ce4-43bc-a1e3-ce1bb8fdb7e2",
"progress": 1,
"status": "done",
"task_update_time": "2015-03-18T16:57:52.755Z",
"result": {
"id": "8f7ef44b-d4ef-41c8-8ded-a0c9d0999e55",
"name": "image_damaged",
"geom": {
"num_vertices": 10046,
"num_triangles": 20081,
"has_uvs": false
},
"transform": [
[
1,
0,
0,
0
],
[
0,
1,
0,
0
],
[
0,
0,
1,
3
]
],
"analyzed": true,
"problems": []
}
}
Step 4: Create a Tray¶
Before generating a printable file for the repaired mesh, you need to call the POST trays endpoint to create a tray (build platform) for the specific printer and printer profile you intend to use to print the 3D model.
Note that the response returns a task id
that you need to use to call the GET tasks/:id endpoint. See Step 1 for more details. When the task is complete, the GET tasks/:id endpoint returns the tray object with details about the created tray.
POST trays Request¶
curl -v 'https://developer.api.autodesk.com/ps/v1/print/trays'
-X 'POST'
-H 'Authorization: Bearer pLETl872BI4xnnVsk0DH4pgfpnYp'
-H 'Content-Type: application/json'
-d '
{
"printer_type_id": "7FAF097F-DB2E-45DC-9395-A30210E789AA",
"profile_id": "34F0E39A-9389-42BA-AB5A-4F2CD59C98E4",
"mesh_ids": [
"8f7ef44b-d4ef-41c8-8ded-a0c9d0999e55"
]
}
'
GET tasks/:id Response¶
The example shows the response of a completed task.
The result
object in the response contains the tray object with details about the created tray.
{
"id": "f7dc02e6-cc5d-43c3-8ad0-3ad8cfe55c46",
"progress": 1,
"status": "done",
"task_update_time": "2015-03-22T14:55:42.154Z",
"result": {
"id": "c88a02c2-4868-4a6e-b7af-793ae23c76ff",
"printer_type_id": "7FAF097F-DB2E-45DC-9395-A30210E789AA",
"settings": {
"support_angle_tol": 1.3,
"layer_height": 0.0020,
"burn_in_layers": 3
},
"meshes": [
{
"id": "19f38eb7-4cb5-429c-8e25-0e440f8bfd2b",
"name": "mage_damaged",
"geom": {
"num_vertices": 10046,
"num_triangles": 20080,
"has_uvs": false,
"bounding_box": {
"max": [
12.562538146972656,
56.06819534301758,
16.380802154541016
],
"min": [
-16.40504264831543,
-0.0002610000083222985,
-13.500799179077148
]
}
},
"transform": [
[
1,
0,
0,
0
],
[
0,
1,
0,
0
],
[
0,
0,
1,
0
]
],
"analyzed": true,
"problems": []
}
],
"mesh_attrs": {
"19f38eb7-4cb5-429c-8e25-0e440f8bfd2b": {
"reposition": true,
"reorient": true,
"support": true
}
},
"state": "created",
"ready": false,
"default_material_id": "426F14FE-E6AF-496F-BBC7-7D6C0E16861D"
}
}
Step 5: Prepare the Tray¶
The POST trays/prepare endpoint slices the mesh, enables you to orient the position of the mesh on the tray, and creates supports for it.
Note that the response returns a task id
that you need to use to call the GET tasks/:id endpoint. See Step 1 for more details. When the task is complete, the GET tasks/:id endpoint returns the tray object with details about the prepared tray.
POST trays/prepare Request¶
curl -v 'https://developer.api.autodesk.com/ps/v1/print/trays/prepare'
-X 'POST'
-H 'Authorization: Bearer pLETl872BI4xnnVsk0DH4pgfpnYp'
-H 'Content-Type: application/json'
-d '
{
"id": "f7dc02e6-cc5d-43c3-8ad0-3ad8cfe55c46"
}
'
GET tasks/:id Response¶
The example shows the response of a completed task.
The result
object in the response contains the “tray” entity with details about the prepared tray.
{
"id": "f7dc02e6-cc5d-43c3-8ad0-3ad8cfe55c46",
"progress": 1,
"status": "done",
"task_update_time": "2015-03-22T14:55:42.154Z",
"result": {
"id": "c88a02c2-4868-4a6e-b7af-793ae23c76ff",
"printer_type_id": "7FAF097F-DB2E-45DC-9395-A30210E789AA",
"settings": {
"support_angle_tol": 1.3,
"layer_height": 0.0020,
"burn_in_layers": 3
},
"meshes": [
{
"id": "19f38eb7-4cb5-429c-8e25-0e440f8bfd2b",
"name": "mage_damaged",
"geom": {
"num_vertices": 10046,
"num_triangles": 20080,
"has_uvs": false,
"bounding_box": {
"max": [
12.562538146972656,
56.06819534301758,
16.380802154541016
],
"min": [
-16.40504264831543,
-0.0002610000083222985,
-13.500799179077148
]
}
},
"transform": [
[
1,
0,
0,
0
],
[
0,
1,
0,
0
],
[
0,
0,
1,
0
]
],
"analyzed": true,
"problems": []
}
],
"mesh_attrs": {
"19f38eb7-4cb5-429c-8e25-0e440f8bfd2b": {
"reposition": true,
"reorient": true,
"support": true
}
},
"state": "supported",
"ready": true,
"default_material_id": "426F14FE-E6AF-496F-BBC7-7D6C0E16861D"
}
}
Step 6: Generate a Printable File¶
The POST trays/generate-printable endpoint generates a printable file from the tray for either FDM (G-code file) or DLP (ZIP or image files) printers. See the GET buckets/:bucketKey/objects/:objectName endpoint for information about downloading the file.
Note that the response returns a task id
that you need to use to call the GET tasks/:id endpoint. See Step 1 for more details. When the task is complete, the GET tasks/:id endpoint returns the file_id
for the printable file.
POST trays/generate-printable Request¶
curl -v 'https://developer.api.autodesk.com/ps/v1/print/trays/generatePrintable'
-X 'POST'
-H 'Authorization: Bearer pLETl872BI4xnnVsk0DH4pgfpnYp'
-H 'Content-Type: application/json'
-d '
{
"id": "19f38eb7-4cb5-429c-8e25-0e440f8bfd2b"
}
'
GET tasks/:id Response¶
The example shows the response of a completed task.
The result
object in the response contains the file_id
to be used in the GET buckets/:bucketKey/objects/:objectName endpoint.
{
"id": "16eeb4db-30dc-4964-9ef9-b676e115610e",
"progress": 1,
"status": "done",
"task_update_time": "2016-05-16T14:17:33.560Z",
"result": {
"file_id": "urn:adsk.objects:os.object:print-services-external/b1996dd1-4b7f-44d8-9040-01615530073c.tar.gz"
}
}