0

I am trying to display 2d file in viewer in Offline mode using pure Javascript. I have already uploaded and extracted dwg using https://extract.autodesk.io/ . Extracted file contains many json.gz files and one folder. In this folder, it has manifest, metadata (json.gz file) and one .f2d file

I have given this file location to my viewer options

var docs = [{ "path": "./{foldername}/primaryGraphics.f2d", "name": "2D view" }];
var options = { 'docid': docs[0].path, env: 'Local' };

And my viewer initialization is

viewer = new Autodesk.Viewing.Private.GuiViewer3D(document.getElementById('MyViewerDiv'), {}); 
Autodesk.Viewing.Initializer(options, function () {
        viewer.initialize();
        viewer.loadModel(options.docid);
});

It is giving me error message in the viewer saying "We cant display the item you are looking for. It may not have been processed yet...." And giving me error code as 5 (Specified type is invalid).

Please help.

Gaurav
  • 122
  • 1
  • 2
  • 11
  • I tried giving the file "path": "http://developer-autodesk.github.io/translated-models/shaver/0.svf" in the options, it shows up in the viewer. But this is a 3d file and mine is 2d. which is extracted as f2d file, and this file format is not supported. Please need help – Gaurav Jun 13 '18 at 08:02

1 Answers1

1

Please make sure that you have completely downloaded all extracted viewable bubbles of your DWG and the path of the model you want to load is correct, since error code 5 stands for NETWORK_FILE_NOT_FOUND.

I just tested this blocks_and_tables_-_metric.dwg from the AutoCAD Sample Files with the below code snippet, and it works fine.

var options = {
    env: 'Local',
};

var doc = { 'rootFolder': 'Model', 'path': '29c9e407-f76f-a1c0-0972-dcb5b496fff9_f2d/primaryGraphics.f2d', 'name': '2D view' };

var viewerDiv = document.getElementById( 'MyViewerDiv' );
var viewer = new Autodesk.Viewing.Private.GuiViewer3D( viewerDiv );


Autodesk.Viewing.Initializer(options, function() {
    if( viewer.initialize() != 0 ) return console.error( 'Failed to initialize viewer' );

    var basePath = getCurrentBaseURL();
    var modelFolderPath = basePath + doc.rootFolder + '/';
    var modelFilePath = modelFolderPath + doc.path;
    var modelOptions = {
        sharedPropertyDbPath: modelFolderPath
    };

    viewer.loadModel( modelFilePath, modelOptions, onLoadModelSuccess, onLoadModelError );
});

function getCurrentBaseURL() {
    var basePath = '';
    var lastSlash = document.location.href.lastIndexOf( '/' );

    if( lastSlash != -1 )
        basePath = document.location.href.substr( 0, lastSlash + 1 );

    return basePath;
}

/**
 * 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 );
}

The file structure of the extracted model of blocks_and_tables_-_metric.dwg is shown below: enter image description here

The file structure of 2D model I used is: enter image description here

Eason Kang
  • 6,155
  • 1
  • 7
  • 24
  • Thank you very much @Eason, I missed to copy manifest.json.gz and metadata.json.gz files in the project folder. Is there any api from where I can get these .json.gz files? I have used https://developer.api.autodesk.com/modelderivative/v2/designdata/:urn/manifest api to get the manifest and this only shows some img files and f2d files. – Gaurav Jun 15 '18 at 09:34
  • Yes, those files are hidden from the Manifest API response, but check this blog showing how to download viewable bubbles via simple progress in Node.js: https://forge.autodesk.com/blog/simple-sample-consumes-process-extracting-svf-package-nodejs – Eason Kang Jun 15 '18 at 09:43