from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import StructuralType
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
active_level = doc.ActiveView.GenLevel
pt_start = XYZ(0,0,0)
pt_end = XYZ(20,0,0)
line = Line.CreateBound(pt_start, pt_end)
beam_type_id = doc.GetDefaultFamilyTypeId(ElementId(BuiltInCategory.OST_StructuralFraming))
beam_type = doc.GetElement(beam_type_id)
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))