I was hoping someone might be able to help with this issue I’ve been having with my graph (I’m using dynamo for revit 2021). I am trying to get the building area for a building using the approach where a new room is temporarily created external to the building. The process I’m using is:
- Collect all the walls in the view.
- Filter the walls into vertically and horizontally oriented.
- Get the walls that are located the furthest north, east, south and west (4 walls total) and create a bounding box around them.
- Scale the bounding box up to two times its size.
- Convert the bounding box to a solid. Get the top face of the bounding box solid and create room separation lines on the four edges of that face on the same sketchplane the walls in the view are on.
- Place a new room (called “Inverse Building Area”) exterior to the building.
*the next step is the one I’m struggling with
7) Get the newly created room (“Inverse Building Area”) boundary lines and area.
For some reason dynamo/revit recognizes that the new room has been created but I can’t get the room boundaries or the room area within the same graph. The clockwork room.boundaries node just returns an empty list. The room.area node just returns 0 as the area.
It’s weird because I’ve tried splitting the graph into two separate graphs (just creating the room and room separation lines in the first graph, then finding the room area/boundaries in the second graph) and it works.
I thought it may be an issue related to timing, so I’ve tried these approaches so far but without any luck:
- Add transaction end/start nodes after the room creation.
- Use the waitfor/passthrough node after the room creation.
- Use time.delay in a code block to try and wait a few seconds before getting the new list of rooms.
If anyone as any ideas it would be greatly appreciated!
Attached is the dynamo file:
Get Building Area with Bounding Box Method.dyn (189.6 KB)
and the python scripts are here (I numbered them in the screenshot of the graph):
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
def WallOrientation(wall):
loc = wall.Location
flipped = False
if hasattr(loc, "Curve"):
lcurve = loc.Curve
if hasattr(wall, "Flipped"): flipped = wall.Flipped
if str(type(lcurve)) == "Autodesk.Revit.DB.Line":
if flipped: return wall.Orientation.ToVector().Reverse()
else: return wall.Orientation.ToVector()
else:
direction = (lcurve.GetEndPoint(1) - lcurve.GetEndPoint(0)).Normalize()
if flipped: return XYZ.BasisZ.CrossProduct(direction).ToVector().Reverse()
else: return XYZ.BasisZ.CrossProduct(direction).ToVector()
else: return None
walls = UnwrapElement(IN[0])
if isinstance(IN[0], list): OUT = [WallOrientation(x) for x in walls]
else: OUT = WallOrientation(walls)
# Load the Python Standard and DesignScript Libraries
import clr
import sys
clr.AddReference('ProtoGeometry')
clr.AddReference("RevitAPI")
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
from Autodesk.Revit.DB import *
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference ("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# The inputs to this node will be stored as a list in the IN variables.
level_input = UnwrapElement(IN[0])
point_input = UnwrapElement(IN[1])
name = IN[2]
number = IN[3]
# Place your code below this line
TransactionManager.Instance.EnsureInTransaction(doc)
try:
level_elevation = level_input.Elevation
room_location = UV((point_input.U/275), (point_input.V/275))
room = doc.Create.NewRoom(level_input, room_location)
room.Name = name
room.Number = number
TransactionManager.Instance.TransactionTaskDone()
OUT = room
except Exception as e:
TransactionManager.Instance.TransactionTaskDone()
OUT = str(e)
import clr
import sys
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument
new_room = IN[0]
all_rooms = FilteredElementCollector(doc)
all_rooms.OfCategory(BuiltInCategory.OST_Rooms)
all_rooms.WhereElementIsNotElementType()
new_list = all_rooms.ToElements()
OUT = new_list