Skip to content

Commit a267ef5

Browse files
authored
feat: improve cad_audit_check.py (#2559)
Added condition to catch the case of a project with no CAD instances
1 parent 2dda290 commit a267ef5

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

extensions/pyRevitTools.extension/checks/cad_audit_check.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -106,32 +106,36 @@ def check_model(doc, output):
106106

107107
table_data = [] # store array for table formatted output
108108
row_head = ["No", "Select/Zoom", "DWG instance", "Loaded status", "Workplane or single view", "Duplicate", "Workset", "Creator user", "Location site name"] # output table first and last row
109+
row_no_cad = ["-", "-", "No CAD instances found", "-", "-", "-", "-", "-", "-"] # output table row for when no CAD found
109110
cad_instances = collect_cadinstances(coll_mode)
110-
for count, cad in enumerate(cad_instances, start=1):
111-
cad_id = cad.Id
112-
cad_is_link = cad.IsLinked
113-
cad_name = cad.Parameter[DB.BuiltInParameter.IMPORT_SYMBOL_NAME].AsString()
114-
115-
table_row = [
116-
count,
117-
output.linkify(cad_id, title="Select"),
118-
cad_name,
119-
get_load_stat(cad, cad.IsLinked), # loaded status
120-
]
121-
122-
# if the instance has an owner view, it was placed on the active view only (bad, so give warning and show the view name)
123-
# if the instance has no owner view, it should have a level or workplane (good)
124-
cad_own_view_id = cad.OwnerViewId
125-
if cad_own_view_id == DB.ElementId.InvalidElementId:
126-
table_row.append(doc.GetElement(cad.LevelId).Name)
127-
else:
128-
cad_own_view_name = doc.GetElement(cad_own_view_id).Name
129-
table_row.append(":warning: view '{}'".format(cad_own_view_name))
130-
table_row.append(":warning:" if cad_name in [row[2] for row in table_data] else "-") # If the name is already in table_data, it is a duplicat (bad)
131-
table_row.append(revit.query.get_element_workset(cad).Name) # cad instance workset
132-
table_row.append(DB.WorksharingUtils.GetWorksharingTooltipInfo(revit.doc, cad.Id).Creator) # ID of the user
133-
table_row.append(get_cad_site(cad)) # Extract site name from location
134-
table_data.append(table_row)
111+
if not cad_instances:
112+
table_data.append(row_no_cad)
113+
else:
114+
for count, cad in enumerate(cad_instances, start=1):
115+
cad_id = cad.Id
116+
cad_is_link = cad.IsLinked
117+
cad_name = cad.Parameter[DB.BuiltInParameter.IMPORT_SYMBOL_NAME].AsString()
118+
119+
table_row = [
120+
count,
121+
output.linkify(cad_id, title="Select"),
122+
cad_name,
123+
get_load_stat(cad, cad.IsLinked), # loaded status
124+
]
125+
126+
# if the instance has an owner view, it was placed on the active view only (bad, so give warning and show the view name)
127+
# if the instance has no owner view, it should have a level or workplane (good)
128+
cad_own_view_id = cad.OwnerViewId
129+
if cad_own_view_id == DB.ElementId.InvalidElementId:
130+
table_row.append(doc.GetElement(cad.LevelId).Name)
131+
else:
132+
cad_own_view_name = doc.GetElement(cad_own_view_id).Name
133+
table_row.append(":warning: view '{}'".format(cad_own_view_name))
134+
table_row.append(":warning:" if cad_name in [row[2] for row in table_data] else "-") # If the name is already in table_data, it is a duplicat (bad)
135+
table_row.append(revit.query.get_element_workset(cad).Name) # cad instance workset
136+
table_row.append(DB.WorksharingUtils.GetWorksharingTooltipInfo(revit.doc, cad.Id).Creator) # ID of the user
137+
table_row.append(get_cad_site(cad)) # Extract site name from location
138+
table_data.append(table_row)
135139
table_data.append(row_head)
136140
output.print_md("## Preflight audit of imported and linked CAD")
137141
output.print_table(table_data=table_data,
@@ -142,7 +146,7 @@ def check_model(doc, output):
142146

143147
# Summary output section:
144148
link_to_view = output.linkify(ac_view.Id, title="Show the view")
145-
print("{} CAD instances found.".format(len(cad_instances)))
149+
print("{} CAD instances found.".format(len(cad_instances or [])))
146150
if coll_mode: # if active view only
147151
summary_msg = "the active view ('{}') {}".format(ac_view.Name, link_to_view)
148152
else:

0 commit comments

Comments
 (0)