Got it. I just modified the original flex code. Thanks to all that responded. This works with models that are square or rectangular. You will get undesired effects with complex models unless you modify the vertex check to include some instuction of mid range vertecis.
Function UpdateFlex(flexmesh)
w#=MeshHeight(flexmesh)
xs#=EntityX(flexmesh):ys#=EntityY(flexmesh):zs#=EntityZ(flexmesh)
;move model To 0,0,0
PositionMesh flexmesh,0,0,0
;here we just see wich vertices are below 0(top of model) and wich
;are above 0 (bottom of model)
s=GetSurface(flexmesh,1)
For i=0 To CountVertices(s)-1
vx#=VertexX(s,i)
vy#=VertexY(s,i)
vz#=VertexZ(s,i)
TFormPoint vx,vy,vz,flexmesh,0
vy#=TFormedY()
If vy#<0 Then sorter(i)=1 Else sorter(i)=2
Next
;put model in its original position again
PositionMesh flexmesh,xs,ys,zs
;original flex code
For i=0 To CountVertices(s)-1
vx#=VertexX(s,i)
vy#=VertexY(s,i)
vz#=VertexZ(s,i)
TFormPoint vx,vy,vz,flexmesh,0
vx=TFormedX() : vy=TFormedY() : vz=TFormedZ()
LinePick vx,vy,vz,vx,vy-9000,vz
vy=PickedY()-.1
TFormPoint vx,vy,vz,0,flexmesh
vx=TFormedX() : vy=TFormedY() : vz=TFormedZ()
;we put bottom vertices on ground
If sorter(i)=1 Then
VertexCoords s,i,vx,vy,vz
Else
;and just sink the top vertices by original mesh height
VertexCoords s,i,vx,vy+w#,vz
EndIf
Next
;since mesh is origin is 0,0,0 lets move it
; back up by half its height
TranslateEntity flexmesh,0,(w#/1.25),0
End Function