|
| 1 | +# FDA-postman-tutorial |
| 2 | +Basic tutorial on how to run a 3ds Max script in Design Automation V3 |
| 3 | + |
| 4 | +## Description |
| 5 | +This tutorial will demonstrate how to use Design Automation V3 to automate the execution of a script on a 3ds Max scene using postman. |
| 6 | +You can use your own script and max scene or the [samples](samples) provided. |
| 7 | + |
| 8 | +## Forge and Postman setup |
| 9 | +### Creating ForgeApp |
| 10 | +Go to the forge website, create a new account if you don't have one and sign in. |
| 11 | +```https://forge.autodesk.com/``` |
| 12 | + |
| 13 | +Once you are logged in, you will be able to create a new forge app. To do so, first mouse over the picture on the top right corner and select "My Apps" or press the "GO TO MY APPS" button |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +Once you reached the "My Apps" page, press the "CREATE APP" button. |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +Once you have reached the "Create App" page. You will need to select the "Data Management API" the "Design Automation API V3" since these are the 2 APIs that will be required for this tutorial. |
| 22 | +Fill the rest of the form and press the "CREATE APP" button. |
| 23 | + |
| 24 | +Note that in certain contexts, your app needs to hand over part of the authentication flow to the Forge Platform. |
| 25 | +For example, in three-legged authentication for a web app, an end user of your app is redirected to an Autodesk login flow, so that the user can tell the platform that your app is authorized to act on the user’s behalf. |
| 26 | +The callback URL is what is passed to the Autodesk login flow to tell it how to redirect the user back to your app. |
| 27 | +However, the tutorial will not require any three-legged authentication so the Callback URL can be any valid url. |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +Once you have pressed the "CREATE APP" button, you should be presented with the App information which contains your app "Client ID" and "Client Secret". |
| 32 | +Make sure to keep these value close since we will need them later in the tutorial. |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +### Postman Installation |
| 37 | +Download and install postman from this url |
| 38 | +```https://www.getpostman.com/downloads/``` |
| 39 | + |
| 40 | +### Postman Collection |
| 41 | +Once postman is installed, launch the application and import the [DAS Tutorial.postman_collection.json](DAS Tutorial.postman_collection.json) by pressing the import button and selecting the collection file. |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +Once the collection is imported you should see it in the side bar to the left. |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +Expand the collection by clicking on the small triangle. You should now see the 15 requests we will be doing during this tutorial. |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +Once you select a request in the side bar, you will see the details of the request appear on the right. |
| 54 | +You can see the verb and url of the request in the top bar and different tabs that will let you browse the headers and body of the different request. |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +## Executing the tutorial |
| 59 | +The tutorial will walk you through making 15 http requests using postman. |
| 60 | +Each request has a number associated with it that indicate the order in which they should be executed for this tutorial. |
| 61 | +If you wish to restart the tutorial or cleanup what have been created during it, the request 14 and 15 are designed to delete everything stored in Design Automation for your forge APP and the storage that was created during the tutorial. |
| 62 | +To send a request you will simply have to press the "Send" button in postman. However, make sure to read the instructions below for each request before sending it since some request might require you to enter some information. |
| 63 | + |
| 64 | +### 1- Authentication |
| 65 | +This request to the Authentication API will obtain a token with the scope require for this tutorial. |
| 66 | +This token will be used by all the subsequent request inside the "Authorization" header to identify your forge app. |
| 67 | +This token will expire after one hour so you might need to execute the request again to get a new token if your expire. |
| 68 | + |
| 69 | +Before executing this request, you will need to enter the forge app client id and client secret that was obtained by following the "Creating ForgeApp" section of this readme.md inside the body of the request. |
| 70 | +Once the request is completed, postman will save the access_token received in the body response inside a variable named "accessToken" to be reused in the subsequent requests. |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +### 2- Create Activity |
| 76 | +This request to the Design Automation V3 API will create an activity. |
| 77 | +In design automation an activity specify an action that can be executed using a specified engine. |
| 78 | +The request body contains the following fields. |
| 79 | + |
| 80 | +##### id |
| 81 | +The id of the activity to be created. This should be unique for a given forge app. |
| 82 | + |
| 83 | +##### commandLine |
| 84 | +This define the command line to be executed. You use variable that will be replaced before executing your command line. The details of these variables can be found here (TODO ADD A LINK TO THE DOC) |
| 85 | + |
| 86 | +##### engine |
| 87 | +This define the processing engine to be installed on the machine that will execute the action. (Auto CAD, Inventor, Revit, 3ds Max) |
| 88 | + |
| 89 | +##### commandLine |
| 90 | +This define the command line to be executed. You use variable that will be replaced before executing your command line. The details of these variables can be found here (TODO ADD A LINK TO THE DOC) |
| 91 | + |
| 92 | +##### parameters |
| 93 | +These define the inputs and outputs that will need to be provided to execute the action defined. |
| 94 | + |
| 95 | +###### InputZip |
| 96 | +For this tutorial we define an input parameter that will be used to downloaded and unzipped a zip file inside a folder name "workingFolder". This input zip will contain a max scene and all it dependencies. |
| 97 | + |
| 98 | +###### MaxFileName |
| 99 | +For this tutorial we define an input string parameter that will be used to provide the name of the 3ds Max file inside the zip file provided by the "InputZip" parameter |
| 100 | + |
| 101 | +###### MaxscriptToExecute |
| 102 | +For this tutorial we define an input parameter that will be used to downloaded a maxscript file that will be named maxscriptToExecute.ms once downloaded. |
| 103 | + |
| 104 | +###### outputZip |
| 105 | +For this tutorial we define an output parameter that will zip the sub-folder named "workingFolder" at the end of the execution and upload it. |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | +### 3- Create Activity Alias |
| 111 | +When submitting an activity to be executed to the Design Automation API V3, we must reference it by it's alias (see request 13). |
| 112 | +An alias is like a tag that point to a particular version of an activity. |
| 113 | +The version an alias point to can be changed in the future as develop more version of a given activity. |
| 114 | +The request number 2 created the version 1 of our activity "executeScript". |
| 115 | +This request will now create an alias named "tutorial" to reference version 1. |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | +### 4- Create OSS bucket |
| 121 | +This request to the Data Management API will create a bucket in the object storage service (OSS) that we will use to store our input zip file, input script file and our resulting zip file. |
| 122 | +The bucket will be created with a random guid and the key to this bucket will be saved inside the "bucketKey" variable for sub-sequent request. |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | +### 5- Upload input zip file to OSS |
| 128 | +This request to the Data Management API will upload the input zip file containing the 3ds Max file to the object storage service (OSS). |
| 129 | +Before sending the request you will need to select the file to be uploaded by pressing the "Choose files" button in the Body tab. |
| 130 | +If you wish to use the [samples](samples) provided in the tutorial, select the [input.zip](samples/input.zip) file. |
| 131 | +Once the request is done, the "objectKey" value from the response body will be automatically saved into a variable named "zipFileObjectKey" that will be used in sub-sequent requests. |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | +### 6- Upload input script to OSS |
| 136 | +This request to the Data Management API will upload the input script file to the object storage service (OSS). |
| 137 | +Before sending the request you will need to select the file to be uploaded by pressing the "Choose files" button in the Body tab. |
| 138 | +If you wish to use the [samples](samples) provided in the tutorial, select the [TwistIt.ms](samples/TwistIt.ms) file. |
| 139 | +This script will simply apply the twist modifier to your entire scene and create an animation from frame 0 to 100. |
| 140 | +Once the request is done, the "objectKey" value from the response body will be automatically saved into a variable named "scriptFileObjectKey" that will be used in sub-sequent requests. |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | +### 7- Get temporary download url for the input zip |
| 146 | +This request to the Data Management API will create a temporary download url for the input zip file we uploaded to the Object Storage Service during request 5. |
| 147 | +We will provide this url to the Design Automation V3 API during request 11 when we send our work item to be executed. |
| 148 | +The design Automation API will use this url to download our zip file before executing the command line we defined inside our activity during request 2. |
| 149 | +Once the request is done, the "signedUrl" value from the response body will be automatically saved into a variable named "zipFileSignedUrl" that will be used in sub-sequent requests. |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | +### 8- Get temporary download url for input script |
| 154 | + |
| 155 | +This request to the Data Management API will create a temporary download url for the script file we uploaded to the Object Storage Service during request 6. |
| 156 | +We will provide this url to the Design Automation V3 API during request 11 when we send our work item to be executed. |
| 157 | +The design Automation API will use this url to download our script file before executing the command line we defined inside our activity during request 2. |
| 158 | +Once the request is done, the "signedUrl" value from the response body will be automatically saved into a variable named "scriptFileSignedUrl" that will be used in sub-sequent requests. |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | + |
| 163 | + ### 9- Get temporary upload url for the output script |
| 164 | + |
| 165 | + This request to the Data Management API will create a temporary upload url to a new object in the Object Storage Service. |
| 166 | + We will provide this url to the Design Automation V3 API during request 11 when we send our work item to be executed. |
| 167 | + The design Automation API will use this url to upload the resulting zip file after executing the command line we defined inside our activity during request 2. |
| 168 | + Once the request is done, the "signedUrl" value from the response body will be automatically saved into a variable named "outputFileSignedUrl" that will be used in sub-sequent requests. |
| 169 | + |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | +### 10- Get forge app nickname |
| 174 | +This request to the Design Automation V3 will request your forge app nickname from the Design Automation API. |
| 175 | +By default this value will always be your forge app client id. We will use this value to reference the activity and alias we created for it during request 11. |
| 176 | +Once the request is done, the body the response body value will be saved automatically inside a variable named "forgeAppNickname". |
| 177 | + |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | +### 11- Send work item |
| 182 | +This request to the Design Automation V3 API will launch the execution of the activity that was created during the request number 2. |
| 183 | +Once the request is done, the id of the work item will be automatically extracted from the body response and saved inside a variable name "workitemId" for sub-sequent requests. |
| 184 | +The body of the request contains the following fields. |
| 185 | + |
| 186 | +##### activityId |
| 187 | +This id identify the activity that we want to execute. The id that refer to the activity alias that was created during request number 3. |
| 188 | +The id is made of 3 parts, first the forge app nickname followed by the '.' character followed by the activity name followed by the '+' character and finally the alias id. |
| 189 | + |
| 190 | +##### arguments |
| 191 | +This section contains all the arguments that need to be passed to the activity selected by the activityId. |
| 192 | +These need to match one for one what we defined as parameters in our activity during request number 2. |
| 193 | + |
| 194 | +###### MaxFileName |
| 195 | +This argument provide the name of the 3ds Max file inside InputZip to load before running the script. |
| 196 | +You should change this value to reflect what is inside you inputZip if you are not using the [samples](samples). |
| 197 | + |
| 198 | +###### InputZip |
| 199 | +This argument provide the signed url we created during request number 7. This url will be used to download the input zip file. |
| 200 | + |
| 201 | +###### MaxscriptToExecute |
| 202 | +This argument provide the signed url we created during request number 8. This url will be used to download the input script file. |
| 203 | + |
| 204 | +###### OutputZip |
| 205 | +This argument provide the signed url we created during request number 9. This url will be used to upload a zip file with the content of the "workingFolder" sub-folder at the end of the execution of the work item. |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | +### 12- Get workitem status |
| 211 | +This request to the Design Automation API V3 will query the status of the work item. |
| 212 | +We can use this request to determine when the work item is done executing. |
| 213 | +However, it is important to note that you can also define an url to be called once the work item is done instead of polling the status from this url. |
| 214 | +This can be done inside the request that submit the work item but this is outside of the scope of this tutorial. (TODO add documentation link) |
| 215 | +The request should be repeated until the status value inside the body pass from "pending" to "inprogress" to "success". |
| 216 | +Once you reached the "success" status it means that your work item has finished executing. |
| 217 | +You can use "reportUrl" value to download the log file of your work item execution if you wish to take a look. |
| 218 | + |
| 219 | + |
| 220 | + |
| 221 | +### 13- Download output from OSS |
| 222 | +This request to the Data Management API will let you download the result zip file that have been uploaded by Design Automation to the Object Storage Service (OSS). |
| 223 | +To save the result back to disk locally, press the download button once the response have been received. |
| 224 | + |
| 225 | + |
| 226 | + |
| 227 | + |
| 228 | +### 14- Delete forge app |
| 229 | +This request to the Design Automation V3 API will delete everything owned by your forge app inside the Design Automation V3 API. |
| 230 | +Be really cautious when using this request if you are using a forge app that already have useful data inside the Design Automation V3 API. |
| 231 | + |
| 232 | + |
| 233 | + |
| 234 | + |
| 235 | +### 15- Delete OSS bucket |
| 236 | +This request to the Data Management API will delete the bucket that was created by request number 4 and every file that it contains. |
| 237 | + |
| 238 | + |
0 commit comments