How to make an object fit in a unit cube?
You can use this kind of script (works with the active object) :



Alternative script, so that :


Rotation and scale are previously applied (avoid border effects when export)
Place all the vertices between 0 and 1 (previous script only matters about overall dimensions)




import bpy
from mathutils import Vector

obj = bpy.context.object

#Eventually apply transforms (comment if unwanted)
bpy.ops.object.transform_apply( rotation = True, scale = True )

minX = min( [vertex.co[0] for vertex in obj.data.vertices] )
minY = min( [vertex.co[1] for vertex in obj.data.vertices] )
minZ = min( [vertex.co[2] for vertex in obj.data.vertices] )

vMin = Vector( [minX, minY, minZ] )

maxDim = max(obj.dimensions)

if maxDim != 0:
    for v in obj.data.vertices:
        v.co -= vMin #Set all coordinates start from (0, 0, 0)
        v.co /= maxDim #Set all coordinates between 0 and 1
else:
    for v in obj.data.vertices:
        v.co -= vMin