Reliable way to determine if a tag's text is hardcoded or dynamically generated

I’m looking for tags that have no parameter bindings and are not dynamically updated based on element properties. However, some tags might be linked to parameters but still have hardcoded text that isn’t dynamically updated. My goal is to find tags that do not contain any labels—just hardcoded text.

What I found is that for hardcoded text, IndependentTag.TagText returns an empty string. However, it also returns an empty string for tags that have labels where the parameter for that label has no value.

Questions:

  1. Is there a reliable way to determine if a tag’s text is hardcoded or dynamically generated?
  2. Are there any additional properties or methods I can use to identify hardcoded tags more accurately?
  3. Could there be scenarios where a tag might appear hardcoded but is actually linked to a parameter in a non-obvious way?

Any insights or suggestions would be greatly appreciated!

This is what I have created, but the filtered list contains a mix of tags with hardcoded text and tags whose label parameters do not have any value in the host element’s parameters.

all_tags = FilteredElementCollector(doc).OfClass(IndependentTag)
filtered_tags = [tag for tag in all_tags if not tag.TagText] # We need tags that do not have label and text is hardcoded into them
OUT = filtered_tags

Could you show some tags/parameters in Revit that behave like this? I’m not entirely sure i follow what you mean.

3 Likes

I think the only way to do this is through the FamilyDocument, checking to see if the tag contains any labels or whether it’s just text blocks.

1 Like

This is just an assumption. What I meant is that a tag could have a label along with hardcoded text—for example, instead of a suffix or prefix, just hardcoded text. I believe this is possible, though I’m still investigating whether this scenario exists in the Revit file I am currently checking. My statement was based on that assumption.

Our main intent is to find all tags that have hardcoded text blocks, meaning the tag will display the same value for every object and will not update if we change the element’s parameter, as no label is added to the tag.

I will explore the possibility shared by @Nick_Boyts.

Maybe keep it simple and have like a checkbox in your tag(s)?

But i guess this only works when you prepared (your) Tags in advance.

It’s not about that. I have to audit hundreds of models that were not prepared by my team.
I was seeking an API solution to address this. I have already developed a solution, and it is currently retrieving the hardcoded text tag IDs. I’m just unsure how reliable it will be.
I plan to seek advice from @Nick_Boyts or @c.poupin about the code I’ve prepared. For now, though, it seems to be working.

TransactionManager.Instance.ForceCloseTransaction()

# Function to check if a family contains hardcoded text
def is_family_hardcoded(family):
    """
    Open the annotation family and check if it contains only text blocks.
    """
    family_doc = doc.EditFamily(family)
    is_hardcoded = True

    # Collect all TextElement instances in the family document
    annotations = FilteredElementCollector(family_doc).OfClass(TextElement).ToElements()

    for text_element in annotations:
        if isinstance(text_element, TextElement) and not isinstance(text_element, TextNote):
            is_hardcoded = False  # Family contains a text label
            break

    family_doc.Close(False)  # Close the family without saving changes
    return is_hardcoded


all_tags = FilteredElementCollector(doc).OfClass(IndependentTag).ToElements()
used_tag_families = OrderedDict()

for tag in all_tags:
    family = doc.GetElement(tag.GetTypeId()).Family
    used_tag_families[family.Id] = family

hardcoded_families = OrderedDict()

for family in used_tag_families.values():
    if is_family_hardcoded(family):
        hardcoded_families[family.Id] = family
        

hardcoded_text_tags = []
for tag in all_tags:
    family = doc.GetElement(tag.GetTypeId()).Family
    if family.Id in hardcoded_families:
        hardcoded_text_tags.append(tag)
        

OUT = hardcoded_text_tags
3 Likes