Fabien
Fabien

Reputation: 41

How to set model.getDocumentNode when loading multiple documents?

I load multiple models from multiple converted revit files in the viewer. In each of these models I put points associated to selected element. To be able to reuse these points later, I need:

  1. Which revit document it was taken from -> models[x].myData.urn : ok
  2. Which view (model) from revit document it was taken from -> model.getDocumentNode returns null (which is not the case when I load a single model with viewerApp). This leads node.model.getDocumentNode().data.guid which is guid of the view to be not reachable. ko
  3. Dbid -> present in selection event: ok
  4. Guid -> I build a 2 ways mapping table (dbid<->guid) to get what I need : ok (open to more straightforward ways, but ok)

Main issue is the 2nd point, How to set model.getDocumentNode when loading multiple models in the viewer?

Thank you,

Upvotes: 0

Views: 447

Answers (1)

Petr Broz
Petr Broz

Reputation: 9942

You could collect the document URN and the model GUID during the loading process:

function load(urn) {
    viewerApp.loadDocument(
        'urn:' + urn,
        function onDocumentLoadSuccess(doc) {
            const viewables = viewerApp.bubble.search({ 'type': 'geometry' });
            if (viewables.length > 0) {
                const path = doc.getViewablePath(viewables[0].data);
                const viewer = viewerApp.getCurrentViewer();
                const options = { /* your options */ };
                viewer.loadModel(path, options, function onModelLoadSuccess(model) {
                    model._myURN = urn;
                    model._myGUID = viewables[0].data.guid;
                });
            }
        }
    );
}

Upvotes: 1

Related Questions