Erase lines or join faces on the same plane as an element

Hello everyone, I would like to join the faces of elements that then on the same plane, as you see in the image, the foundation when I import comes with multifaceted geometry, I would like to join them creating a smoothed geometry, that’s what I’m trying, could someone hel

p me create this script.

Why does the geometry have those faces to begin with? Are those faces planar?

They are linked IFC elements geometries, this is how it is generated by the program that I exported to IFC, my flow is to link the IFC and then import it, to create a floor plan of structures, I’m looking for help for a script that can smooth these faces . I’m sorry if I wasn’t clear

Yes, these faces are planar