Problem with rotating framing (family instance input)

Hello Forum, this is my first post here and I’m looking for some help with a script I was working on.

The main goal of the script is to allign all the “almost straight” beams to 0, 90 or 180 deg. This is what I have so far:

Because the idea is to use it on whole floor, I have a sorting mechanism, but the last node accepts only “FamilyInstance” value. Is there a way to easily “convert” as the red line indicates?

Thank you for your help

and to point to exact problem:

@dbsznsky Don’t think FamilyInstance.SetRotation works on Structural framing

Can’t think of a work around other than deleting and recreating the faulty beams.