DVS
DVS

Reputation: 1

Autodesk Forge, DOMException from viewer3D.min.js

I have tried to follow the Autodesk Forge Tutorials, to make a Basic Viewer. (see myCoolViewer.html below)

When I open that html file in Chrome, I see the following error in Chrome's console:

image: error in chrome console

The rvt file referenced in the html was previously successfully loaded into a bucket using

developer.api.autodesk.com/oss/v2/buckets/MyCoolBucket/objects/rac_basic_sample_project.rvt

and was translated into SVF format using

developer.api.autodesk.com/modelderivative/v2/designdata/job

as verified by

developer.api.autodesk.com/modelderivative/v2/designdata/the-source-URN,-Base64-encoded/manifest

I would appreciate any troubleshooting steps !

<head>
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=no" />
    <meta charset="utf-8">

    <!-- The Viewer CSS -->
    <link rel="stylesheet" href="https://developer.api.autodesk.com/viewingservice/v1/viewers/style.min.css" type="text/css">

    <!-- Developer CSS -->
    <style>
        body {
            margin: 0;
        }
        #MyViewerDiv {
            width: 100%;
            height: 100%;
            margin: 0;
            background-color: #F0F8FF;
        }
    </style>
</head>
<body>

    <!-- The Viewer will be instantiated here -->
    <div id="MyViewerDiv"></div>

    <!-- The Viewer JS -->
    <script src="https://developer.api.autodesk.com/viewingservice/v1/viewers/three.min.js"></script>
    <script src="https://developer.api.autodesk.com/viewingservice/v1/viewers/viewer3D.min.js"></script>

    <!-- Developer JS -->
    <script>
        var viewer;
        var options = {
            env: 'AutodeskProduction',
            accessToken: 'eyJhbGciOiJIUzI1NiIsImtpZCI6Imp3dF9zeW1tZXRyaWNfa2V5In0.eyJjbGllbnRfaWQiOiJCTlgxNHZZeWFPM0xyQ3JNVXBrYlJZMmVTUGMyaHhpWCIsImV4cCI6MTQ5NzkwNTQ4Miwic2NvcGUiOlsiZGF0YTpyZWFkIiwiZGF0YTp3cml0ZSIsImJ1Y2tldDpjcmVhdGUiLCJidWNrZXQ6cmVhZCJdLCJhdWQiOiJodHRwczovL2F1dG9kZXNrLmNvbS9hdWQvand0ZXhwNjAiLCJqdGkiOiI2Nzd4b2o3T3dick1FaVQ5RjIwOFc3VGdhcTRYckpoWlI1dkl1c1FMVll6R3ZrRVdJSm5QYzlYaGgxRUpzQWtVIn0.PF19xEsEb8EcD99bmoLYu83kOCEPpOm6huxyQfHOr-w' 
        };
        var documentId = 'urn:adsk.objects:os.object:b01_a/rac_basic_sample_project.rvt'; 
        Autodesk.Viewing.Initializer(options, function onInitialized(){
            Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
        });

        /**
        * Autodesk.Viewing.Document.load() success callback.
        * Proceeds with model initialization.
        */
        function onDocumentLoadSuccess(doc) {

            // A document contains references to 3D and 2D viewables.
            var viewables = Autodesk.Viewing.Document.getSubItemsWithProperties(doc.getRootItem(), {'type':'geometry'}, true);
            if (viewables.length === 0) {
                console.error('Document contains no viewables.');
                return;
            }

            // Choose any of the avialble viewables
            var initialViewable = viewables[0];
            var svfUrl = doc.getViewablePath(initialViewable);
            var modelOptions = {
                sharedPropertyDbPath: doc.getPropertyDbPath()
            };

            var viewerDiv = document.getElementById('MyViewerDiv');
            viewer = new Autodesk.Viewing.Private.GuiViewer3D(viewerDiv);
            viewer.start(svfUrl, modelOptions, onLoadModelSuccess, onLoadModelError);
        }

        /**
         * Autodesk.Viewing.Document.load() failuire callback.
         */
        function onDocumentLoadFailure(viewerErrorCode) {
            console.error('onDocumentLoadFailure() - errorCode:' + viewerErrorCode);
        }

        /**
         * viewer.loadModel() success callback.
         * Invoked after the model's SVF has been initially loaded.
         * It may trigger before any geometry has been downloaded and displayed on-screen.
         */
        function onLoadModelSuccess(model) {
            console.log('onLoadModelSuccess()!');
            console.log('Validate model loaded: ' + (viewer.model === model));
            console.log(model);
        }

        /**
         * viewer.loadModel() failure callback.
         * Invoked when there's an error fetching the SVF file.
         */
        function onLoadModelError(viewerErrorCode) {
            console.error('onLoadModelError() - errorCode:' + viewerErrorCode);
        }

    </script>
</body>

Upvotes: 0

Views: 421

Answers (2)

Felipe
Felipe

Reputation: 4375

As Eason mentioned it, documentId needs to be base64-encoded and preceded by urn:, eg. "urn:dxgsjsksk......."

Upvotes: 0

Eason Kang
Eason Kang

Reputation: 7070

It seems that your documentId is not proper for the Forge, the documentId should be a base64 encoded string of the ObjectKey of your uploaded rvt file like this:

Base64URN

For more detail via here.

Could you do me a favor to replace your documentId with the the-source-URN,-Base64-encoded in your JavaScript code?

Hope this help.

Upvotes: 0

Related Questions