Viewer API query nodes base on revit custom parameter value

Thank you for seeking help! Our friendly community is here to assist you. :folded_hands:

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

Hi @Miguel_Gutierrez

Your approach looks very legit at least from the viewer API point of view. Maybe the properties do not get sent over from the host application?

Can provide us with an example stream so we can have a closer look?

Cheers

1 Like