Trying to create a script that makes roofs on selected boxes
Here is a quick script that extrudes selected faces of selected mesh objects, if the face has 4 vertices and the angle between the face normal and the up axis is lower than 3°:

import bpy
import bmesh
from math import degrees
from mathutils import Vector

up = Vector((0, 0, 1))

for ob in bpy.context.selected_editable_objects:
    if ob.type == 'MESH':
        me = ob.data
        if me.is_editmode:
            bm = bmesh.from_edit_mesh(me)
        else:
            bm = bmesh.new()
            bm.from_mesh(me)
        bm.normal_update()

        for face in bm.faces:
            if len(face.verts) == 4 and face.select:
                try:
                    angle = degrees(face.normal.angle(up))
                except ValueError:
                    continue
                if angle &lt; 3: # some threshold
                    ret = bmesh.ops.extrude_face_region(bm, geom=[face])
                    verts = [e for e in ret['geom'] if isinstance(e, bmesh.types.BMVert)]
                    faces = [e for e in ret['geom'] if isinstance(e, bmesh.types.BMFace)]
                    bmesh.ops.translate(bm, vec=face.normal * -0.7, verts=verts)

                    e1, e2, e3, e4 = faces[0].edges
                    if (e1.calc_length() + e3.calc_length()) &lt; (e2.calc_length() + e4.calc_length()):
                        edges = [e1, e3]
                    else:
                        edges = [e2, e4]
                    bmesh.ops.collapse(bm, edges=edges)

        if me.is_editmode:
            bmesh.update_edit_mesh(me)
        else:
            bm.to_mesh(me)
        me.update()


The two shorter edges of the top-face is collapsed to create a sensible roof.

Note that it doesn't account of degenerated quads (non-planar, self-intersecting), but should work good enough for your use case.