Thanks gile,
That is exactly what I need!
I did not know about the "cmdactive" variable, and that you can use it in a while loop during a active command. Very good thing. I just added one line for a prompt:
(defun c:3df ()
(command "_3dpoly")
(while (/= 0 (getvar "CMDACTIVE"))
(princ "Pick z")
(command ".z" "_end" pause)
)
)