Reputation: 23
I have a problem with Forge browser using AggregatedView. If I load 3 models in the viewer, in the browser appears label "Model" 3 times, instead of revit file name ("1.rvt", "2.rvt" e "3.rvt"), as reported in the attached imageforge browser. Is it possible to change the behavior (using some options)? I've tried to use "accessControlProperties" option (https://forge.autodesk.com/en/docs/viewer/v2/reference/javascript/document/#load-documentid-onsuccesscallback-onerrorcallback-accesscontrolproperties) but nothing changes.
TIA Alder
function fetchForgeToken( callback ) {
callback( "eyJhbGciOiJSUzI1NiIsImtpZCI6IlU3c0dGRldUTzlBekNhSzBqZURRM2dQZXBURVdWN2VhIn0.eyJzY29wZSI6WyJkYXRhOnJlYWQiLCJkYXRhOmNyZWF0ZSIsImRhdGE6d3JpdGUiLCJ2aWV3YWJsZXM6cmVhZCJdLCJjbGllbnRfaWQiOiJpSGVHMlRrbW9ucmF6TjUyS1JoRUdHWnZFTVU3RWg3dCIsImF1ZCI6Imh0dHBzOi8vYXV0b2Rlc2suY29tL2F1ZC9hand0ZXhwNjAiLCJqdGkiOiJpVEVVZTdYdVRqam9MVzFnNzQyYWNrREtkd244Q3ZLRHZLcXI1NzBrVkk2ZUR6dzRlNDc3N1BkeFNhelRCWWo3IiwiZXhwIjoxNjI3MzAzNjQ0fQ.VNZZHhuo4fGLsy-StB_YLkEtFNphPuuTDCJt-NtAvzGOD8_dsRjj6szBm9-rXNqKIBUVeg3DkYHG3jfSFQeAN_ie76H2_fVs-zmHMelNi6jZBvyM6DGoE62068TvKpEK9_8po__YstQ1JygEuUyiqivXE0-RqYEjd15wNrb1PUqVJTA-Ug4lEEIGmFNyhQsW861MwcRklkcHzhC9gDijQKqcDAqC_udueWZ5Bh48SPtNNJe4bXFwWcWqEipom-apyArd1nLw9-fpmNd-qPgSQJwNo_0sk-wEIn1Zl6Uq8k67f1bBXBrg7XfUAS2-_M_YOTrHZFl6QVEQ-fvKr4PR9g", "2000" );
}
function launchViewer( models ) {
if( !models || models.length <= 0 )
return console.error( 'Empty model input' );
const options = {
env: 'AutodeskProduction',
getAccessToken: fetchForgeToken
};
const options3d = {
viewerConfig: {
disableBimWalkInfoIcon: true
}
};
function loadManifest( documentId, documentName ) {
return new Promise(( resolve, reject ) => {
const onDocumentLoadSuccess = ( doc ) => {
//doc.downloadAecModelData();
doc.downloadAecModelData(() => resolve(doc));
};
console.log("doc.id = " + documentId);
//var accessControlProperties = {name: documentName};
var accessControlProperties = {modelNameOverride: documentName};
//https://forge.autodesk.com/en/docs/viewer/v2/reference/javascript/document/#load-documentid-onsuccesscallback-onerrorcallback-accesscontrolproperties
//oppure
//https://forge.autodesk.com/blog/customizing-model-browser-custom-label-behavior-styling-and-data-sources
Autodesk.Viewing.Document.load( documentId, onDocumentLoadSuccess, reject, accessControlProperties );
});
}
Autodesk.Viewing.Initializer( options, function() {
//get the viewer div
const viewerDiv = document.getElementById( 'viewer' );
//initialize the viewer object
const view = new Autodesk.Viewing.AggregatedView();
view.init( viewerDiv, options3d );
const viewer = view.viewer;
const tasks = [];
models.forEach( md => tasks.push( loadManifest( md.urn, md.name ) ) );
Promise.all(tasks)
.then( docs => Promise.resolve( docs.map( doc => {
const bubbles = doc.getRoot().search({type:'geometry', role: '3d'});
const bubble = bubbles[0];
if( !bubble ) return null;
return bubble;
})))
.then( bubbles => view.setNodes( bubbles ) );
});
}
const models = [
{ name: '1.rvt', urn: 'urn:dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLm5kLXcyZUNSU3ktdHhHTmZ6OWo4bFE/dmVyc2lvbj0x' }, { name: '2.rvt', urn: 'urn:dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLkxHVDFOSW1nUlgtZnN0cnhMZUU5aUE/dmVyc2lvbj0x' }, { name: '3.rvt', urn: 'urn:dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLjhTbE1zOGNWUllTenV1TGR6SXJiWHc/dmVyc2lvbj0x' } ];
launchViewer( models.concat() );
Upvotes: 0
Views: 175
Reputation: 7070
To assign modelNameOverride
, we need to take advantage of getCustomLoadOptions
. See below code snippet for example:
const options3d = {
viewerConfig: {
disableBimWalkInfoIcon: true,
},
getCustomLoadOptions: (bubble) => {
const modelName = bubble.getDocument().getRoot().search({ role: "viewable" })[0].data.name;
console.log(modelName);
let loadOptions = { modelNameOverride: modelName };
return loadOptions;
}
};
view.init( viewerDiv, options3d );
Upvotes: 1