Advertisement
dezindzer

FloorPlan.ByRoom.dyf (py)

May 29th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.45 KB | None | 0 0
  1. # Copyright(c) 2015, Konrad K Sobon
  2. # @arch_laboratory, http://archi-lab.net
  3. # http://tinypic.com/m/kbrvxh/1
  4.  
  5. import clr
  6. clr.AddReference('ProtoGeometry')
  7. from Autodesk.DesignScript.Geometry import *
  8.  
  9. # Import Element wrapper extension methods
  10. clr.AddReference("RevitNodes")
  11. import Revit
  12. clr.ImportExtensions(Revit.Elements)
  13.  
  14. # Import geometry conversion extension methods
  15. clr.ImportExtensions(Revit.GeometryConversion)
  16.  
  17. # Import DocumentManager and TransactionManager
  18. clr.AddReference("RevitServices")
  19. import RevitServices
  20. from RevitServices.Persistence import DocumentManager
  21. from RevitServices.Transactions import TransactionManager
  22. doc = DocumentManager.Instance.CurrentDBDocument
  23.  
  24. # Import RevitAPI
  25. clr.AddReference("RevitAPI")
  26. import Autodesk
  27. from Autodesk.Revit.DB import *
  28.  
  29. import System
  30. from System import Array
  31. from System.Collections.Generic import *
  32.  
  33. import sys
  34. pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
  35. sys.path.append(pyt_path)
  36.  
  37. #The inputs to this node will be stored as a list in the IN variable.
  38. dataEnteringNode = IN
  39.  
  40. if isinstance(IN[0], list):
  41.     rooms = UnwrapElement(IN[0])
  42. else:
  43.     rooms = [UnwrapElement(IN[0])]
  44. namePrefix = IN[1]
  45. bboxOffset = IN[2]
  46. runMe = IN[3]
  47.  
  48. def OffsetBBox(bbox, offset):
  49.     bboxMinX = bbox.Min.X - offset
  50.     bboxMinY = bbox.Min.Y - offset
  51.     bboxMinZ = bbox.Min.Z - offset
  52.     bboxMaxX = bbox.Max.X + offset
  53.     bboxMaxY = bbox.Max.Y + offset
  54.     bboxMaxZ = bbox.Max.Z + offset
  55.     newBbox = BoundingBoxXYZ()
  56.     newBbox.Min = XYZ(bboxMinX, bboxMinY, bboxMinZ)
  57.     newBbox.Max = XYZ(bboxMaxX, bboxMaxY, bboxMaxZ)
  58.     return newBbox
  59.  
  60. try:
  61.     errorReport = None
  62.     if runMe:
  63.         viewTypes = FilteredElementCollector(doc).OfClass(ViewFamilyType)
  64.         for i in viewTypes:
  65.             if i.ViewFamily == ViewFamily.FloorPlan:
  66.                 viewTypeId = i.Id
  67.                 break
  68.             else:
  69.                 continue
  70.        
  71.         existingPlans = FilteredElementCollector(doc).OfClass(View).ToElements()
  72.        
  73.         existingPlanNames, existingPlanElements = [], []
  74.         for i in existingPlans:
  75.             if not i.IsTemplate:
  76.                 if i.ViewType == ViewType.FloorPlan:
  77.                     existingPlanNames.append(i.ToDSType(True).Name)
  78.                     existingPlanElements.append(i)
  79.                    
  80.         # Start Transaction
  81.         #viewName = namePrefix + "-" + i.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString() + "-" + i.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()
  82.  
  83.         TransactionManager.Instance.EnsureInTransaction(doc)
  84.        
  85.         floorPlans = []
  86.         for i in rooms:
  87.             levelId = i.LevelId
  88.             bbox = i.BoundingBox[doc.ActiveView]
  89.             newBbox = OffsetBBox(bbox, bboxOffset)
  90.             viewName = namePrefix + i.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString() + "-" + i.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()
  91.             if viewName in existingPlanNames:
  92.                 view = existingPlanElements[existingPlanNames.index(viewName)]
  93.                 view.CropBox = newBbox
  94.                 view.CropBoxActive = True
  95.                 view.CropBoxVisible = True
  96.                 floorPlans.append(view)
  97.             else:
  98.                 newView = ViewPlan.Create(doc, viewTypeId, levelId)
  99.                 newView.ViewName = viewName
  100.                 newView.CropBox = newBbox
  101.                 newView.CropBoxActive = True
  102.                 newview.CropBoxVisible = True
  103.                 floorPlans.append(newView)
  104.    
  105.         # End Transaction
  106.         TransactionManager.Instance.TransactionTaskDone()
  107.     else:
  108.         errorReport = "Run Me set to False"
  109. except:
  110.     # if error accurs anywhere in the process catch it
  111.     import traceback
  112.     errorReport = traceback.format_exc()
  113.  
  114. #Assign your output to the OUT variable
  115. if errorReport == None:
  116.     OUT = floorPlans
  117. else:
  118.     OUT = errorReport
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement