Problems with getting the properties of an ID when

2019-07-31 09:48发布

问题:

I'm interested to get the properties of all dbId elements. For this purpose I'm simply looping over my array of dbIds and use the getProperties function provided by the Forge Viewer.

  someFunction() {

    const instanceTree = this.viewer.model.getData().instanceTree;

    const allDbIds = Object.keys(instanceTree.nodeAccess.dbIdToIndex);

    console.log('all DbIds');
    console.log(allDbIds);

    // This will give the correct Properties
    // this.viewer.getProperties(5, (result) => {
    //   console.log(result)
    // })

    allDbIds.forEach((dbId) => {

      this.viewer.getProperties(dbId, (result) => {
        console.log('result:');
        console.log(result);

      }, (err) => {
        console.log('err');
        console.log(err);
      });
    });
  }

When I access a specific dbId directly I get the correct property array. However when looping over all dbIds and calling the getProperties function only the first two dbIds are returning properties and all the others are only returning empty arrays. Additionally the first two arrays are way to big and seem to contain the other properties. --> Link to console output

Does somebody know what I'm doing wrong here? Thanks already!

回答1:

Instead of iterating properties on the client page, a better approach might be to query all properties at once via the Model Derivative API. See these references:

https://developer.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-metadata-GET/

https://developer.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-metadata-guid-properties-GET/