def get_available_tags(elements=None): """Get tags used in current model or on a list of elements. Args: elements (list[DB.Element], optional): list of elements to filer by tag. Returns: set[Tag]: set of tags in model or on elements """ global _METADATA_DICT target_elements = \ elements \ or query.get_elements_by_param_value( param_name=tagscfg.get_tags_param(), param_value="", inverse=True, doc=revit.doc ) \ or query.get_all_elements() tags = set() for element in target_elements: tags.update(extract_tags(element)) # record metadata _METADATA_DICT = {'count': len(target_elements)} return sorted(tags)
def get_all_tag_elements(tag): """Get all elements of given tag. Args: tag (Tag): tag object Returns: list[DB.Element]: list of elements in that tag """ # does not work in < 2016 # spid = framework.Guid('24353a46-1313-46a4-a779-d33ffe9353ab') # pid = DB.SharedParameterElement.Lookup(revit.doc, spid) # pp = DB.ParameterValueProvider(pid) # pe = DB.FilterStringEquals() # vrule = DB.FilterDoubleRule(pp, pe, tag_id, True) # param_filter = DB.ElementParameterFilter(vrule) # elements = DB.FilteredElementCollector(revit.doc) \ # .WherePasses(param_filter) \ # .ToElementIds() skip_cats = [query.get_category(x) for x in SCOPE_SKIP_CATEGORIES] skip_catids = [x.Id for x in skip_cats if x is not None] return [ x for x in query.get_all_elements() if tag in extract_tags(x) and x.Category is not None and x.Category.Id not in skip_catids ]
def clear_tags(elements=None): """Clear all tags from model or set of elements. Args: elements (list[DB.Element], optional): set of elements to remove the tag from. """ target_elements = elements or query.get_all_elements() for element in target_elements: apply_tags(element, [])