Door Set Handing

In this post I will demonstrate how to automatically determine if a door is left or right handed.

One of my fellow Bloggers asked me this morning about determining door set handing programmatically (or any other automated way). Dynamo is pretty good at accessing Revit API so I quickly cooked up a solution using three of the door properties: HandFlipped, ToRoom and FacingFlipped. Those three combined together make it easy to determine if a door is left or right handed. For all doors swinging into space that has no room placed (most likely exterior) there is another set of hardware called Right Hand Reversed and Left Hand Reversed. Here’s a solution:

Here’s what the Dynamo definition looks like:

Here’s the code that sits under the hood of Door Set Handing node:

#Copyright(c) 2015, Konrad Sobon
# @arch_laboratory, http://archi-lab.net

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

from System.Collections.Generic import *

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

# unwrap inputs
elements = []
for i in IN[0]:
    elements.append(UnwrapElement(i))
phase = UnwrapElement(IN[1])

# check if door has a left or right handed swing
right, left, lhr, rhr = [], [], [], []
for i in elements:
    to_room = i.ToRoom[phase]
    if to_room is not None:
        if not i.FacingFlipped:
            if i.HandFlipped:
                right.append(i)
            else:
                left.append(i)
        else:
            if i.HandFlipped:
                left.append(i)
            else:
                right.append(i)
    else:
        if i.FacingFlipped:
            if i.HandFlipped:
                rhr.append(i)
            else:
                lhr.append(i)
        else:
            if i.HandFlipped:
                lhr.append(i)
            else:
                rhr.append(i)

# Assign your output to the OUT variable
OUT = right, left, rhr, lhr

Door Set Handing is now a custom node available for download here: [Dynamo Download Page](/content/?page_id=47 "Dynamo"/index.html).

Preview of this functionality:

How to determine Door Set Handing (left/right handed door) using Dynamo - YouTube

Also, Håvard Vasshaug has made a short video and a write up on his blog demonstrating this node in real world application. You can find it here.

PS. 02/26/2015

In response to questions posted below originally by Dominik, I made some changes to the Door Set Handing Node. Code that you see above reflects those changes. There is an additional input now, for a Phase, since extracting door ToRoom and FromRoom information required that input. I had originally made a silly assumption that everyone’s phases would be called “New Construction” or “Existing”, while in reality some people like to change their names.
Anyways, it was an issue with Phase names, and the node should be working well. Thank you to Dominik and recently Jan for pointing out that the node wasn’t functioning well.

Here’s the latest example that uses Document.Phases from Clockwork package, to extract a phase on which door might reside: