FirsttFitDecreasing from BIM4Struct should do the trick.
More here: Beam length cut optimization - #16 by Dieter_Vermeulen