Hi @mohammad.al-sharqawi,
If the proposed script works mark as solution, please.
Regarding the rotation of BoundingBox here is an explanation: