npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

view-and-data

v2.0.3

Published

The official npm package for Autodesk View and Data API

Downloads

22

Readme

Autodesk View and Data API NPM Package

Description

An NPM package for Autodesk View & Data API.

Setup

  • As usual:

      $ npm install view-and-data
  • Request your own API keys from our developer portal developer.autodesk.com.

  • Replace the credentials placeholders with your own keys in config-view-and-data.js or use ENV variables:

      ConsumerKey: process.env.LMV_CONSUMERKEY || '<replace with your consumer key>',
      ConsumerSecret: process.env.LMV_CONSUMERSECRET || '<replace with your consumer secret>'
  • Set up the default bucket name defined by the defaultBucketKey variable.

  • Copy the file config-view-and-data.js to your server config directory.

Test

This test will upload a sample file (/test/data/test.dwf) and translate, then show the URN.

Make sure to set up your consumer key and secret and the default bucket name in config-view-and-data.js as described above (the test will look for this config file!), Change the bucket name to a bucket you actually own in test/test.js, then run the following commands in the node_modules/view-and-data/ folder:

$ npm install
$ npm test

Usage

Here is a simple example on how to use the library. It will retrieve or create the specified bucket (you will need to modify that value in config-view-and-data.js or provide directly a unique bucket name, see that article for more details). Then it will upload the test.dwf file, monitor it's translation status and get the thumbnail of model if the translation is successful.

      //Make sure config-view-and-data.js is copied at indicated location
      //in your server and that you filed up the API credentials as indicated above

      var config = require('your-server-config/config-view-and-data');
      var Lmv = require('view-and-data');

      var lmv = new Lmv(config);

      //you probably want a more specific error handler...
      function onError(error) {
        console.log(error);
      }

      //wrapper is initialized. Token refreshment will happen automatically
      //no need to worry about it
      function onInitialized(response) {

        var createIfNotExists = true;

        var bucketCreationData = {
          bucketKey: config.defaultBucketKey,
          servicesAllowed: {},
          policy: 'transient' //['temporary', 'transient', 'persistent']
        };

        lmv.getBucket(config.defaultBucketKey,
          createIfNotExists,
          bucketCreationData).then(
            onBucketCreated,
            onError);
      }

      //bucket retrieved or created successfully
      function onBucketCreated(response) {

        //see resumableUpload instead for large files

        lmv.upload(path.join(__dirname, './data/test.dwf'),
          config.defaultBucketKey,
          'test.dwf').then(onUploadCompleted, onError);
      }

      //upload complete
      function onUploadCompleted(response) {

        var fileId = response.objects[0].id;

        urn = lmv.toBase64(fileId);

        lmv.register(urn, true).then(onRegister, onError);
      }

      //registration complete but may have failed
      //need to check result
      function onRegister(response) {

        if (response.Result === "Success") {

          console.log('Translating file...');

          lmv.checkTranslationStatus(
            urn, 1000 * 60 * 5, 1000 * 10,
            progressCallback).then(
              onTranslationCompleted,
              onError);
        }
        else {
          console.log(response);
        }
      }

      //optional translation progress callback
      //may be used to display progress to user
      function progressCallback(progress) {

        console.log(progress);
      }

      //file ready for viewing
      function onTranslationCompleted(response) {

        console.log('URN: ' + response.urn);

        lmv.getThumbnail(urn).then(onThumbnail, onError);
      }

      //thumbnail retrieved successfully
      function onThumbnail(response) {

        //response: base64 encoded thumbnail data
        //ex: var imgsrc = "data:image/png;base64," + response;
        //<img src=imgsrc>
      }

      //start the test
      lmv.initialize().then(onInitialized, onError);

Offline

The package now allows you to download the full viewable package on your disk to run the viewer completely offline. Here is an example that illustrates downloading a model packge from its URN:

    var lmv = new Lmv(config);

    function onError(error) {
      done(error);
    }

    function onInitialized(response) {

      // downloads package to target directory,
      // creates recursively if not exists
      lmv.download(urn, '.test/data/download').then(
        onDataDownloaded,
        onError
      );
    }

    function onDataDownloaded(items) {

      console.log('Model downloaded successfully');

      var path3d = items.filter(function(item){
        return item.type === '3d';
      });

      console.log('3D Viewable path:');
      console.log(path3d);

      var path2d = items.filter(function(item){
        return item.type === '2d';
      });

      console.log('2D Viewable path:');
      console.log(path2d);
    }

    //start the test
    lmv.initialize().then(onInitialized, onError);

To load the model from downloaded package:

  • In your html:

Grab the zip in "lmv" directory and unzip its content in your client lib folder. Then reference style.css and viewer3d.js (or style.min.css/viewer3d.min.js for production).

<link rel="stylesheet" type="text/css" href="lib/lmv-local/version/style.css">
<script src="lib/lmv-local/version/viewer3D.js"></script>
  • In your javascript:

Load an available viewable path obtained as output of the download.

//<div id="viewerContainer"></div> in your html
var viewer = new Autodesk.Viewing.Private.GuiViewer3D(
  document.getElementById('viewerContainer'));

var options = {
  path: viewablePath[0].path,
  env: 'Local'
};

Autodesk.Viewing.Initializer (options, function () {

  viewer.initialize();

  viewer.load(options.path);
});

License

This sample is licensed under the terms of the MIT License. Please see the LICENSE file for full details. The Autodesk Viewer is not under MIT License but copyright by Autodesk, Inc.

Written by

Autodesk Forge, 2016