0

I have translated a revit file with several link files. From viewer i can browse all elements from the root revit model including all elements from link files using 'Model Browser' default extension. Even i also created a custom extension from where i can isolate each object type's all elements.

Now, i want to create a extension like 'Model Browser', which will show Root file name as top or parent node and all link file's name as child node.I also want, by clicking each link file, all elements from that link file should isolate in the viewer and by clicking Root file, all elements including all link files elements should show .

For information, my application is built using C# and JavaScript in .Net platform.

Can anyone advice me which api, i can try? It would be also very helpful if someone share examples or url where i can get help.

Thanks in advance!

Ahasanul
  • 35
  • 2

1 Answers1

1

You can take advantage of the AecModelData to get linked models data and rebuild relationships from the PropertyDB inside Forge Viewer.

If an object is from the linked RVT, you can check its' external id. If the external id contains a slash symbol, then this means it is from a linked RVT. Here is an example:

  • Object extetnal id: ffa0b0a8-8aab-48f9-beb5-dba5d9b4968f-0010cfee/e021b7a9-1e57-428c-87db-8e087322cd49-0015a0f6
  • An instanceId from the linkedDocuments in the AECModelData: ffa0b0a8-8aab-48f9-beb5-dba5d9b4968f-0010cfee

You can see the GUID on the left side of the slash symbol matches the instance id mentioned above.

enter image description here

To get the linked RVT model name, we can reuse the instanceId from the linkedDocuments of the AECModelData to get the information we need again. Here is a code snippet for you, and assume the instance id is ffa0b0a8-8aab-48f9-beb5-dba5d9b4968f-0010cfee:

function getExternalIdMappingAsync( model ) {
    return new Promise( ( resolve, reject ) => {
        model.getExternalIdMapping(
            map => resolve( map ),
            error => reject( error )
        );
    });
}

function getPropertiesAsync( dbId, viewer ) {
    return new Promise( ( resolve, reject ) => {
        viewer.getProperties(
            dbId,
            result => resolve( result ),
            error => reject( error )
        );
    });
}

//1.  Get external id mapping for converting external id to Viewer's dbId
let externalIdMapping = await getExternalIdMappingAsync( viewer.model );
let dbId = externalIdMapping['ffa0b0a8-8aab-48f9-beb5-dba5d9b4968f-0010cfee'];

//2. Get properties of the linked model instance
let propResult = await getPropertiesAsync( dbId, viewer )

//3. Find the type name property for its value
let linkNameProp = propResult.properties.find( prop => prop.displayName == 'Type Name' || prop.attributeName == 'Type Name' );
let linkName = linkNameProp.displayValue; //!<<< This is linked RVT name

Here is the snapshot of my test:

enter image description here

Hope it helps~

Eason Kang
  • 6,155
  • 1
  • 7
  • 24
  • Hi Eason Kang, thanks for your detail answer! Seems like it will work. Let us try to implement it. I will come back here again. – Ahasanul Nov 05 '20 at 07:54
  • Hello Eason Kang, we implemented and it is working perfect for almost all models, except for one model,we are struggling with performance which have many link files(35+) and size is very big(7GB+). In that model,extension i made following your steps is very slow.To get rid of that we changed our strategy a bit.In the main model and all of it's link models we added a project level parameter where we filled model name and using that parameter through extension i listed all those link files and can switch on/off model data and gained performance a lot but still not that much.Anyways,thanks again. – Ahasanul Dec 11 '20 at 16:07
  • Hi Ahasanul, thank you for letting me know. To improve the performance, you can take advantage of the [web worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) to rebuild the tree in the separated thread or query AecModelData & properties in your backend. Here is an example demonstrating how to query properties without loading the model with the viewer: https://github.com/cyrillef/propertyServer – Eason Kang Dec 16 '20 at 08:31