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);
}
});
};
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: