Copying Views Selected in Project Browser (API)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 = 'DEMO PLAN' myTemplate = 0 for view in collectorViews: if view.IsTemplate and view.Name == templateName: myTemplate = view break #by how much you want to expand the crop around the room expandVal = 1 #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 #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 #assign room's BoundingBox to view CropBox vp.CropBox = rmbox vp.CropBoxActive = True #you can fancy this up by assigning a particular view template etc t.Commit()
I’ve been programming & teaching myself the Revit 2014 API with the Python Shell. Using Dima Chiriacov’s tutorial regarding creating room plan views based on user selection, I have been trying to tweak it to accomplish a similar task.
Rather than having the user select the room in a project view before applying the script to create new room views, I want the user to select Floor Plan views in the Project Browser.
Some areas in the code I’ve tested to accomplish this includes much of the For Loop after the transaction starts.
Would anyone be able to point me in the correct direction to have selected views in the project browser create views rather than room selections?
Thanks,
S.W.
Tutorial Script: http://dp-stuff.org/downloads/dpstuff/free/revitpython/createRoomPlanViews.txt