Skip to content

Fix place_family failing to find families/types and accented names on Revit 2026 - #49

Open
thiagokeneth wants to merge 2 commits into
mcp-servers-for-revit:masterfrom
thiagokeneth:fix/place-family-name-attribute-error
Open

Fix place_family failing to find families/types and accented names on Revit 2026#49
thiagokeneth wants to merge 2 commits into
mcp-servers-for-revit:masterfrom
thiagokeneth:fix/place-family-name-attribute-error

Conversation

@thiagokeneth

@thiagokeneth thiagokeneth commented Aug 13, 2026

Copy link
Copy Markdown

Summary

Two independent bugs made place_family unusable on Revit 2026, both in revit_mcp/utils.py / revit_mcp/placement.py:

1. find_family_symbol_safely — any lookup returned "Family type not found"

symbol.Name is not accessible through the IronPython binding for every FamilySymbol on Revit 2026 and raises AttributeError. The whole search loop sat inside one outer try/except, so the first symbol that raised on .Name access aborted the entire search and the function returned None regardless of the actual target — place_family failed for every family, even ones that exist.

Fix: use the existing get_element_name() helper (already used elsewhere in this file, e.g. list_families, for the same reason) instead of symbol.Name, and guard each symbol individually so one bad symbol is skipped instead of failing the whole lookup.

2. Accented family/type/level names never matched

Separately, even after fix #1, any family, type, or level name containing non-ASCII characters (e.g. level_name="Nível 1") still failed with "not found", while ASCII-only names worked fine.

Root cause: incoming JSON string values (family_name, type_name, level_name) arrive at the Routes handler as Python 2 str containing raw, undecoded UTF-8 bytes rather than unicode — e.g. "Nível" arrives as the 8 raw bytes that spell N\xc3\xadvel instead of the single-codepoint unicode string u"N\xedvel". ASCII bytes are valid UTF-8 already (hence why ASCII-only names were unaffected), but comparing this raw-byte string against Revit's own element names (always proper unicode from the API) never matches.

Confirmed via a temporary debug route dumping repr() and per-character codepoints of both the incoming value and the real Revit level name: the incoming value's codepoints were exactly the UTF-8 byte sequence of the intended text (195, 173 for "í") rather than its single Unicode codepoint (237) — an un-decoded byte string, not an encoding mismatch on the Revit side.

Fix: added fix_request_string() to utils.py, which decodes these fields as UTF-8 before they're used for lookups, and applied it to family_name, type_name, and level_name in place_family.

Test plan

  • Reproduced both bugs on a real Revit 2026 project via the actual MCP → Routes → Revit round trip (not just in-process scripting).
  • Bug 1: place_family with family_name="M_Coluna retangular" (ASCII, exists in model) returned 404 before the fix; succeeded after.
  • Bug 2: place_family with level_name="Nível 1" (exists in model) returned 404 "Level not found" even after fix 1; succeeded after fix 2, placing and then removing a test column instance to confirm.
  • list_families / list_levels were unaffected by either bug (they already used get_element_name() and don't do incoming-string comparisons the same way), so this doesn't change behavior elsewhere in the extension.

🤖 Generated with Claude Code

find_family_symbol_safely() accessed symbol.Name directly, but on
Revit 2026 FamilySymbol.Name is not accessible through the IronPython
binding for every symbol and raises AttributeError. Since the whole
loop was wrapped in a single try/except, the first bad symbol hit
while iterating the collector aborted the entire search, so
place_family (and its "Family type not found" error) fired
regardless of whether the requested family/type actually existed.

Switch to the existing get_element_name() helper (already used
elsewhere in this file for the same reason) and guard each symbol
individually so one bad symbol is skipped instead of failing the
whole lookup.
Incoming JSON string values (family_name, type_name, level_name) arrive
at the Routes handler as Python 2 str containing raw, undecoded UTF-8
bytes rather than unicode -- e.g. "Nível" arrives as the 8 raw bytes
that spell "N\xc3\xadvel" instead of the single-codepoint unicode
string u"N\xedvel". ASCII-only values are unaffected (ASCII bytes are
valid UTF-8 already), which is why only accented/non-ASCII names failed
to match against Revit's own element names (always proper unicode from
the API) -- e.g. place_family with level_name="Nível 1" returned
"Level not found" even though the level exists.

Add fix_request_string() to decode these fields as UTF-8 before using
them for lookups.

Confirmed root cause via a temporary debug route that dumped repr()
and per-character codepoints of both the incoming value and the
Revit-side name -- the incoming value's codepoints were exactly the
UTF-8 byte sequence of the intended text (195, 173 for "í") rather than
its single Unicode codepoint (237), confirming an un-decoded byte
string rather than e.g. an encoding mismatch on the Revit side.
@thiagokeneth thiagokeneth changed the title Fix place_family failing to find any family on Revit 2026 Fix place_family failing to find families/types and accented names on Revit 2026 Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant