In the previous post I covered how you could quickly generate Room Plan Views, already cropped to the room size with a Python Shell script, but this post adds Non Rectangular Viewports from Revit 2014 to the equation. The script from the previous post can be used in either Revit 2013 or Revit 2014. The issue is that in Revit 2013 view crop box can be just what the name suggests – a rectangular 2D box. Recently released Revit 2014 however allows us to edit the profile of the crop box with a sketch! Basically you can crop your view in the latest version to virtually any shape you want as long as you use straight segments (yes-no arcs). But even if you need to do an arc shaped crop you can still approximate it with short straight segments, right? What is an even better news (for me) is that this functionality was immediately added to Revit 2014 API – you can programmatically access ViewCropRegionShapeManager object to which you can pass a new CurveLoop for a new Crop Box boundary. So, what does that mean for us? Going back to the previous post and Room Plan Views generation – now with Revit 2014 API we can actually create these plan views and make their crop boxes to match the rooms’ boundaries – non rectangular viewports! All that can be achieved with Python Scripting.
In the end of the post you will find a Python script that is similar to the one from the previous post, with the difference that it has a Revit 2014 API – specific stuff that extracts each room’s boundary loop, approximates arc segments (if any) with lines and assigns this room boundary geometry and passes to room’s View Crop Region via ViewCropRegionManager object.
To batch-create Room Plan Views in Revit 2014:
- Download createViewRoomPlanViews2014 Python Script
- Select one or multiple rooms to create Room Plans for
- Fire up Revit Python Shell and run the downloaded script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
#dp Stuff | http://dp-stuff.org | createRoomPlanViews #this Revit Python Script batch generates Room Plan Views #before running the script select the rooms to generate Plan Views for import clr import math clr.AddReference('RevitAPI') clr.AddReference('RevitAPIUI') from Autodesk.Revit.DB import * app = __revit__.Application doc = __revit__.ActiveUIDocument.Document uidoc = __revit__.ActiveUIDocument collector = FilteredElementCollector(doc).OfClass(clr.GetClrType(ViewFamilyType)) collectorVP = FilteredElementCollector(doc).OfClass(clr.GetClrType(ViewPlan)).WhereElementIsNotElementType() vtId = 0 #by how much you want to expand the crop around the room expandVal = 0 #selected room elements selEls = uidoc.Selection.Elements #get elementId of FloorPlan viewFamilyType for el in collector: if el.ViewFamily == ViewFamily.FloorPlan: vtId = el.Id break t = Transaction(doc, 'Create Room Plan View(s)') t.Start() for rm in selEls: if int(BuiltInCategory.OST_Rooms) == rm.Category.Id.IntegerValue: rmbox = rm.get_BoundingBox(None) print rmbox minPt = XYZ(rmbox.Min.X-expandVal, rmbox.Min.Y-expandVal, 0) maxPt = XYZ(rmbox.Max.X+expandVal, rmbox.Max.Y+expandVal, 0) rmbox.Min = minPt rmbox.Max = maxPt lev = rm.Level #create a Plan View for the room vp = ViewPlan.Create(doc, vtId, lev.Id) print vp.Name testName = rm.get_Parameter('Name').AsString() + ' ' + str(rm.get_Parameter('Number').AsString()) for el in collectorVP: if el.Name == testName: testName = testName + ' (1)' break vp.Name = testName #2014 custom crop view boundary block opt = SpatialElementBoundaryOptions() rmBoundarySegListList = rm.GetBoundarySegments(opt) bsList = 0 crvList = list() #get first BoundarySegment Loop for bsL in rmBoundarySegListList: bsList = bsL break #create a Curve Loop and make sure they are all lines #if a segment is not a line then we tesselate it for bs in bsList: if bs.Curve is clr.GetClrType(Line): crvList.append(bs.Curve) else: #we tesselate the curve pts = bs.Curve.Tessellate() i = -1 for pt in pts: i+=1 if i < len(pts)-1: #create and add linear segments to the future CropBoundary loop crvList.append(Line.CreateBound(pts[i], pts[i+1])) myLoop = CurveLoop.Create(crvList) #assign CurveLoop to the CropBox of the view vp.CropBoxActive = True cropManager = vp.GetCropRegionShapeManager() if cropManager.Valid and cropManager.IsCropRegionShapeValid(myLoop): cropManager.SetCropRegionShape(myLoop) else: print 'Not Allowed to manage Crop for ' + vp.Name + ' :-(' vp.CropBox = rmbox #END 2014 custom crop view boundary block #you can fancy this up by assigning a particular view template etc t.Commit()