Hi everyone,
I’m Mathilde and I’m working on a project where I need to program a Speckle viewer.
The programming language I’m using is JavaScript.
My goal is to extract specific information from my models. These pieces of information are not always located in the same place within the model trees (two highlighted examples are shown in the screenshots).
The aim is to retrieve these codes, which are used to identify all the elements in my Speckle viewer.
Later, I want to match them with a reference I’ve selected (for example: 0WSwMjjc57dvDi9Q454zCt).
Then, I want to zoom in on these elements within the viewer.
Right now, I’m unable to search for the elements in my code—my program isn’t working…
I need help!
Thank you so much.
async function searchObjectsInSpeckle(viewer, value, propertyName) {
try {
const foundObjects = [];
const worldTree = await viewer.getWorldTree();
const allObjects = worldTree.getRenderTree();
console.log("All objects in Speckle", allObjects);
const pro = await viewer.getObjectProperties();
console.log("Properties of value", pro);
for (const node of allObjects) {
try {
const properties = await viewer.getObjectProperties(node.model.raw.properties.element.IfcGUID);
console.log("Properties of node", node.id);
if (properties && properties[propertyName] === value) {
foundObjects.push(node.id);
}
} catch (error) {
continue;
}
}
return foundObjects;
} catch (error) {
console.error(`Error searching objects with ${propertyName} = ${value}:`, error);
return [];
}
}
async function selectObjectsInSpeckle(viewer, objectIds) {
try {
const selectionExtension = viewer.getExtension(SelectionExtension);
console.log("Selecting Extension:", selectionExtension);
if (selectionExtension) {
await selectionExtension.selectObjects(objectIds);
console.log("Objects selected in Speckle:", objectIds);
}
} catch (error) {
console.error("Error selecting objects in Speckle:", error);
}
}
async function focusObjectsInSpeckle(viewer, objectIds) {
try {
if (objectIds.length > 0) {
await viewer.isolateObjects(objectIds);
await viewer.zoomToObject(objectIds);
}
} catch (error) {
console.error("Error focusing objects in Speckle:", error);
}
}