Perhaps someone can help me here… I’m trying to place unplaced rooms using the NewRoom(room, plan circuit) method. I’m feeding in Rooms and circuits ; however, the warning message I’m getting its looking for either a phase or level. It appears it is looking at the other two NewRoom methods, but not the one I want to use. Any thoughts?
import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference(‘RevitAPIUI’)
from Autodesk.Revit.UI import *
clr.AddReference(‘System’)
from System.Collections.Generic import List
clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
#Preparing input from dynamo to revit
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
UnplacedRooms=UnwrapElement(IN[0])
circuit = IN[1]
roomlist =
Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for room in UnplacedRooms:
a=doc.Create.NewRoom(UnplacedRooms,circuit)
roomlist.append(a)
End Transaction
TransactionManager.Instance.TransactionTaskDone()
OUT = roomlist
Replace your UnplacedRooms
variable with room
in your list. The way you currently have it written, it is trying to use the entire list of rooms as the Room argument. One of the overloads for the NewRoom method is (Level, UV) so that’s why you’re seeing that particular error message.
for room in UnplacedRooms:
a = doc.Create.NewRoom(room, circuit)
roomlist.append(a)
wow thanks … can’t believe I missed that. Been tinkering with this for too long I guess.
I still am getting the same error though…
For whatever reason its not recognizing I’m wanting to give it rooms and circuits…
I’m having that same problem. Can’t seem to get it to use the correct method. Have you had any luck since this post?
Perhaps the circuit also has to be unwrapped? In its current form, doc.Create.NewRoom(room, circuit)
would be providing a Revit-owned room and a Dynamo-owned circuit. I don’t have access to Revit right now to test but I think that may be the issue.
I managed to get it working by unwrapping the room in the loop:
for room in unPRooms:
rm = UnwrapElement(room)
newRoom = doc.Create.NewRoom(rm,planCirc)
newRoom.LimitOffset = 5
In order for it to fully finish, I had to apply a “height” to the room with the Limit Offset parameter. I’m still not 100% sure what UnwrapElement really does but that got it working for me.
1 Like
UnwrapElement is a way of establishing an element as Revit-owned. If you are interacting with the Revit API, all of your data has to be either generic types (strings, ints, etc.) or Revit-owned types (Element, Parameter, etc.).
1 Like
Awesome… I had abandoned this for a bit. Thanks for the extra push.
still getting the same error… I’ve tried unwrapping all elements outside and inside of the loop. Did you only do it within?
TransactionManager.Instance.EnsureInTransaction(doc)
unPRooms = UnwrapElement(IN[0])
planCirc= UnwrapElement(IN[1])
Height = UnwrapElement(IN[2])
roomlist = []
# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for room in unPRooms:
rm= UnwrapElement(room)
pc = UnwrapElement(planCirc)
newRoom = doc.Create.NewRoom(rm,pc)
newRoom.LimitOffset = Height
roomlist.append(newRoom)
# End Transaction
TransactionManager.Instance.TransactionTaskDone()
OUT = roomlist
Here’s my full code. In my case, I was moving all unplaced rooms into a single location, so that’s what the “target area” part is all about. I also had to give it a phase and a level in order to get all of the available plan circuits.
outL = []
lvl = UnwrapElement(IN[1])
phs = UnwrapElement(IN[2])
unPRooms = IN[0]
targetArea = IN[3]
### GET TARGET PLAN CIRCUIT
topo = doc.get_PlanTopology(lvl,phs)
circs = topo.Circuits
planCirc = None
for circ in circs:
outL.append(circ.Area)
if round(circ.Area,5) == round(targetArea,5):
planCirc = circ
TransactionManager.Instance.EnsureInTransaction(doc)
for room in unPRooms:
rm = UnwrapElement(room)
newRoom = doc.Create.NewRoom(rm,planCirc)
newRoom.LimitOffset = 5
TransactionManager.Instance.TransactionTaskDone()
1 Like