Skip to content

Commit 07c1ff3

Browse files
committed
add missing import, remove leftover double counting, minor black formatting fixes
1 parent ecedec8 commit 07c1ff3

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack/Inspect.pulldown/ListFamilySizeCreator.pushbutton/ListFamilySizeCreator_script.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import math
55
import tempfile
6+
from collections import defaultdict
67
from pyrevit import revit, forms, script, DB, HOST_APP
78

89
output = script.get_output()
@@ -15,6 +16,7 @@
1516
save_as_options = DB.SaveAsOptions()
1617
save_as_options.OverwriteExistingFile = True
1718

19+
1820
def convert_size(size_bytes):
1921
if not size_bytes:
2022
return "N/A"
@@ -75,7 +77,7 @@ def print_sorted(families, group_by):
7577
key=lambda fam_item: fam_item.get(sort_by),
7678
reverse=False
7779
)
78-
80+
7981
for fam_item in sorted_families:
8082
group_by_value = fam_item[group_by]
8183
if group_by_value not in families_grouped:
@@ -86,7 +88,7 @@ def print_sorted(families, group_by):
8688
if group_by in ["Creator", "Category"]:
8789
output.print_md("---")
8890
output.print_md("## {}: {}".format(group_by, group_value))
89-
91+
9092
# Prepare table data
9193
table_data = []
9294
for fam_item in families_grouped[group_value]:
@@ -100,19 +102,21 @@ def print_sorted(families, group_by):
100102
else:
101103
row.append(str(value))
102104
table_data.append(row)
103-
105+
104106
# Print table using output.print_table()
105107
output.print_table(
106108
table_data,
107109
columns=fields_sorted
108110
)
109-
111+
110112
print_totals(families_grouped[group_value])
111113

114+
112115
# main logic
113116
# ask use to choose sort option
114-
sort_by = forms.CommandSwitchWindow.show(FIELDS,
115-
message='Sorting options:',
117+
sort_by = forms.CommandSwitchWindow.show(
118+
FIELDS,
119+
message="Sorting options:",
116120
)
117121
if not sort_by:
118122
script.exit()
@@ -131,12 +135,6 @@ def print_sorted(families, group_by):
131135
.ToElements()
132136

133137
# Create a dictionary to count instances per family
134-
family_instance_counts = {}
135-
for instance in all_family_instances:
136-
try:
137-
if instance.Symbol:
138-
family_name = instance.Symbol.Family.Name
139-
family_instance_counts[family_name] = \
140138
family_instance_counts = defaultdict(int)
141139
for instance in all_family_instances:
142140
try:
@@ -172,10 +170,10 @@ def print_sorted(families, group_by):
172170
fam.Id).Creator
173171
if fam_path and os.path.exists(fam_path):
174172
fam_size = os.path.getsize(fam_path)
175-
173+
176174
# Get instance count for this family
177175
fam_count = family_instance_counts.get(fam.Name, 0)
178-
176+
179177
all_family_items.append({"Size": fam_size,
180178
"Creator": fam_creator,
181179
"Category": fam_category,

0 commit comments

Comments
 (0)