Python Script to get Handrails

Hi, I’m trying to get handrails from railing to get then their length using Dynamo. Unfortunately, I’m stuck with getting Handrails, list of values just shows nulls every time for any kind of railings :frowning:
I’ve already seen similiar script for Rail Types and it is work. And that’s my first Python script, so here can be some really stupid mistakes, sorry :sweat_smile:

That’s my script:

import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

railing = UnwrapElement(IN[0])

rrail = railing.GetHandRails()

lst =
lst.append(rrail)
lst.append(doc.GetElement(rrail.PrimaryHandrail())
lst.append(doc.GetElement(rrail.SecondaryHandrail())
lst.append(doc.GetElement(rrail.TopRail())
OUT = lst
image

Thank you in advance

hi @Artemisia111

replace your python script with this:

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

railing = UnwrapElement(IN[0])

rail = railing.GetHandRails()
railType = doc.GetElement(railing.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsElementId())

lst = list()

lst.append(railType)
lst.append(doc.GetElement(railType.PrimaryHandrailType))
lst.append(doc.GetElement(railType.SecondaryHandrailType))
lst.append(doc.GetElement(railType.TopRailType))


OUT = lst

-biboy

1 Like

Thank you very much for response, not exactly want I want, but you gave me a clue how it should looks like! When I’m implementing this code, I receive TypeId. And when I’m trying to get Lenght, I receive nulls image
I don’t need the Type of element, I need its as element geometry to catch length then. Wouldn’t it be insolent to ask you take a look at my variant? I have en error ‘NoneType’ object has no attribute “AsString”

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

railing = UnwrapElement(IN[0])

rail = railing.GetHandRails()
railType = doc.GetElement(railing.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsElementId())

lst = list()

lst.append(railType)
lst.append(doc.GetElement(railType.PrimaryHandrailType))
lst.append(doc.GetElement(railType.SecondaryHandrailType))
lst.append(doc.GetElement(railType.TopRailType))

rLength = doc.GetElement(railing.get_Parameter(BuiltInParameter.CONTINUOUSRAIL_LENGTH_PARAM).AsString())

lstl = llist()

lstl.append(railLength)
lstl.append(doc.GetElement(rLength.PrimaryHandrailLength))
lstl.append(doc.GetElement(rLength.SecondaryHandrailLength))
lstl.append(doc.GetElement(rLength.TopRailLength))


OUT = lst, lstl

Please mark my solution as the solution to your original question because I think I have solved it. For another question not related or a question supplementary to your original question, please make another topic about it.