Align pivot based on longest edge´s object

Hello there,

I guessing if there a way to align a pivot based on longest edge of an object like attachment.
Thx any help.

AttachmentSize
screenshot_1.jpg40.68 KB