The problem you are having seems to be one of abstract understanding..
When you type and ENTER something in the script editor, it is ALL seen as a single undo-able action. for example:
if you typed:
ccc;
then that is one undoable action. if you typed:
ccc;
ttt;
that is STILL ONE undoable action.
when you add the command undo to this entry in the script editor you are asking for confusion because the undo becomes part of the single undoable action..
if you type:
ccc;
ttt;
undo;
then it behaves as expected. if you type:
ccc;
ttt;
undo;
then the undo here is only going to undo the last thing that happened in ttt
because you're telling Maya to include an undo in a single undoable action. now I'm even confused myself but you should hopefully see what the problem is.
:nathaN