Skip to content

gitgreencoder/workflow-node.js-view.and.data.api

Repository files navigation

Autodesk View and Data API Node.js Basic Sample

Description

A sample demonstrating how to view a model in a web application with the Autodesk View & Data API. This web application has a basic Node.js server and JavaScript/HTML5 client. This sample does not demonstrate how to upload a model to the Autodesk server for translation.

Dependencies

Install Node.js on your machine and clone this repo. Download the project dependencies using npm before running the app by running the following command

npm install

on the node.js console. This will install the following node.js modules in the project:

  • express
  • request
  • serve-favicon

This sample does not include the workflow of uploading models. It depends on other workflow samples to upload models and get model URNs - as explained in the Setup/Usage Instructions.

Setup/Usage Instructions

Use your own credentials to upload models to your account

  • Apply for your own credentials (API keys) from http://developer.autodesk.com
  • Replace the placeholder with your own keys in credentials.js, line #23 and #25
    credentials.ClientId = '<replace with clientId>';
    
    credentials.ClientSecret = '<replace with clientSecret>';
    
  • Upload one of your models to your account and get its URN using another workflow sample, for example,
  • Copy this URN in /www/views/index.js at line #18
    var urnprod = 'your_urn_here';
    
  • Run the server from the Node.js console, by running the following command:
    node server.js
    
  • Connect to you local server using a WebGL-compatible browser: http://localhost:3000/

This sample can also work with the Autodesk staging server (vs production) or work with someone else's credentials as long you can get a valid token. By default, the project is setup with the production server, and use your own credentials. If you are interested by a different setup, see the Options below.

Options

You can work with production or staging Autodesk View and Data environments. By default, the project is setup with the production server.

Option A: Production server option: Use upload tool online service to upload model.

  • The upload tool provides some existing models. Choose any one of them, or upload one of your own models with upload tool. The upload tool will generate a URN of the model that you need later.
  • Copy this URN in /www/views/index.js at line #18
    var urnprod = 'your_urn_here';
    
  • In /www/views/index.js, at line #36, change value of tokenurl to the access token you can generate from 'http://still-spire-1606.herokuapp.com/api/rawtoken'
  • Run the server from the Node.js console, by running the following command:
    node server.js
    
  • Connect to your local server using a WebGL-compatible browser: http://localhost:3000/

Option B: To work with the staging environment, you need to use your own credentials vs the option above.

  • Apply your own credentials from http://developer-stg.autodesk.com
  • Replace the place holder with your own keys in credentials-stg.js, line #23 and #25
    credentials.ClientId = '<replace with clientId>';
    
    credentials.ClientSecret = '<replace with clientSecret>';
    
  • Upload one of your models to your account and get its URN using another workflow sample, for example,
  • Copy this URN in /www/views/index.js at line #19
    var urnstg = 'your_urn_here';
    
  • In /www/views/index.js, around line #24, make sure the variable staging is true.
  • In /www/views/index.html (line $33 and #34), use viewer3D.min.js and style.css from the staging environment
    <link type="text/css" rel="stylesheet" href="https://developer-stg.api.autodesk.com/viewingservice/v1/viewers/style.css"/>
    
    <script src="https://developer-stg.api.autodesk.com/viewingservice/v1/viewers/viewer3D.min.js"></script>
    
  • Run the server from the Node.js console, by running the following command:
    node server.js
    
  • Connect to you local server using a WebGL-compatible browser: http://localhost:3000/

License

That samples are licensed under the terms of the MIT License. Please see the LICENSE file for full details.

Written by

Written by Philippe Leefsma

About

A demo with the usage of viewer client in Node.JS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 82.0%
  • HTML 18.0%