Reputation: 97
I am using the following JavaScript code to show models in Autodesk Forge Viewer:
var options = {
'document': 'urn:' + urn,
'env': 'AutodeskProduction',
'getAccessToken': getToken,
'refreshToken': getToken
};
Autodesk.Viewing.Initializer(options, function () {
Autodesk.Viewing.Document.load(options.document,
function (doc) { // onSuccessCallback
// load the viewer
},
function (errorCode) { // onErrorCallback
interval = setInterval(function () {
$.ajax({
url: 'https://developer.api.autodesk.com' + '/viewingservice/v1/' + urn,
type: 'GET',
headers: { Authorization: 'Bearer ' + getToken() },
success: function (i) {
switch (i.status) {
case 'success':
// load the viewer
break;
case 'failed':
case 'timeout':
// report error
break;
case 'inprogress':
break;
default:
break;
}
},
error: function (b, d, e) {
// report error
}
});
}, 3000); // Repeatedly request the viewing service for each 3 seconds
}
);
});
onSuccessCallback: it will show the model in the viewer.
onErrorCallback: it will keep posting the viewing service until it get the 'success' status. If the status is 'failed' or 'timeout', it will report back to users that they cannot view this model.
After Autodesk.Viewing.Document.load(options.document), it will jump to errorCode==9 ('There is nothing viewable in the fetched document'). Then I keep request the viewing service to get the result from it. Here is the errorCode list:
var errorCodes = {
1: 'An unknown failure has occurred.',
2: 'Bad data (corrupted or malformed) was encountered.',
3: 'A network failure was encountered.',
4: 'Access was denied to a network resource (HTTP 403)',
5: 'A network resource could not be found (HTTP 404)',
6: 'A server error was returned when accessing a network resource (HTTP 5xx)',
7: 'An unhandled response code was returned when accessing a network resource (HTTP "everything else")',
8: 'Browser error: webGL is not supported by the current browser',
9: 'There is nothing viewable in the fetched document',
10: 'Browser error: webGL is supported, but not enabled',
11: 'There is no geomtry in loaded model',
12: 'Collaboration server error'
};
The problem is sometimes it returns to status=='failed' (in Revit) or status=='timeout' (in Inventor) without more details. It happens to some Revit/Inventor files, not all of the cases.
How can I ask the Forge viewing service to re-translate those files to display back to the web browser. They always get failed from requests to the viewing service. So those files have no chance to show in the Forge viewer.
Upvotes: 1
Views: 2145
Reputation: 8574
First, and very important, you should not be calling translation from the client. That implies your getToken method returns a token with write capabilities, so a malicious user can use it to access and modify your files. Your client should only see the read-only token. Consider use a write token on server and a read token on client (for autodesk-viewer).
Second, you should be using the v2 of autodesk-model-derivative API with the JOB endpoint, where the MANIFEST endpoint will provide you a full description of the translation (either in progress or completed/failed). The previous v1 view&data API was divided into Viewer (client) and Model Derivative API (server), which give us better control of the server-side translation, including several new capabilities.
Upvotes: 1