#dp Stuff | http://dp-stuff.org | createRoomPlanViews #this Revit Python Script batch generates Room Plan Views #AND assigns view template #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 vtId = 0 collector = FilteredElementCollector(doc).OfClass(clr.GetClrType(ViewFamilyType)) collectorVP = FilteredElementCollector(doc).OfClass(clr.GetClrType(ViewPlan)).WhereElementIsNotElementType() collectorViews = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views) #template name templateName = 'Test Plan Template' myTemplate = 0 for view in collectorViews: if view.IsTemplate and view.Name == templateName: myTemplate = view break #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 #get the view filter t = Transaction(doc, 'Create Room Plan View(s)') t.Start() for rm in selEls: if int(BuiltInCategory.OST_Rooms) == rm.Category.Id.IntegerValue: lev = rm.Level #create a Plan View for the room vp = ViewPlan.Create(doc, vtId, lev.Id) #assign template to the view if myTemplate != 0: vp.ViewTemplateId =myTemplate.Id 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 print 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()