Ahasanul
Ahasanul

Reputation: 35

How can i get the list of link files from a translated compressed/zip of revit file?

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!

Upvotes: 0

Views: 548

Answers (1)

Eason Kang
Eason Kang

Reputation: 7070

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~

Upvotes: 1

Related Questions