0

I am working on platform that links the data between our local databases and the 3d model ( using Autodesk forge bim360 to viewer the models and retrieves the metadata of each obj in the 3d model), all good if the model is .rvt. But, when it comes to IFC files all the methods I was using it fails. I couldn't find anything in the forge docs. I am using the methods below to get all the need data from the Revit Model .rvt

export const findLeafNodes = (model: Autodesk.Viewing.GuiViewer3D | undefined) => {
  if (!model) return;

  return new Promise(function (resolve, reject) {
    model.getObjectTree(function (tree: any) {
      let leaves: number[] = [];
      tree.enumNodeChildren(
        tree.getRootId(),
        function (dbId: any) {
          if (tree.getChildCount(dbId) === 0) {
            leaves.push(dbId);
          }
        },
        true
      );
      resolve(leaves);
    }, reject);
  });
};

export const getProps = (
  model: Autodesk.Viewing.GuiViewer3D,
  ids: number[]
) => {
  if (!model) return;
  return new Promise((resolve, rejects) => {
    try {
      model.model.getBulkProperties2(
        ids,
        {},
        (result) => {
          resolve(result);
        },
        (err) => {
          rejects(err);
        }
      );
    } catch (error) {
      console.log(error);
    }
  });
};
Abed Aarabi
  • 51
  • 1
  • 5

1 Answers1

1

Are you not getting any properties at all? The Viewer APIs should let you query properties from your design no matter whether it's Revit, IFC, DGN, or any other file format. However, keep in mind that each file format will most likely use different properties.

Try opening the following live demo with a sample IFC file: https://aps-simple-viewer-nodejs.autodesk.io/#dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cGV0cmJyb3otc2FtcGxlcy9BQzIwLUluc3RpdHV0ZS1WYXItMi5pZmM, and run the following code snippet in the browser console:

(function () {
    function getLeafNodes(model) {
        return new Promise(function (resolve, reject) {
            const tree = model.getInstanceTree();
            const dbids = [];
            tree.enumNodeChildren(
                tree.getRootId(),
                function (dbId) {
                    if (tree.getChildCount(dbId) === 0) {
                        dbids.push(dbId);
                    }
                },
                true
            );
            resolve(dbids);
        });
    }

    function getProperties(model, dbids) {
        return new Promise(function (resolve, reject) {
            model.getBulkProperties(dbids, {}, resolve, reject);
        });
    }

    getLeafNodes(NOP_VIEWER.model)
        .then(dbids => getProperties(NOP_VIEWER.model, dbids))
        .then(props => console.log(props))
        .catch(err => console.error(err));
})();

This should list a lot of properties from all the leaf elements:

enter image description here

Petr Broz
  • 8,891
  • 2
  • 15
  • 24
  • Hi Petr, I got another question regarding the best performance when I am trying to extract the metadata from a very **LARGE** model. It takes long time, do you have any idea to improve it, I am following the same methods you provided above :) – Abed Aarabi Feb 25 '23 at 12:56
  • Hi Abed, depending on your exact use case, you might want to consider retrieving all the properties "without the viewer": https://aps.autodesk.com/blog/accessing-design-metadata-without-viewer. Or, if your designs are hosted on ACC, you could use the new Model Properties to query specific data directly from the server: https://aps.autodesk.com/en/docs/acc/v1/tutorials/model-properties/. – Petr Broz Feb 27 '23 at 09:27
  • Thanks Petr. I think I won’t publish the entire model in a one viewer template , I will split out. – Abed Aarabi Feb 27 '23 at 13:29