Skip to content

Commit

Permalink
Sort revisions before printing (pyrevitlabs#1583)
Browse files Browse the repository at this point in the history
The previous script outputs the revision list straight from a FilteredElementCollector, so the list of revisions are not necessarily in numerical order. This change gathers the revision numbers and revision data in a rev_data list prior to adding them to the rev_table string, that way they can be sorted first.
  • Loading branch information
perrylackowski authored and Andrea Ghensi committed Jan 20, 2023
1 parent b9525b4 commit 29b90c4
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,20 @@
"|:-------------:|:--------------:|:-------------|\n"
rev_table_template = "|{number}|{date}|{desc}|\n"
rev_table = rev_table_header
for rev in all_revisions:
revnum = revit.query.get_rev_number(rev)
rev_table += rev_table_template.format(number=revnum,
date=rev.RevisionDate,
desc=rev.Description)

# gather revision number, date, and description in tuple list
rev_data = [(revit.query.get_rev_number(rev),
rev.RevisionDate,
rev.Description) for rev in all_revisions]

# sort tuple list by revision number
rev_data.sort(key=lambda rev:rev[0])

# add revision data to the revision table string
for rev in rev_data:
rev_table += rev_table_template.format(number=rev[0],
date=rev[1],
desc=rev[2])

# print revision table
console.print_md(rev_table)
Expand Down

0 comments on commit 29b90c4

Please sign in to comment.