Creating a View Using Glue API

Creating a view using Glue API is possible using model/v1/view_create. That said, defining parameters for an intended view can be a challenge without the user interaction. In this post, I’m going to look at view_create method, focusing purely on the format of parameters.

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

Method: POST

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

A list of parameters required to create a view may need a little bit explanation. The documentation lists parameters that are mixture for creating a view and for a folder. It makes less clear what parameters are needed to create a view. 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 to create a view.

Parameters:

  • model_id – id of the model you are viewing
  • view_object – Navisworks view object. More detail below.
  • view_name – the name for a new view. e.g., “API View”.
  • is_global – the type of view. 1: shared, 0: private (i.e., “My Views”)
  • is_folder – 0: view, 1: folder. This needs to be 0 to create a view.
  • view_display_mode – 0: show in markups, 1: show in views, 2: show is both. In our case, 1.
  • parent_id – (optional) the id of the parent folder. If not specified, a view will be created at the top level.

Format of view_object:

The key parameter we need to pass to create a view is view_object. Unfortunately, Glue API documentation only says “Navisworks view object” and lacks further explanation. So I did a bit of digging.

view_object takes the same format as view_info, which we can get through model/v2/view_info of existing view:

https://b4.autodesk.com/api/model/v2/view_info/doc

For example, if you “snoop” into a response from /model/v2/view_info, you may see like below:

ViewInfo1 and 2

Below is an example of view_object. Note that I’m adding line breaks for readability.

{
  "Type": "AutodeskCommonCamera",
  "Version": 1,
  "Projection": "Perspective",
  "VerticalExtent": 100.0,
  "HorizontalExtent": 100.0,
  "TargetDistance": 100.0,
  "UnitsToMetersScaleFactor": 0.001,
  "WorldUpDirection": [
    0.0,
    0.0,
    1.0
  ],
  "WorldFrontDirection": [
    0.0,
    1.0,
    0.0
  ],
  "WorldRightDirection": [
    1.0,
    0.0,
    0.0
  ],
  "Position": [
    400.0,
    60.0,
    300.0
  ],
  "ViewDirection": [
    -0.58,
    0.58,
    -0.58
  ],
  "UpDirection": [
    -0.41,
    0.41,
    0.82
  ],
  "NearDistance": 0.0,
  "NearDistanceType": "Auto",
  "FarDistance": 0.0,
  "FarDistanceType": "Auto",
  "UpOffset": 0.0,
  "RightOffset": 0.0,
  "ImageFit": "Vertical",
  "HorizontalScale": 1.0,
  "ApertureDiameter": 0.0,
  "ShutterSpeed": 0.0
} 

In case you need a template for view_object, here is a version without line breaks:

{"Type":"AutodeskCommonCamera","Version":1,"Projection":"Perspective","VerticalExtent":100.0,"HorizontalExtent":100.0,"TargetDistance":100.0,"UnitsToMetersScaleFactor":0.001,"WorldUpDirection":[0.0,0.0,1.0],"WorldFrontDirection":[0.0,1.0,0.0],"WorldRightDirection":[1.0,0.0,0.0],"Position":[400.0,60.0,300.0],"ViewDirection":[-0.58,0.58,-0.58],"UpDirection":[-0.41,0.41,0.82],"NearDistance":0.0,"NearDistanceType":"Auto","FarDistance":0.0,"FarDistanceType":"Auto","UpOffset":0.0,"RightOffset":0.0,"ImageFit":"Vertical","HorizontalScale":1.0,"ApertureDiameter":0.0,"ShutterSpeed":0.0}

The image below shows a sample parameter set to create a view at glance (along with other parameter names for model/v1/create_view):

GlueModelViewCreate_createViewParams

Here is a sample image of resulting view:

GlueViews_APIView3

In this example, we are creating a view at the top level. If you want to create a view under a certain folder, specify parent_id. You can use model/v2/view_tree to get a tree structure of folders in Views. Choose a folder (object_id of a folder) of your interest from the tree, and set as a parameter value of parent_id.

In practice, you will probably need to experiment with parameters to get a feel of it. The way your model is defined, such as where the origin is, will be a factor to decide your view point as well.

For more detail about Navisworks view, please refer to Navisworks API documentation about Viewpoint class. You can download SDK, which includes documentation, from Navisworks Developer page: http://www.autodesk.com/developNavisworks

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