def selection_dependent(): """By selection""" sel = selection.elements if not len(sel): alert("Nothing selected") return results = {} for e in sel: t = Transaction(doc, "Check selection " + str(e.Id.IntegerValue)) t.Start() deleted_ids = doc.Delete(e.Id) t.RollBack() try: el_type = e.Category.Name except: el_type = "Other" # Exclude selected element from result deleted_ids = filter(lambda x: x != e.Id, deleted_ids) try: name = e.Name except: name = "None" results["%s, ID: %d, Name: %s" % (el_type, e.Id.IntegerValue, name)] = group_by_type(deleted_ids) return results
def level_dependent(): """By level""" levels_all = all_levels() if len(levels_all) < 2: print( "At least 2 levels should be created in a project to check dependent. Create one more level and run again" ) return selected_levels = select_levels_dialog(levels_all) if not selected_levels: print("Nothing selected") return results = {} for e in selected_levels: views_to_close = check_dependent_views(e) if len(views_to_close) > 0: q = TaskDialog.Show( __title__, "These views will be closed:\n%s" % ", ".join( map(lambda x: doc.GetElement(x.ViewId).Name, views_to_close)), TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel) if str(q) == "Cancel": break if len(uidoc.GetOpenUIViews()) == len(views_to_close): uidoc.ActiveView = starting_view() for v in views_to_close: v.Close() t = Transaction(doc, "Check level " + e.Name) t.Start() elements = doc.Delete(e.Id) t.RollBack() results[e.Name] = group_by_type(elements) return results
def FillPatterns_wip(self, doc, deps, **kwargs): elements = get_FillPatterns(doc) not_purged = [] count = 0 mcount = len(elements) for e in elements: if e.Id.IntegerValue in deps: mcount -= 1 continue try: ids = doc.Delete(e.Id) # print(len(ids)) count += 1 except Exception as exception: # print("exception6", exception, e.Id.IntegerValue) not_purged.append(e) pass return (count, mcount, not_purged)
def ImageType(self, doc, deps, **kwargs): elements = get_ImageType(doc) not_purged = [] count = 0 mcount = len(elements) for e in elements: if e.Id.IntegerValue in deps: mcount -= 1 continue try: ids = doc.Delete(e.Id) # print(len(ids)) count += 1 except Exception as exception: print("exception0", exception) not_purged.append(e) pass return (count, mcount, not_purged)
def Materials_wip(self, doc, deps, **kwargs): # TODO проверять object styles materials = get_materials(doc) not_purged = [] count = 0 mcount = len(materials) for e in materials: if e.Id.IntegerValue in deps: mcount -= 1 continue try: ids = doc.Delete(e.Id) # print(len(ids)) count += 1 except Exception as exception: print("exception4", exception) not_purged.append(e) pass return (count, mcount, not_purged)
def Families(self, doc, deps, **kwargs): if "fam_not_used" not in kwargs.keys(): return doc_families = kwargs["fam_not_used"] # print(doc_families) not_purged = [] count = 0 for f in doc_families: # print("\n" + f.Name) if f.IsInPlace: continue try: ids = doc.Delete(f.Id) count += 1 except Exception as e: not_purged.append(f) return (count, len(doc_families), not_purged)