Search code examples
autodesk-viewerautodesk-model-derivative

How to exclude 2d sheets from translation


We are using Model Derivative API to translate Revit models for viewing in the Viewer3d. We have models which have 2d sheets, and if we have those, a panel opens up on the left side of the viewer. Is it possible to parametrise the request for translation to skip these sheets? Or as an alternative solution is it possible to make the viewer ignore everything but the 3d?

We are using a json like this for the request currently:

{
  "input": {"urn": "someurn"},
  "output": {
    "destination": {"region": "us"},
    "formats": [{"type": "svf","views":["3d"]}]
  }
}

We are using version 2.10 of the Viewer API.


Solution

  • The 2D views appear because you are using the A360 viewing application - I know that's what the official points out but we are going to update that - below is the vanilla code using the viewer API directly, it will only display the viewable path that you select programmatically:

    /////////////////////////////////////////////////////////////////
    // Initialization Options
    //
    /////////////////////////////////////////////////////////////////
    var initOptions = {
      documentId: urn,
      env: 'AutodeskProduction',
      getAccessToken: function( onGetAccessToken) {
        return token;
      }
    }
    /////////////////////////////////////////////////////////////////
    // Document Loaded Handler
    //
    /////////////////////////////////////////////////////////////////
    function onDocumentLoaded (doc) {
      var rootItem = doc.getRootItem()
      // Grab all 3D items
      var geometryItems3d =
        Autodesk.Viewing.Document.getSubItemsWithProperties(
          rootItem, { 'type': 'geometry', 'role': '3d' }, true)
      // Grab all 2D items
      var geometryItems2d =
          Autodesk.Viewing.Document.getSubItemsWithProperties(
          rootItem, { 'type': 'geometry', 'role': '2d' }, true)
      // Pick the first 3D item otherwise first 2D item
      var selectedItem = (geometryItems3d.length ?
              geometryItems3d[0] :
              geometryItems2d[0])
      var domContainer = document.getElementById('viewer')
      // UI-less Version: viewer without controls and commands
      //viewer = new Autodesk.Viewing.Viewer3D(domContainer)
      // GUI Version: viewer with controls
      var viewer = new Autodesk.Viewing.Private.GuiViewer3D(domContainer)
      viewer.initialize()
      viewer.loadModel(doc.getViewablePath(selectedItem))
    }
    /////////////////////////////////////////////////////////////////
    // Environment Initialized Handler
    //
    /////////////////////////////////////////////////////////////////
    function onEnvInitialized () {
      Autodesk.Viewing.Document.load(
        initOptions.documentId,
        function(doc) {
          onDocumentLoaded (doc)
        },
        function (errCode){
          onLoadError (errCode)
        })
    }
    /////////////////////////////////////////////////////////////////
    // Error Handler
    //
    /////////////////////////////////////////////////////////////////
    function onLoadError (errCode) {
      console.log('Error loading document: ' + errCode)
    }
    /////////////////////////////////////////////////////////////////
    // Bootstraping
    //
    /////////////////////////////////////////////////////////////////
    Autodesk.Viewing.Initializer(
      initOptions,
      function() {
        onEnvInitialized ()
      })
    

    You can check that demo for the complete code, there is also an example using viewing application similar to the API doc.

    Now, why you still get the 2d views when you only request 3d is another question I need to check with the dev team... Note that exported views can be selected manually from revit through an addin