Enhancement 1739 - Improve Copy Legend Functionality #2745
Enhancement 1739 - Improve Copy Legend Functionality #2745jmcouffin merged 13 commits intopyrevitlabs:developfrom
Conversation
…errides exception
… class, remove transaction status, and clear success message
…display logs if operation not aborted
|
I've hit an internal error while addressing the comment. Please try again later. |
|
@devloai please review this PR |
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the Copy Legends functionality by adding a progress bar, transaction groups, improved error handling, and clearer user feedback messages. The refactoring transforms a simple copy function into a more robust operation with detailed logging and user experience improvements.
- Added progress bar for better user feedback during copy operations
- Implemented transaction groups and enhanced error handling with detailed logging
- Improved user messaging with success/failure notifications and detailed operation summaries
| logger_messages.log_message_with_doc_and_legend( | ||
| dest_doc.Title, | ||
| legend_name, | ||
| "Legend name already exists. Renaming to: {}".format(new_name)) |
There was a problem hiding this comment.
The log message is logged for every legend regardless of whether it was actually renamed. This should only be logged when counter > 0 (i.e., when a rename actually occurred).
| logger_messages.log_message_with_doc_and_legend( | |
| dest_doc.Title, | |
| legend_name, | |
| "Legend name already exists. Renaming to: {}".format(new_name)) | |
| if counter > 0: | |
| logger_messages.log_message_with_doc_and_legend( | |
| dest_doc.Title, | |
| legend_name, | |
| "Legend name already exists. Renaming to: {}".format(new_name)) |
|
|
||
| options = DB.CopyPasteOptions() | ||
| options.SetDuplicateTypeNamesHandler(CopyUseDestination()) | ||
| copied_elements = DB.ElementTransformUtils.CopyElements( |
There was a problem hiding this comment.
The indentation of this line is inconsistent with the surrounding code block. It should align with the other statements in the transaction.
| # skip reference plane for now, they are copied in the model space | ||
| if isinstance(el, DB.Element) and el.Category and not isinstance(el, DB.ReferencePlane): |
There was a problem hiding this comment.
[nitpick] The condition logic could be more readable by extracting the ReferencePlane check into a separate variable or adding a comment explaining why ReferencePlanes are excluded.
| # skip reference plane for now, they are copied in the model space | |
| if isinstance(el, DB.Element) and el.Category and not isinstance(el, DB.ReferencePlane): | |
| # ReferencePlanes are skipped because they are copied in the model space, not in the legend view. | |
| is_reference_plane = isinstance(el, DB.ReferencePlane) | |
| if isinstance(el, DB.Element) and el.Category and not is_reference_plane: |
There was a problem hiding this comment.
PR Summary:
This PR enhances the Copy Legend functionality by adding:
• Progress bar with cancellation support
• TransactionGroup for better transaction management
• Clear success/failure messages with detailed reporting
• Improved error handling and logging
• Reference plane exclusion to avoid model space copying (addresses #2319)
Review Summary:
Overall solid enhancement that addresses the original issue #1739. The code adds meaningful user feedback and better error handling. I identified 3 logic bugs that should be fixed: incorrect boolean condition for logging, misleading log messages, and missing progress bar cancellation handling. The changes follow pyRevit patterns well and the Reference plane exclusion properly addresses a known issue.
Follow-up suggestions:
@devloai fix the identified logic issues
| content = "\n".join(details) | ||
| forms.alert(msg=main_instruction, sub_msg=content) | ||
|
|
||
| if logger_messages: |
There was a problem hiding this comment.
The condition here is incorrect. logger_messages is an instance of LogMessage class and will always evaluate to True in a boolean context. You need to check if there are actually messages to log.
if logger_messages.get_messages().strip():
logger.warning(logger_messages.get_messages())actions
Feedback: Rate this comment to help me improve future code reviews:
- 👍 Good - Helpful and accurate
- 👎 Poor - Wrong, unclear, or unhelpful
- Skip if you don't have any strong opinions either way.
| while new_name in all_legend_names: | ||
| counter += 1 | ||
| new_name = src_name + " (Duplicate %s)" % counter | ||
| logger_messages.log_message_with_doc_and_legend( |
There was a problem hiding this comment.
This logging message is misleading. It logs "Legend name already exists" for every legend, even when no duplication occurs. The message should only be logged when counter > 0.
if counter > 0:
logger_messages.log_message_with_doc_and_legend(
dest_doc.Title,
legend_name,
"Legend name already exists. Renaming to: {}".format(new_name))actions
Feedback: Rate this comment to help me improve future code reviews:
- 👍 Good - Helpful and accurate
- 👎 Poor - Wrong, unclear, or unhelpful
- Skip if you don't have any strong opinions either way.
| current_operation = 0 | ||
| skipped_docs = [] | ||
|
|
||
| with forms.ProgressBar(cancellable=True) as pb: |
There was a problem hiding this comment.
Progress bar should handle cancellation. Currently, if user cancels the operation, the script will continue processing. Check pb.cancelled and break/exit if needed.
with forms.ProgressBar(cancellable=True) as pb:
for dest_doc in open_docs:
if pb.cancelled:
break
# ... rest of the loopactions
Feedback: Rate this comment to help me improve future code reviews:
- 👍 Good - Helpful and accurate
- 👎 Poor - Wrong, unclear, or unhelpful
- Skip if you don't have any strong opinions either way.
|
It seems fine overall, please review and test the comments from our AI friends, |
|
@jmcouffin I think we're good now |
|
@MohamedAsli at line 61, Using variable 'tg' before assignment |
|
@jmcouffin Good catch! |
It was listed in my code editor errors list :) Thanks for all of the above @MohamedAsli |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25216+1429-wip |
|
Thanks!
My pycharm didn't, surely missing some settings |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25219+0909-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25251+0805-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25251+0824-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25252+1659-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25255+0644-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25255+0911-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25256+0727-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25258+1448-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25265+1047-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25266+0803-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25268+1757-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1336-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1431-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1436-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25269+1822-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25271+1719-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2003-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2012-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2017-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25272+2149-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25274+1734-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25277+1425-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25277+1427-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25279+2157-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25280+0218-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25280+1054-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25280+1057-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25282+1656-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25283+0140-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25286+1022-wip |
|
📦 New work-in-progress (wip) builds are available for 5.2.0.25302+0949-wip |
Improve Copy Legend Functionality
Description
This PR enhances the functionality for copying legend views between documents in Revit by adding :
Checklist
Before submitting your pull request, ensure the following requirements are met:
Related Issues
#1739
Additional Notes
For now I just skipped ReferencePlanes, because they get copied in the model space (unwanted) (see #2319)