Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
148 views
in Technique[技术] by (71.8m points)

Object selection in forge viewer

I have created the sample application for forge viewer.

I am able to view the Revit and navisworks files in forge viewer.

I want to select an item from the viewer by passing inputs to viewer.bubble.search method.

I am using the same coding from the url: https://forge.autodesk.com/en/docs/viewer/v7/reference/Viewing/BubbleNode/

I am using the below code. Please help.

var viewer;
 var urn1;
 var accestoken1;
 var jsdata;

 function uploadfile(file) {
     document.getElementById('<%=UploadBtn.ClientID%>').click();
 }

 function showModel(urn) {
     var options = {
         env: 'AutodeskProduction',
         getAccessToken: getForgeToken
     };

     Autodesk.Viewing.Initializer(options, () => {
         viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('forgeViewer'), { extensions: ['Autodesk.DocumentBrowser'] });
         viewer.start();
         var documentId = 'urn:' + urn;
         urn1 = urn;
         Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
        // viewer.fitToView([270005], viewer.model);
        // viewer.select([270005]);
     });

 }

 function myFunction1() {
     setTimeout(function () {
         myFunction2();
     }, 500);
 }


 function onDocumentLoadSuccess(doc) {                 
     var viewables = viewer.bubble.search({ type: 'geometry', role: '3d', name: 'DOMW PIPE' });

     if (viewables.length === 0) {
         console.error('Document contains no viewables.');
         return;
     }
 }

 function onDocumentLoadFailure(viewerErrorCode) {
     console.error('onDocumentLoadFailure() - errorCode:' + viewerErrorCode);
 }

 function getForgeToken(callback) {
     fetch('/api/forge/oauth/token').then(res => {
         res.json().then(data => {
             callback(data.access_token, data.expires_in);
             accestoken1 = data.access_token;
         });
     });
 }

with thanks and regards.

Castro Nelson

question from:https://stackoverflow.com/questions/65931468/object-selection-in-forge-viewer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you'd like to make it possible to choose which of the 2D or 3D views (that the Model Derivative service extracted from your original design) to load in the viewer, consider using the built-in viewer extension called Autodesk.DocumentBrowser. The extension will add a new UI to the viewer that can be used to switch between the different 2D/3D views quite easily.

You can experiment with the extension on https://forge-extensions.autodesk.io: enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...