Create Revit Rooms with Python ShellHere is how you can avoid the hassle and quickly batch create Revit Room Plans using one short Python script and some Revit API. I got an email the other day from Rasmus Freek Engstrøm inquiring if that was possible to achieve with Python:

“…The crop to 3d code you made, made me think if its possible to make room plans based on rooms. Do you know if this i possible. Its a repetitive task, making room plans, and if a code, could make x amount of plans based on all the rooms in a given project, that could save so much time.”

It is definitely possible, in-fact it is actually pretty straight-forward to create a rectangular floor plan view for a room. All you need to do is to select one or many rooms that you want to generate floor plan views for, open Revit Python Shell and run this script. In a nutshell this Python script iterates over the selected rooms and extract their Bounding Boxes. Then it adds a plan view to the Revit document on the same level that the room is hosted on and assigns rooms Bounding Box to the view’s Crop Box. Lastly, the script assigns the name to the plan view that matches room’s name and number.

Now, what you are getting here is a rectangular crop region that takes the extreme bounding box of the each room profile and assigns it to the view. If you have non-rectangular rooms and you want your room plan view to hide everything that is outside the room boundaries then you have to manually or programmaticly create a masking region that would hide the rest of the stuff. That is because in Revit 2013 View CropBox can only be rectangular. However, in Revit 2014 you can actually alter/sketch the profile of View CropBox with straight segments and Revit API 2014 lets us access and alter this information so you can approximate almost any shape – I hope you see where I am going with that! So, in the next post I will cover how you can create Revit Room Plans with CropBox that is not really a box and that can match the shape of the room. But for no that’s about it – pretty quick and dirty Python solution that can potentially save you many many hours of labor trying to manually create Revit Room Plans.

Download the createRoomPlanViews Python 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
#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 = 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		
 
		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()
Tagged with →  
Share →

2 Responses to Create Revit Room Plans with Python Shell and Revit API

  1. Rasmus Freek says:

    This is awesome, thanks!!

    • Dima Chiriacov says:

      No problem, I will post next post on how to do that in Revit 2014 – which works much better because the CropBoxes can actually match the room boundary.

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>