def getRailCurve(element_dict): refArray = DB.ReferenceArray() # refArray.Append(railCurve.Reference) for key in element_dict: print("Rail Detected\nELEMENT ID No. : " + str(key) \ + "\nElement String Representation : " + str(element_dict[key])) # refArray.Append(element_dict[key].GetPath().Reference()) railCurve = element_dict[key].GetPath() for curve in railCurve: # refArray.Append(curve.Reference) print(curve.Reference) # print(str(element_dict[key].HostRailingId)) # HostRail = element_dict[key].HostRailingId # HostParams = doc.GetElement(HostRail).Parameters # for param in HostParams: # print("Host Rail PARAMETER NAME : " + param.Definition.Name) # if param.HasValue: # try: # print("Value : " + param.AsString()) # except: # print("Value : " + param.ToString()) # for path in reversed(railCurve): # refArray.Append(path.Reference) # refArray.Append(railCurve.ReferenceArray) refArray.Append(DB.Reference(element_dict[key])) return railCurve, refArray
def main(): """Main Script. """ print("🐍 Running {fname} version {ver}...".format(fname=__name, ver=__version)) # STEP 0: Setup doc = __revit__.ActiveUIDocument.Document view = doc.ActiveView # STEP 1: Get all available Pipe Tags in the project print("Getting all available pipe tags from the model...", end="") tag_types = db.FilteredElementCollector(doc)\ .OfCategory(db.BuiltInCategory.OST_PipeTags)\ .WhereElementIsElementType()\ .ToElements() print("✔") tags = {} # tag_title: tag_type for tag_type in tag_types: tag_family_name = tag_type.get_Parameter(db.BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM).AsString() tag_type_name = tag_type.get_Parameter(db.BuiltInParameter.SYMBOL_NAME_PARAM).AsString() full_tag_name = "{f_name} - {t_name}".format(f_name=tag_family_name, t_name=tag_type_name) tags[full_tag_name] = tag_type # STEP 2: Check if setup tags actually exist in project print("Checking if expected tag family (and types) exist(s)... ", end="") all_tags_available = True for tag_name in TAG_TYPE_NAME_MAPPING.values(): if not tag_name in tags: print("✘ Error: {tag_name} not available!".format(tag_name=tag_name)) all_tags_available = False if not all_tags_available: print("✘ Error: Not all required tags are available in the project! See above.") return ui.Result.Failed print("✔") # STEP 3: Check if the current view a plan view print("🛈 Current view is: '{v}' {t}".format(v=view.Name, t=type(view))) if type(view) is not db.ViewPlan: print("✘ Error: Currently active view is not a plan view!") return ui.Result.Failed # STEP 4: Get all pipes in the view print("Getting all pipes from the currently active view... ", end="") pipes = db.FilteredElementCollector(doc, view.Id)\ .OfCategory(db.BuiltInCategory.OST_PipeCurves)\ .ToElements() print("✔") print(" ➜ Found {num} pipes in the currently active view.".format(num=len(pipes))) # STEP 5: Filter for vertical pipes print("Filtering vertical pipes... ", end="") vertical_pipes = [pipe for pipe in pipes if is_vertical(pipe)] print("✔") print(" ➜ Found {num} vertical pipes in the view.".format(num=len(vertical_pipes))) # STEP 6: Get the top and bottom view range elevations print("Finding views boundary elevations... ", end="") top, bottom = top_and_bottom_elevation(doc, view) print("✔") print(" ➜ Top boundary elevation is {0} ft (= {1} m)".format(top, top*FEET_TO_METER)) print(" ➜ Bottom boundary elevation is {0} ft (= {1} m)".format(bottom, bottom*FEET_TO_METER)) # STEP 7: Categorize pipes according to location and flow print("Categorizing vertical pipes... ", end="") categorized_pipes, _ = categorize_pipes(vertical_pipes, top, bottom) print("✔") for category, pipes in categorized_pipes.items(): print(" ➜ Found {num} pipes in category '{cat}'".format(num=len(pipes), cat=category)) # STEP 8: Place tags at the pipes TODO: avoid creating duplicate tags print("Creating tags... ", end="") transaction = db.Transaction(doc) transaction.Start("{name} - v{ver}".format(name=__name, ver=__version)) try: for category, pipes in categorized_pipes.items(): tag_type_id = tags[TAG_TYPE_NAME_MAPPING[category]].Id for pipe in pipes: point = pipe_location(pipe, top) new_tag = db.IndependentTag.Create(doc, view.Id, db.Reference(pipe), False, db.TagMode.TM_ADDBY_CATEGORY, db.TagOrientation.Horizontal, point) new_tag.ChangeTypeId(tag_type_id) except Exception as ex: print("\n✘ Exception:\n {ex}".format(ex=ex)) transaction.RollBack() return ui.Result.Failed else: transaction.Commit() print("✔\nDone. 😊") return ui.Result.Succeeded