Thank you for seeking help! Our friendly community is here to assist you.
To assist you better, please consider providing:
- Objective: I aim to isolate and change element colors based on a filter by property value.
- Issue: The current code I have is exhaustive. I was wondering if there exist a shortcut to achieve the same goal by using the speckle viewer API.
- I was trying to use the getObjectProperties() command but it’s not finding my custom revit param.
// const properties: PropertyInfo[] =
// await SpeckleApp.viewer.getObjectProperties();
// const propertyInfo: PropertyInfo = properties.find((value) => {
// return value.key.includes("MP_Project_Building ID");
// }) as PropertyInfo;
- Example:
public async filterAndIsolateByParameter(
parameterName: string, //"MP_Project_Department"
expectedValue: any
) {
if (!SpeckleApp.viewer) return;
const objectNodes = SpeckleApp.viewer
.getWorldTree()
.findAll((node: TreeNode) => {
if (
!node.model.raw.speckle_type ||
node.model.raw.speckle_type !== "Objects.Other.Revit.RevitInstance"
)
return false;
const paramValues: any = Object.values(node.model.raw.parameters);
const paramFound = paramValues.find((p: any) => {
if (
p !== null &&
typeof p === "object" &&
"name" in p &&
"value" in p &&
p.name === parameterName
) {
return p.value === expectedValue;
}
});
return paramFound;
});
SpeckleApp.viewer
.getExtension(FilteringExtension)
.isolateObjects(objectNodes.map((node: TreeNode) => node.model.id));