Advertisement
Guest User

Untitled

a guest
May 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.12 KB | None | 0 0
  1. #reference - http://thebuildingcoder.typepad.com/blog/2013/03/rename-view-by-matching-elevation-tag-with-room.html
  2.  
  3. import math
  4. import clr
  5. clr.AddReference("RevitNodes")
  6. import Revit
  7. clr.ImportExtensions(Revit.Elements)
  8.  
  9. clr.AddReference("RevitServices")
  10. import RevitServices
  11. from RevitServices.Persistence import DocumentManager
  12. from RevitServices.Transactions import TransactionManager
  13.  
  14. clr.AddReference("RevitAPI")
  15. import Autodesk
  16. from Autodesk.Revit.DB import *
  17.  
  18. import System
  19. from System.Collections.Generic import *
  20.  
  21. doc = DocumentManager.Instance.CurrentDBDocument
  22. uiapp = DocumentManager.Instance.CurrentUIApplication
  23.  
  24. def angles_yo(x,y):
  25.     radian_angle = math.atan2(x-0,y-0)
  26.     degrees_angle = math.degrees(radian_angle)
  27.     return degrees_angle
  28.    
  29. def direction_yo(angle):
  30.     if angle <= -45 and angle >=-135:
  31.         return "EAST"
  32.     if angle <= -135 and angle >= -180 or angle >= 135 and angle <= 180:
  33.         return "NORTH"
  34.     if angle >= 45 and angle <= 135:
  35.         return "WEST"
  36.     if angle >= -45 and angle <=45:
  37.         return "SOUTH"
  38.  
  39. view_sections = FilteredElementCollector(doc).OfClass(ViewSection).WhereElementIsNotElementType().ToElements()
  40.  
  41. room_at_point_out = []
  42. location_point_out = []
  43. view_section_name_out = []
  44. set_param_out = []
  45. room_name_out = []
  46. new_name_out = []
  47. new_names = []
  48. dones = []
  49. outs = []
  50.  
  51. unique_names = []
  52.  
  53. for view_section in view_sections:
  54.     if view_section.LookupParameter("Type").AsValueString() == "Interior Elevation":
  55.        
  56.         view_section_name_out.append(view_section)
  57.        
  58.         xmax = (UnwrapElement(view_section).CropBox.Max.X)
  59.         xmin = (UnwrapElement(view_section).CropBox.Min.X)
  60.         ymax = (UnwrapElement(view_section).CropBox.Max.Y)
  61.         ymin = (UnwrapElement(view_section).CropBox.Min.Y)
  62.         zmax = (UnwrapElement(view_section).CropBox.Max.Z)     
  63.         zmin = (UnwrapElement(view_section).CropBox.Min.Z)
  64.        
  65.  
  66.         location_point = Autodesk.Revit.DB.XYZ(xmax-0.5*(xmax-xmin),ymax-0.5*(ymax-ymin),0)
  67.         location_point_transform = view_section.CropBox.Transform.OfPoint(location_point)
  68.         location_point_out.append(location_point_transform)
  69.         try:   
  70.             room_at_point = doc.GetRoomAtPoint(location_point_transform)
  71.             room_at_point_out.append(room_at_point)
  72.             room_number = room_at_point.Number.ToString()
  73.             room_name = room_at_point.LookupParameter("Name").AsString()
  74.             room_name_out.append(room_name)
  75.  
  76.             elevX = view_section.ViewDirection.X
  77.             elevY = view_section.ViewDirection.Y
  78.        
  79.             view_angle = angles_yo(elevX,elevY)
  80.             direction = direction_yo(view_angle)
  81.    
  82.             TransactionManager.Instance.EnsureInTransaction(doc)
  83.    
  84.             new_name = (room_number + " " + room_name + " - " + direction)
  85.             new_names.append(new_name)
  86.            
  87.             for name in new_names:
  88.                 base_name = name
  89.                 new_name = base_name
  90.                 counter = 1
  91.                 while new_name in unique_names:
  92.                     counter += 1
  93.                     new_name = base_name + " " + str(counter)
  94.                 unique_names.append(new_name)
  95.            
  96.             view_name_param = view_section.get_Parameter(BuiltInParameter.VIEW_NAME)
  97.             done = view_name_param.Set(new_name)       
  98.             dones.append(done) 
  99.            
  100.             TransactionManager.Instance.TransactionTaskDone()  
  101.         except:
  102.             pass
  103.            
  104.  
  105. OUT =dones, unique_names
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement