Problems with getting the properties of an ID when looping over all Ids

北城以北 提交于 2019-12-11 07:13:19

问题


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/



来源:https://stackoverflow.com/questions/41148239/problems-with-getting-the-properties-of-an-id-when-looping-over-all-ids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!