@@ -106,32 +106,36 @@ def check_model(doc, output):
106
106
107
107
table_data = [] # store array for table formatted output
108
108
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
109
110
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 )
135
139
table_data .append (row_head )
136
140
output .print_md ("## Preflight audit of imported and linked CAD" )
137
141
output .print_table (table_data = table_data ,
@@ -142,7 +146,7 @@ def check_model(doc, output):
142
146
143
147
# Summary output section:
144
148
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 [] )))
146
150
if coll_mode : # if active view only
147
151
summary_msg = "the active view ('{}') {}" .format (ac_view .Name , link_to_view )
148
152
else :
0 commit comments