Skip to content

A reusable shared-parameter filter (power pattern)

⚠️ Advanced concept — read, don’t copy

This chapter demonstrates a pattern, not a finished implementation.

The JSONata shown here will be refined in later chapters. Do not copy this directly into production rules.

This chapter is for learning but be aware that the jsonata query here needs to be imporved further!

This filter introduces a generic, reusable way to read shared parameters from Revit elements using their GUIDs.

Once you understand this pattern, you can reuse it for any shared parameter — without rewriting logic.

do not copy this one

(
  /* 1. GUID-map: logical name → GUID */
  $paramGuids := {
    "NLRS_C_bouwwerk_laag": "beca98b3-5207-4cde-a26b-7e9797c4eb26"
  };

  /* 2. Shared parameter helper */
  $getSharedParam := function($object, $logicalName){(
    $guid := $lookup($paramGuids, $logicalName);
    $guid = undefined ? {
      "paramExist": false,
      "value": "Parameter niet aanwezig",
      "guid": null,
      "name": $logicalName
    } :
    (
      $valuesExist := $exists($object.values);
      $paramKey := "p_" & $guid;
      $sp := $valuesExist ? $lookup($object.values, $paramKey) : undefined;

      $present := $exists($sp);

      $hasValue :=
        $present and (
          ($exists($sp.valueAsString) and $sp.valueAsString != "") or
          $exists($sp.value)
        );

      $val :=
        $hasValue
          ? (
              ($exists($sp.valueAsString) and $sp.valueAsString != "")
                ? $sp.valueAsString
                : $sp.value
            )
          : null;

      {
        "paramExist": $present,
        "value": $val,
        "guid":  $guid,
        "name":  $logicalName
      }
    )
  )};

  /* Filter FamilyInstances */
  $[type = "FamilyInstance"].{
    "id": id,
    "type": type,
    "name": name,
    "NLRS_C_bouwwerk_laag": $getSharedParam($, "NLRS_C_bouwwerk_laag")
  }
)

What this filter does (plain language)

“For each FamilyInstance, retrieve the value of one or more shared parameters in a safe, consistent, and reusable way.”

This filter:

  • Does not validate anything yet
  • Does not assume the parameter exists
  • Always returns a predictable structure

Step 1 — the $paramGuids map (your extension point)

$paramGuids := {
  "NLRS_C_bouwwerk_laag": "beca98b3-5207-4cde-a26b-7e9797c4eb26"
};

This object maps:

Logical parameter names → Revit shared parameter GUIDs

Why this matters:

  • GUIDs are unreadable
  • Logical names are human-friendly
  • Rules should not be full of raw GUID strings

This is where users extend the script

To add more shared parameters, you only change this object.

Example:

$paramGuids := {
  "NLRS_C_bouwwerk_laag": "beca98b3-5207-4cde-a26b-7e9797c4eb26",
  "NLRS_C_brandwerendheid": "3a5b8e12-9d2e-4c1f-b8b7-cc02a12e9f88",
  "NLRS_C_fase": "9e6c3a12-4d8a-42d3-a5d2-21a8bfae9981"
};

No other code changes are required.


Step 2 — the helper function $getSharedParam

$getSharedParam := function($object, $logicalName){ ... }

This function:

  • Takes any Revit object
  • Takes a logical parameter name
  • Looks up the GUID
  • Safely retrieves the parameter value
  • Returns a structured result

It handles all edge cases:

  • Parameter not defined in $paramGuids
  • Object has no values
  • Parameter missing on the object
  • Parameter exists but has no value

Why this is a “power script”

Without this helper, rules usually:

  • Hard-code parameter keys
  • Repeat logic
  • Break when parameters are missing
  • Return inconsistent data

With this helper:

  • One implementation
  • Unlimited shared parameters
  • Predictable output
  • Easy review and debugging

This pattern scales across:

  • Rules
  • Categories
  • Projects
  • Standards

Step 3 — using the helper in the filter output

"NLRS_C_bouwwerk_laag": $getSharedParam($, "NLRS_C_bouwwerk_laag")

Key points:

  • $ refers to the current FamilyInstance
  • "NLRS_C_bouwwerk_laag" must match a key in $paramGuids
  • The output is not just a value, but an object:

Example result:

{
  "paramExist": true,
  "value": "00",
  "guid": "beca98b3-5207-4cde-a26b-7e9797c4eb26",
  "name": "NLRS_C_bouwwerk_laag"
}

This structure is ideal for:

  • Validation
  • Error messages
  • Reporting
  • Debugging

You can add multiple parameters to the output without changing the function:

$[type = "FamilyInstance"].{
  "id": id,
  "type": type,
  "name": name,
  "NLRS_C_bouwwerk_laag": $getSharedParam($, "NLRS_C_bouwwerk_laag"),
  "NLRS_C_brandwerendheid": $getSharedParam($, "NLRS_C_brandwerendheid")
}

This turns the filter into a parameter data extractor, not a one-off rule.


Key takeaway

The logic lives in the function. The configuration lives in $paramGuids.

If users remember only one thing from this chapter, it should be this.