Autodesk.Viewing.Document
new Document(dataJSON,path,acmsession)
Core model data class for all items and collections.
It allows the client to load the model data from the cloud, it gives access to the root and provides a method for finding elements by id.
Typically, you load the document from the Viewing Service, parse it for the required content (for example, 3d geometries), then pass this on to the viewer to display. You can also get some information about the document, such as the number of views it contains and its thumbnail image.
You can view the JSON structure of a Document object by requesting it from the Model Derivative endpoints.
Parameters
| dataJSON* object | JSON data representing the document. |
| path* string | Path to the document. |
| acmsession* string | ACM session ID. |
Methods
getFullPath(urn)
Returns the full path to the given URN.
Parameters
| urn* string | URN of the document. |
Returns
| Type | Description |
|---|---|
| string |
getItemById(id)
Returns an item from the model data hierarchy with the given id. If the item is not found, null object is returned.
Parameters
| id* string | ID of the item to be found. |
Returns
| Type | Description |
|---|---|
| object | Item with a given ID. |
getMessages(itemId,excludeGlobal)
Returns messages (error and warning messages) associated with a given item. It includes item’s messages as well as messages of all its parents.
Parameters
| itemId* string | GUID of the item. |
| excludeGlobal* boolean | If true, the top messages that apply to the whole file are excluded. |
Returns
| Type | Description |
|---|---|
| object | Returns an array of messages. |
getNumViews(item)
Returns the number of view items underneath a geometry item.
Parameters
| item* object | Geometry item. |
Returns
| Type | Description |
|---|---|
| number | The number of view items underneath the geometry item. |
getParentId(item)
Parameters
| item* string | The node ID. |
Returns
| Type | Description |
|---|---|
| string |
getPath()
Returns the id of this document.
Returns
| Type | Description |
|---|---|
| string | ID of the document |
getPropertyDbPath()
Returns the root path to a shared (across all sheets/views) property database’s JSON files.
Returns
| Type | Description |
|---|---|
| string | The root path to a shared property database’s JSON files |
getRoot()
Returns a BubbleNode instance, encapsulating the current document manifest JSON
Returns
| Type | Description |
|---|---|
| BubbleNode | Returns a BubbleNode instance, encapsulating the current document manifest JSON |
getRootItem()
Returns the root of the model data hierarchy
Returns
| Type | Description |
|---|---|
| object | The root of the model data hierarchy |
getSubItemsWithProperties(item,properties,recursive)
Static method that returns an array of all items with given properties.
Parameters
| item* object | The document node to begin searching from. |
| properties* object | map/list of the properties to search for. |
| recursive* boolean | If true, searches recursively. |
Returns
| Type | Description |
|---|---|
| object | List of items that have given properties. |
Examples
// search the document starting from the root element for all 2d geometry items
geometryItems = Document.getSubItemsWithProperties(adocument.getRootItem(), {
'type' : 'geometry',
'role' : '2d'
}, true);
getThumbnailOptions(item,width,height)
Returns a plain object with properties used to fetch a thumbnail image.
Parameters
| item* object | |
| width* number | |
| height* number |
Returns
| Type | Description |
|---|---|
| object | {urn: string, width: number, height: number, guid: string, acmsession: (string
)} |
getThumbnailPath(item,width,height)
Returns the path to the thumbnail of the item with the given ID.
Parameters
| item* string | Document item. |
| width* int | The requested thumbnail width. |
| height* int | The requested thumbnail height. |
Returns
| Type | Description |
|---|---|
| string |
getViewableItems(document)
Parameters
| document* |
getViewablePath(item,outLoadOptions)
Returns the path to the viewable of the given item.
Parameters
| item* object | The item whose viewable is requested. |
| outLoadOptions* object | Output param: used to store some additional loader options. Needed to extract leaflet params from a bubble item. |
Returns
| Type | Description |
|---|---|
| string |
getViewGeometry(item)
Returns the parent geometry item for a given view item.
Parameters
| item* object | View item. |
Returns
| Type | Description |
|---|---|
| object | The parent geometry item. |
load(documentId,onSuccessCallback,onErrorCallback,accessControlProperties)
Static method to load the model data from the cloud.
Parameters
| documentId* string | The cloud URN of the file. |
| onSuccessCallback* function | A function that is called when load succeeds. |
| onErrorCallback* function | A function that is called when load fails. |
| accessControlProperties* object | An optional list of key value pairs as access control properties, which includes a list of access control header name and values, and an OAuth 2.0 access token. |
Examples
// Load the model from the cloud
var urn = 'dXJuOmFkc2suczM6ZGVyaXZlZC5maWxlOnRyYW5zbGF0aW9uXzI1X3Rlc3RpbmcvRFdGL0Nhci5kd2Y=';
var seedFile = "https://viewing-dev.api.autodesk.com/derivativeservice/v2/" + urn;
var jsonData = "";
Autodesk.Document.load( seedFile, function( doc ) { jsonData=doc }, function( ) { } );
var model = new Autodesk.Document(jsonData, 'path');
var root = model.getRootItem(); // top item of the hierarchy of the model data
var item = model.getItemById( "XXX02UUEs");
var path = model.getFullPath(); // should be 'path'
requestThumbnailWithSecurity(data,onComplete)
This function is only used when Authorization is through Bearer token; aka when cookies are disabled.
Parameters
| data* string | See getThumbnailOptions. |
| onComplete* function | Node style callback function
callback(err, response). |