0

I have been trying to generate viewer through the autodesk-forge api.I've seen the nodejs demo and even tried with the sample code related to autodesk-forge nodejs.As I am following the documentation somehow i am getting bad request error while uploading *.rvt file after that i came to know that we need to convert the response of uploaded to base64 and pass it with urn:****... after following the procedure i am still getting error while generating the view and i am not able find any help so can anyone elaborate how it can be achieved by sample code.

Here is the Sample Code that i've used :-

var viewer;


var options = {
    env: 'AutodeskProduction',
    getAccessToken: getForgeToken
}

var documentId = 'urn:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cmVhY3QtbGF5b3V0LXNhbXBsZS12aWV3ZXIzN2lleGRiZG5xY2Franplc2JocWNlcTVhc2htNzh2My9VcmJhbkhvdXNlLTIwMTUucnZ0=';

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 viewable = Autodesk.Viewing.Document.getSubItemsWithProperties(doc.getRootItem(), {
        'type': 'geometry',
        'role': '3d'
    }, true);
    if (viewable.length === 0) {
        console.error('Document contains no viewables.');
        return;
    }

    // Choose any of the available viewable
    var initialViewable = viewable[0]; // You can check for other available views in your model,
    var svfUrl = doc.getViewablePath(initialViewable);
    var modelOptions = {
        sharedPropertyDbPath: doc.getPropertyDbPath()
    };

    var viewerDiv = document.getElementById('viewerDiv');


    viewer = new Autodesk.Viewing.Viewer3D(viewerDiv);

    viewer = new Autodesk.Viewing.Private.GuiViewer3D(viewerDiv);

    viewer.start(svfUrl, modelOptions, onLoadModelSuccess, onLoadModelError);
}

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

function onLoadModelSuccess(model) {
    console.log('onLoadModelSuccess()!');
    console.log('Validate model loaded: ' + (viewer.model === model));
    console.log(model);
}

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

function changeBackground (){
    viewer.setBackgroundColor(0, 59, 111, 255,255, 255);
}


function resetBackground (){
       viewer.setBackgroundColor(169,169,169, 255,255, 255);
}

function loadMarkup3D (){
       viewer.loadExtension('Viewing.Extension.Markup3D');
}

function loadTransform (){
       viewer.loadExtension('Viewing.Extension.Transform');
}

function loadControlSelector(){
       viewer.loadExtension('_Viewing.Extension.ControlSelector');
}

Any help will be appreciated i am struck with it need to find way..THanks in advance

  • Can you share a verifiable code example (https://stackoverflow.com/help/mcve)? What is the stacktrace of the error you are seeing? – Sinstein Feb 22 '18 at 10:38
  • Hi I can help you with this. One way will be make sure your URN is correctly encoded. There are a couple of ways to encode your URN, you can either do it directly in your code, or use a site to do the encoding or through terminal. This site is the quickest one I use https://www.base64decode.org/ Also you may want to make sure your 2-legged token have the scope for the viewer which is viewables:read set. let me know which tutorial are you using so I can help you out. – Jaime Rosales Feb 22 '18 at 15:01
  • @JaimeRosales Exactly i tried adding hardcoded URN in the code.I tried putting sample files base64 string but it was no luck.But let me try to encode base64decode.org. I am lil bit confused about 2-legged token and use of it. I am following autodesk-forge's documentation. Le tme try again i'll let you know and correct me i am lefting something.@Sinstein i've edited the post and added the sample code.. Thank you for your response – Third Digital Feb 24 '18 at 14:01
  • Hi, We can try with our new tutorial material, it might help you understand better what 2 legged and also the process of the NodeJS server to take care of the OSS and Translation process. Check http://learnforge.autodesk.io/#/ if that works for you, we can then try to fix this other project, but now I'm thinking maybe you are not passing the values of your keys (client_Id, cliente_secret) correctly so the token gets generated correctly at the time of loading your model. – Jaime Rosales Feb 27 '18 at 19:32

0 Answers0