def get_symbols(self): """ Loads family in a fake transaction to return all symbols. Returns ------- set() Set of family symbols Remark ------ Uses SmartSortableFamilySymbol for effective sorting """ logger.debug('Fake loading family: {}'.format(self.name)) symbol_set = set() with revit.ErrorSwallower(): # DryTransaction will rollback all the changes with revit.DryTransaction('Fake load'): ret_ref = clr.Reference[DB.Family]() revit.doc.LoadFamily(self.path, ret_ref) loaded_fam = ret_ref.Value # Get the symbols for symbol_id in loaded_fam.GetFamilySymbolIds(): symbol = revit.doc.GetElement(symbol_id) symbol_name = revit.query.get_name(symbol) sortable_sym = SmartSortableFamilySymbol(symbol_name) logger.debug('Importable Symbol: {}'.format(sortable_sym)) symbol_set.add(sortable_sym) return sorted(symbol_set)
selected_families = \ forms.SelectFromList.show( sorted(family_dict.keys()), title="Select Families to Check", multiselect=True) if selected_families: editable_families = [family_dict[x] for x in selected_families] else: editable_families = [x for x in all_families if x.IsEditable] total_count = len(editable_families) output.reset_progress() with revit.ErrorSwallower(log_errors=True) as swallower: for fam in editable_families: # get the family name fam_name = revit.query.get_name(fam) logger.debug("attempt to open family: %s", fam_name) try: # attempt to open family fam_doc = revit.doc.EditFamily(fam) # report swallowed warnings swallowed_errors = swallower.get_swallowed_errors() if swallowed_errors: error_descs = "\n".join( [x.GetDescriptionText() for x in swallowed_errors]) logger.warning(":warning: %s\n%s", fam.Name, error_descs) count_swallowed += len(swallowed_errors)
script.exit() all_fams = DB.FilteredElementCollector(revit.doc)\ .OfClass(DB.Family)\ .ToElements() all_family_items = [] opened_families = [ od.Title for od in HOST_APP.uiapp.Application.Documents if od.IsFamilyDocument ] with forms.ProgressBar(title=__title__, cancellable=True) as pb: i = 0 for fam in all_fams: with revit.ErrorSwallower() as swallower: if fam.IsEditable: fam_doc = revit.doc.EditFamily(fam) fam_path = fam_doc.PathName # if the family path does not exists, save it temporary # only if the wasn't opened when the script was started if fam_doc.Title not in opened_families and ( not fam_path or not os.path.exists(fam_path)): # edit family fam_doc = revit.doc.EditFamily(fam) # save with temporary path, to know family size fam_path = os.path.join(temp_dir, fam_doc.Title) fam_doc.SaveAs(fam_path, save_as_options) fam_size = 0 fam_category = fam.FamilyCategory.Name if fam.FamilyCategory \
# get family document and verify the file exists fam_doc = revit.doc.EditFamily(family) fam_doc_path = fam_doc.PathName if not op.exists(fam_doc_path): forms.alert( 'Can not find original family file at\n{}'.format(fam_doc_path)) logger.debug( 'Could not find original family file at {}'.format(fam_doc_path)) script.exit() else: logger.debug('Loading family from: {}'.format(fam_doc_path)) # fake load the family so we can get the symbols symbol_list = set() with revit.ErrorSwallower(): with revit.DryTransaction('Fake load'): # remove existing family so we can load the original revit.doc.Delete(family.Id) # now load the original ret_ref = clr.Reference[DB.Family]() revit.doc.LoadFamily(fam_doc_path, ret_ref) loaded_fam = ret_ref.Value # get the symbols from the original for sym_id in loaded_fam.GetFamilySymbolIds(): family_symbol = revit.doc.GetElement(sym_id) family_symbol_name = revit.query.get_name(family_symbol) sortable_sym = SmartSortableFamilyType(family_symbol_name) logger.debug('Importable Type: {}'.format(sortable_sym)) symbol_list.add(sortable_sym) # okay. we have all the symbols.