Fix place_family failing to find families/types and accented names on Revit 2026 - #49
Open
thiagokeneth wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two independent bugs made
place_familyunusable on Revit 2026, both inrevit_mcp/utils.py/revit_mcp/placement.py:1.
find_family_symbol_safely— any lookup returned "Family type not found"symbol.Nameis not accessible through the IronPython binding for everyFamilySymbolon Revit 2026 and raisesAttributeError. The whole search loop sat inside one outertry/except, so the first symbol that raised on.Nameaccess aborted the entire search and the function returnedNoneregardless of the actual target —place_familyfailed 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 ofsymbol.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 2strcontaining raw, undecoded UTF-8 bytes rather thanunicode— e.g. "Nível" arrives as the 8 raw bytes that spellN\xc3\xadvelinstead of the single-codepoint unicode stringu"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()toutils.py, which decodes these fields as UTF-8 before they're used for lookups, and applied it tofamily_name,type_name, andlevel_nameinplace_family.Test plan
place_familywithfamily_name="M_Coluna retangular"(ASCII, exists in model) returned 404 before the fix; succeeded after.place_familywithlevel_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_levelswere unaffected by either bug (they already usedget_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