Add Relink Textures tool to pyRevitTools#2883
Add Relink Textures tool to pyRevitTools#2883jmcouffin merged 22 commits intopyrevitlabs:developfrom
Conversation
## New Tool: Relink Textures **Description:** Automates finding and relinking missing texture paths in Revit materials **Location:** pyRevit tab > Modify panel **Features:** - Automatically finds missing textures - Relinks paths in seconds - Search for textures not just location, in case someone moved the files **Testing:** Tested on Revit 2025
...nsions/pyRevitTools.extension/pyRevit.tab/Project.panel/Relink Textures.pushbutton/script.py
Outdated
Show resolved
Hide resolved
...nsion/pyRevit.tab/Modify.panel/edit3.stack/Edit.pulldown/Relink Textures.pushbutton/icon.png
Show resolved
Hide resolved
|
@Swichllc Added few comments on the structure of the script, I will fetch the PR and test it locally before running code review. |
|
also please propose a different location, I would suggest having it under the project/ links pulldown button This is not an everyday tool so it should not take a full stack. |
|
@tay0thman |
use the icons8 website to find one. |
| t = Transaction(doc, "Relink material textures") | ||
|
|
||
| try: | ||
| t.Start() | ||
|
|
||
| for a_elem in assets: | ||
| if not isinstance(a_elem, AppearanceAssetElement): | ||
| continue | ||
|
|
||
| examined += 1 | ||
| scope = None | ||
|
|
||
| try: | ||
| scope = AppearanceAssetEditScope(doc) | ||
| editable = scope.Start(a_elem.Id) | ||
| fixed_count += relink_asset(editable, roots, name_index, unresolved) | ||
| scope.Commit(True) | ||
| except Exception as ex: | ||
| logger.error("Asset edit failed for {}: {}".format(a_elem.Name, ex)) | ||
| finally: | ||
| if scope: | ||
| try: | ||
| scope.Dispose() | ||
| except: | ||
| pass | ||
|
|
||
| t.Commit() | ||
| logger.info("Transaction committed successfully") |
There was a problem hiding this comment.
more pyrevit like would be
with revit.Transaction("do stuff"):There was a problem hiding this comment.
also wrapping large chunks of code using try / except is highly risky, the logic should be controlled as much as possible
| # Check if SHIFT is pressed for quick-config | ||
| shift_click = False | ||
| try: | ||
| shift_click = __shiftclick__ | ||
| except: | ||
| pass | ||
|
|
||
| if shift_click: | ||
| run_config() |
There was a problem hiding this comment.
i think you can skip the try. Also according to notion you should use EXEC_PARAMS.config_mode
...nsions/pyRevitTools.extension/pyRevit.tab/Project.panel/Relink Textures.pushbutton/script.py
Outdated
Show resolved
Hide resolved
...nsions/pyRevitTools.extension/pyRevit.tab/Project.panel/Relink Textures.pushbutton/script.py
Outdated
Show resolved
Hide resolved
...nsions/pyRevitTools.extension/pyRevit.tab/Project.panel/Relink Textures.pushbutton/script.py
Outdated
Show resolved
Hide resolved
...nsions/pyRevitTools.extension/pyRevit.tab/Project.panel/Relink Textures.pushbutton/script.py
Outdated
Show resolved
Hide resolved
...nsions/pyRevitTools.extension/pyRevit.tab/Project.panel/Relink Textures.pushbutton/script.py
Outdated
Show resolved
Hide resolved
...nsions/pyRevitTools.extension/pyRevit.tab/Project.panel/Relink Textures.pushbutton/script.py
Outdated
Show resolved
Hide resolved
...sion/pyRevit.tab/Modify.panel/edit3.stack/Edit.pulldown/Relink Textures.pushbutton/script.py
Outdated
Show resolved
Hide resolved
|
@Swichllc are you comfortable enough to make all these changes? |
|
@jmcouffin yes, I'm very comfortable to try fixing it. |
Refactored script.py to use pyRevit's config API instead of manual JSON file management, improved error handling, and modularized asset collection and processing. Updated icon.png and added icon_dark.png for better UI support. The code now uses more robust directory traversal, transaction management, and provides clearer user feedback.
|
@jmcouffin @tay0thman @Wurschdhaud
|
I would put it under the modify panel in the edit drowpdown
Will review and polish this week if needed |
Added translations for bundle.yaml
…on management - Introduced ConfigurationManager, TextureIndexer, AssetProcessor, and TextureRelinker classes for better organization and separation of concerns. - Improved error handling and logging throughout the asset processing and relinking workflow. - Updated the main execution flow to utilize the new class structure, enhancing readability and maintainability. - Retained existing functionality while streamlining the user interface for managing texture search folders.
- Introduced constants for transaction names and log formatting to improve code readability and maintainability. - Updated the configuration management to use a constant key for texture folders, enhancing clarity. - Improved logging output consistency by replacing hardcoded strings with defined constants.
- Added a method to validate folder accessibility before adding to the configuration. - Improved error handling for invalid asset elements and edit scope failures. - Streamlined logging to provide clearer feedback on folder and asset processing issues.
- Integrated progress bars for texture indexing and asset relinking processes to provide real-time feedback to users. - Updated logging to reflect the number of indexed files and processing status of assets, improving overall user experience. - Maintained existing functionality while enhancing the visual feedback during lengthy operations.
… Relink Textures script - Added caching for texture index to enhance performance during repeated operations. - Introduced a method to clear the texture index cache when folder configurations change. - Improved folder validation by implementing a caching mechanism to reduce redundant checks. - Updated TextureIndexer to utilize cached data for faster directory validation and indexing. - Enhanced logging to provide clearer feedback on caching operations and folder validation results.
- Updated exception handling in ConfigurationManager, TextureIndexer, and AssetProcessor to catch specific error types (OSError, IOError, ValueError, AttributeError) for improved robustness. - Added initialization documentation for ConfigurationManager, TextureIndexer, and AssetProcessor classes to clarify their purpose and usage. - Streamlined progress updates during texture indexing to focus on essential information, enhancing user feedback.
- Eliminated various logger.info and logger.debug calls to reduce clutter in the output. - Streamlined the texture indexing and relinking processes by focusing on essential information. - Improved overall readability of the script by removing redundant log messages.
|
I went through, did a lot of cleaning, reorganizing, some with cursor, some without. |
…script - Updated the get_all_roots method to only retrieve folders from configuration, removing the project directory check. - Enhanced relink_asset_textures and process_single_asset methods to accept roots directly, improving clarity and reducing dependency on the indexer. - Added detailed output for texture indexing diagnostics, including the number of root folders indexed and total unique filenames processed. - Improved overall structure and readability of the script while maintaining existing functionality.
…/Swichllc/2883
…cript - Simplified the retrieval of texture folder configurations by directly using the configuration key. - Enhanced the show_main_menu method to provide a unified interface for folder management and relinking options. - Removed unnecessary logging statements to improve script clarity and focus on essential user interactions. - Streamlined the process for adding, removing, and clearing texture folders, enhancing user experience.
- Removed logger dependency from ConfigurationManager, TextureIndexer, and AssetProcessor classes to simplify initialization. - Streamlined folder management logic in show_main_menu method for improved user experience. - Enhanced error handling by directly using logger for warnings and errors, reducing redundancy. - Cleaned up unnecessary validation checks and improved overall script readability.
- Replaced ProgressBar with log messages to provide clearer feedback during texture indexing and relinking processes. - Enhanced output messages to inform users about the number of folders indexed and textures relinked. - Streamlined the user alert messages for better clarity and user experience.
|
Reviewed the user flow, simplified some checks and properly tested it this time. |
- Refactored the build_index method to utilize glob for recursive texture file searching, improving performance and accuracy. - Introduced a list of common texture file extensions to streamline the indexing process. - Added logic to skip specific directories during indexing to enhance efficiency. - Updated logging to reflect the number of unique texture files found, providing clearer feedback to users.
- Introduced filtering for common texture file extensions to improve indexing accuracy. - Added logic to skip specific directories during the indexing process for enhanced performance. - Updated the directory traversal to ensure hidden folders are excluded, streamlining the indexing operation.
|
@jmcouffin tested, its working - thank you for helping me with this |
|
@Swichllc I felt the number of assets examined (and counted) was not a crucial info. I left the "Textures relinked" in the output window + unresolved list as well. |
|
Thanks for this tool. This is a great addition |
|
@jmcouffin Perfect, Thank you again |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25301+1412-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25301+1521-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25302+0921-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25302+0949-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25302+1503-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25307+1644-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25307+1935-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25307+2011-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25307+2045-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.0.25307+2237-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.0.25308+0721-wip |
|
📦 New public release are available for 5.3.0.25307+2146 |




New Tool: Relink Textures
Description: Automates finding and relinking missing texture paths in Revit materials
Location: pyRevit tab > Modify panel
Features:
Testing: Tested on Revit 2025