|
| 1 | +''' |
| 2 | +CREATE FLOOR PLAN VIEW BY ROOMS, LEVEL |
| 3 | +''' |
| 4 | +__author__ = 'min.naung/mgjean @https://twentytwo.space/contact' |
| 5 | +__twitter__ = '@_mgjean' |
| 6 | +__version__ ='1.0.0' |
| 7 | + |
| 8 | +# dynamo version - 1.3.2 |
| 9 | + |
| 10 | +# import common language runtime |
| 11 | +import clr |
| 12 | + |
| 13 | +# clr.AddReference loads and imports .net assembly(dll) as python module |
| 14 | +# load RevitAPI.dll and RevitServices.dll |
| 15 | +clr.AddReference("RevitAPI") |
| 16 | +clr.AddReference("RevitServices") |
| 17 | + |
| 18 | +# import all classes from Revit DB |
| 19 | +from Autodesk.Revit.DB import * |
| 20 | +# import document manager |
| 21 | +from RevitServices.Persistence import DocumentManager |
| 22 | +# import transaction manager |
| 23 | +from RevitServices.Transactions import TransactionManager |
| 24 | +# instantiate current document |
| 25 | +doc = DocumentManager.Instance.CurrentDBDocument |
| 26 | + |
| 27 | +# check list for rooms |
| 28 | +if isinstance(IN[0], list): |
| 29 | + rooms = UnwrapElement(IN[0]) |
| 30 | +else: |
| 31 | + rooms = [UnwrapElement(IN[0])] |
| 32 | +# check list for name |
| 33 | +if isinstance(IN[1],list): |
| 34 | + names = IN[1] |
| 35 | +else: |
| 36 | + names = [IN[1]] |
| 37 | + |
| 38 | +# level input |
| 39 | +level = UnwrapElement(IN[2]) |
| 40 | +# offset from room bbox (mm to ft) |
| 41 | +offset = IN[3]/304.8 |
| 42 | + |
| 43 | +def crop_box(bbox, offset): |
| 44 | + # modify x,y,z point of bbox |
| 45 | + minX = bbox.Min.X - offset |
| 46 | + minY = bbox.Min.Y - offset |
| 47 | + minZ = bbox.Min.Z - offset |
| 48 | + maxX = bbox.Max.X + offset |
| 49 | + maxY = bbox.Max.Y + offset |
| 50 | + maxZ = bbox.Max.Z + offset |
| 51 | + # create new bbox |
| 52 | + newbox = BoundingBoxXYZ() |
| 53 | + newbox.Min = XYZ(minX,minY, minZ) |
| 54 | + newbox.Max = XYZ(maxX, maxY, maxZ) |
| 55 | + return newbox |
| 56 | + |
| 57 | +# collect view type in document |
| 58 | +viewTypes = FilteredElementCollector(doc).OfClass(ViewFamilyType) |
| 59 | +#loop view types |
| 60 | +for i in viewTypes: |
| 61 | + # floor plane view type |
| 62 | + if i.ViewFamily == ViewFamily.FloorPlan: |
| 63 | + # get type id |
| 64 | + viewTypeId = i.Id |
| 65 | + # break the loop |
| 66 | + break |
| 67 | +# start transaction |
| 68 | +TransactionManager.Instance.EnsureInTransaction(doc) |
| 69 | +# output list |
| 70 | +floorPlans = [] |
| 71 | +# loop rooms and names together |
| 72 | +for i,name in zip(rooms,names): |
| 73 | + # level id |
| 74 | + levelId = level.Id |
| 75 | + # get bounding box |
| 76 | + bbox = i.BoundingBox[doc.ActiveView] |
| 77 | + # create new bounding vox |
| 78 | + newBbox = crop_box(bbox, offset) |
| 79 | + # create floor plan view |
| 80 | + newView = ViewPlan.Create(doc, viewTypeId, levelId) |
| 81 | + # set view name |
| 82 | + newView.ViewName = name |
| 83 | + # set cropbox to newbbox |
| 84 | + newView.CropBox = newBbox |
| 85 | + # set cropbox active |
| 86 | + newView.CropBoxActive = True |
| 87 | + # set visibility |
| 88 | + newView.CropBoxVisible = False |
| 89 | + # set view scale |
| 90 | + newView.Scale = 50 |
| 91 | + # append output |
| 92 | + floorPlans.append(newView) |
| 93 | + |
| 94 | +# End Transaction |
| 95 | +TransactionManager.Instance.TransactionTaskDone() |
| 96 | +# output |
| 97 | +OUT = floorPlans |
0 commit comments