face selection and detach

hi again
i seen this code ~ i have to modify some
still my skill is poor.
face fucntion is difficult to me still .
pls help me again ~~

my purpose is

0. there is sample box
1. to change box or other mesh to editpoly
2. to delete bottom face
3. to detach topface
4. to bevel and extrude topface
5. to assign topface material ex) topFaces.material = meditMaterials[23]
6. to assign material id num 90

there is no need mutilmatterial
only standard material

if selection.count != 0 do
with redraw off
for o in selection where canconvertto o Editable_Poly do
if not isKindOf o Editable_Poly do convertToPoly o


for o in selection where isKindOf o Editable_Poly or isKindOf o Editable_Mesh do
topFaces = #{}
minFaces = #{}
gfc = if isKindOf o Editable_Poly then polyop.getFaceCenter else meshop.getFaceCenter
for f = 1 to o.numfaces do
if (gfc o f).z == o.max.z do append topFaces f
if (gfc o f).z == o.min.z do append minFaces f
o.selectedfaces = topFaces

o.selectedfaces = minFaces

topFaces.material = meditMaterials[23]