Adding a Folder to Views Using Glue API

Here is a question my colleague asked:

Q. Is it possible to create a folder to Views using Glue API?

A. If you look at the list of methods in the documentation, you don’t see a method name that says “create folder” explicitly. But you can use the following Model Services API to create a folder:

URL: https://b4.autodesk.com/api/model/v1/view_create.{format}

Method: POST

Document: https://b4.autodesk.com/api/model/v1/view_create/doc

The documentation lists parameters that are mixture for creating a view and for a folder. It may make less obvious what parameters are needed to create a folder. But once you know this is the right call, it is not too difficult to figure it out. In addition to the parameters common to all REST calls (i.e., the first six, up to “sig” in the documentation), you will need the following parameters to create a folder.

Parameters:

  • model_id – id of the model you are viewing
  • view_name – the name of the new folder. E.g., “API Folder”.
  • is_global – the type of folder. 1: shared, 0: private (i.e. “My Views”).
  • is_folder – 0: view, 1: folder. Must be 1 in our case as we want to create a folder.
  • parent_id – (optional) the id of the parent folder. If you do not specify, it will create a folder at the top level.

As an example, you may use the following workflow to create a folder to Views:

  1. project/v1/list – to get a list of project. Choose a project (project_id)
  2. model/v1/list – to get a list of models (which could be merged or component model). Choose a model (model_id)
  3. model/v2/view_tree – (optional) to get a tree structure of folders and models under Views. Choose a folder (object_id of a folder). This will be a parent_id for view_create for the next step. If you are creating a top level folder, you can omit this step.
  4. model/v1/view_create – to create a folder.

The image below shows an example of response from model/v2/view_tree (step 3 above). If you want to add a folder under the existing folder, you can pass object_id of a folder as a parameter value of parent_id in mode/v1/view_create (step 4 above).

GlueViewsTree

Here is a sample parameter set to create a folder under an existing folder (along with other parameter names to create a view):

GlueModelViewCreateParams

On success, the response may look like this:

{
“view_id”:”98fcdfo0-ea60-d3s6-8475-fdsa24f90eff”,
“view_name”:”API Folder 4″,
“created_date”:”2016-05-03 22:24:59″,
“action_id”:””
}

(Note: line breaks are added for readability.)

The sample image of the result in UI is shown below.  (Note: if you had UI opened when you modified through API, you will need to reload the project to see the result in UI.)

GlueViewsFolder

Mikako

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s