Skip to content

Enhance font replacement functionality in Revit families#2723

Merged
jmcouffin merged 5 commits intodevelopfrom
fix/replace-fonts-improvment
Jul 2, 2025
Merged

Enhance font replacement functionality in Revit families#2723
jmcouffin merged 5 commits intodevelopfrom
fix/replace-fonts-improvment

Conversation

@jmcouffin
Copy link
Copy Markdown
Contributor

@jmcouffin jmcouffin commented Jul 2, 2025

Description

  • Added regex support for case-insensitive font name replacement.
  • Implemented recursive updates for nested generic annotation families.
  • Improved error handling and logging during font updates.
  • Updated main script logic to handle font replacement in both family and project documents.

thanks to https://discourse.pyrevitlabs.io/u/denver-22 🚀


Checklist

Before submitting your pull request, ensure the following requirements are met:

  • Code follows the PEP 8 style guide.
  • Code has been formatted with Black using the command:
  • Changes are tested and verified to work as expected.

Related Issues

https://discourse.pyrevitlabs.io/t/font-replacement-suggested-changes/9216

- Added regex support for case-insensitive font name replacement.
- Implemented recursive updates for nested generic annotation families.
- Improved error handling and logging during font updates.
- Updated main script logic to handle font replacement in both family and project documents.
@jmcouffin jmcouffin added the Tools Issues related to pyRevit commands [subsystem] label Jul 2, 2025
@jmcouffin jmcouffin requested a review from Copilot July 2, 2025 07:47
Copy link
Copy Markdown
Contributor

@devloai devloai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary:

This PR enhances the font replacement functionality by adding:
• Regex support for case-insensitive font name replacement
• Recursive updates for nested generic annotation families
• Improved error handling and logging during font updates
• Support for both family and project document font replacement workflows

Review Summary:

I've identified several critical issues that need to be addressed before merging. The main concerns are: a document resource leak risk in nested family processing, Revit API compatibility issues with ElementId changes in newer versions, and a variable scope bug in exception handling. I utilized my knowledge of pyRevit's coding standards and Revit API version compatibility requirements to perform this review. Please provide feedback on this review which I'll incorporate for future reviews.

Follow-up suggestions:

@devloai fix the identified issues in this PR
@devloai add error recovery mechanisms for family loading failures

…t3.stack/Edit.pulldown/Replace_Fonts.pushbutton/script.py

Co-authored-by: devloai[bot] <168258904+devloai[bot]@users.noreply.github.com>

This comment was marked as outdated.

@jmcouffin jmcouffin requested a review from Copilot July 2, 2025 07:59
@jmcouffin jmcouffin marked this pull request as ready for review July 2, 2025 08:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the font replacement script for Revit families by adding regex-based, case-insensitive renaming and recursive updates for nested generic annotation families, along with improved error handling and updated main logic to support both family and project documents.

  • Add rename_element_type_if_needed for regex-based, case-insensitive font name replacement.
  • Implement recursive traversal and updating of nested generic annotation families.
  • Improve error logging and expand main script to handle both family and project contexts.
Comments suppressed due to low confidence (2)

extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit3.stack/Edit.pulldown/Replace_Fonts.pushbutton/script.py:3

  • The code calls FamilyLoaderOptionsHandler but it isn’t imported. Add an import, for example: from rpw import FamilyLoaderOptionsHandler (or the appropriate module) to prevent a NameError.
import re

extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/edit3.stack/Edit.pulldown/Replace_Fonts.pushbutton/script.py:32

  • Using DB.Element.Name.GetValue and SetValue is nonstandard and may not work. It’s clearer and more reliable to use the ElementType’s Name property directly, e.g., current_name = element_type.Name and element_type.Name = new_name.
    current_name = DB.Element.Name.GetValue(element_type)

…t3.stack/Edit.pulldown/Replace_Fonts.pushbutton/script.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jmcouffin jmcouffin merged commit 1cba977 into develop Jul 2, 2025
@jmcouffin jmcouffin deleted the fix/replace-fonts-improvment branch July 2, 2025 08:02
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jul 2, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25183+0806-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jul 8, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25189+0609-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25204+0748-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25209+2004-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25211+1247-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 1, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25213+1402-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 4, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25216+1027-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 4, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25216+1429-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 7, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25219+0909-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 7, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25219+1354-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 7, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25219+1400-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 7, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25219+1405-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 7, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25219+1421-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 8, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25220+1008-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25225+0806-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25225+1628-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25240+1743-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25243+1636-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25243+1639-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 1, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25244+0918-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 2, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25245+0639-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 2, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25245+0642-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 2, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25245+1846-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 3, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25246+0855-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 5, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25248+0948-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 8, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25251+0758-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 8, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25251+0805-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 8, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25251+0824-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 9, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25252+1659-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25255+0644-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25255+0911-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25256+0727-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25258+1448-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25265+1047-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25266+0803-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25268+1757-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1336-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1431-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1436-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1822-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25271+1719-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2003-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2012-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2017-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2149-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.2.0.25302+0949-wip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Tools Issues related to pyRevit commands [subsystem]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants