Create Beam

from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import StructuralType

# Variables
doc   = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument


# Get Level of Active View (Only if ViewPlan!)
active_level = doc.ActiveView.GenLevel

# Create Line
pt_start = XYZ(0,0,0)
pt_end   = XYZ(20,0,0)
line = Line.CreateBound(pt_start, pt_end)

# Get Default Beam Type
beam_type_id   = doc.GetDefaultFamilyTypeId(ElementId(BuiltInCategory.OST_StructuralFraming))
beam_type      = doc.GetElement(beam_type_id)


# Create Beam
t = Transaction(doc,'Create Beam')
t.Start()

beam = doc.Create.NewFamilyInstance(line, beam_type, active_level, StructuralType.Beam)


t.Commit()

print('Created Beam: {}'.format(beam.Id))

⌨️ Happy Coding!
Erik Frits