Python_Extract Beam ends connection types

Hello All,
I am a structural engineer. I am trying to use Dyanmo+Python to extract the connection types of structural frame beams.
My code works perfectly fine to extract end beam elevations, but not for connection types.
Any help is appreciated.

Hi @ashafa2K4BT,

This is just a guess, but it’s most likely that you are casting “.AsString” and the parameter returns an Element. So perhaps try using “.AsElementId” then using doc.GetElement(ElementId) method to get the StructuralConnectionType being used.

Let me know if this doesn’t work and I’ll jump on a pc.

Cheers,
Dan

Dan,
Many thanks for the reply.
I am trying to filter out the structural beams with a specific connection type.
How do I get the beam connection types from their id’s?
Thanks in advance for your help!

Hi @ashafa2K4BT,

Here is the code to do this…

import clr

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

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

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

# Use this definition to ensure object is a list...
def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

# Input Variables...
beams = tolist(UnwrapElement(IN[0]))

# Output Variables...
outList = []

# Main...
for b in beams:
	arr = []
	arr.append(doc.GetElement(b.get_Parameter(BuiltInParameter.STRUCT_CONNECTION_BEAM_START).AsElementId()))
	arr.append(doc.GetElement(b.get_Parameter(BuiltInParameter.STRUCT_CONNECTION_BEAM_END).AsElementId()))
	
	outList.append(arr)

# Output...
OUT = outList

To break this down a little as I have compacted the code to single lines to be more concise. see “Main” section below in more step by step…

import clr

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

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

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

# Use this definition to ensure object is a list...
def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

# Input Variables...
beams = tolist(UnwrapElement(IN[0]))

# Output Variables...
outList = []

# Main...
for b in beams:
	# Container for start/end connections per beam. This will be an array of 2 items, Start and End connection for the current beam in loop which we will add to a parent list later...
	arr = []
	# Get Start Connection Id from parameter and casting to ElementId with the ".AsElementId()".
	conStartId = b.get_Parameter(BuiltInParameter.STRUCT_CONNECTION_BEAM_START).AsElementId()
	# Get the Connection Element from its ElementId from the Revit Document. If beam has no Start/End connection, then this will be Null...
	conStart = doc.GetElement(conStartId)
	# Add to the Array...
	arr.append(conStart)
	
	# Same as above but for the End Connection...
	conEndId = b.get_Parameter(BuiltInParameter.STRUCT_CONNECTION_BEAM_END).AsElementId()
	conEnd = doc.GetElement(conEndId)
	arr.append(conEnd)
	
	# Add Start/End Connection array to Parent List for Output...
	outList.append(arr)

# Output...
OUT = outList

So, you can see we are using the .AsElementId() method which you can see in the link below as a method of the Parameter Class…

Parameter.AsElementId()

Since the connection is actually an Element you can cast to ElementId and then use the doc.GetElement() method in the link below to get the actual Element…

Document.GetElement()

I hope this is pretty clear. It’s always good to know which Type the parameter is (string, int, Element e.t.c.) and then cast accordingly.

Also, in your code you are initiating a Transaction. You don’t need to do that unless you are making modifications to the Revit Document. If you are making changes, you need to close this out at the end with…

TransactionManager.Instance.TransactionTaskDone()

Cheers,
Dan

1 Like

Many thanks Dan,
Cheers

No problem @ashafa2K4BT, don’t forget go mark as resolved if this solved your problem