If I have correctly understood your intentions, I think this would be suitable:
Code:
(defun c:test ( / *error* block i sel vars vals )
(defun *error* ( msg )
(if vals (mapcar 'setvar vars vals))
(if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
(princ (strcat "\nError: " msg))
)
(princ)
)
(while
(not
(or
(eq "" (setq block (getstring t "\nSpecify Block to Insert: ")))
(tblsearch "BLOCK" block)
(setq block (findfile (strcat block ".dwg")))
)
)
(princ "\nBlock not found.")
)
(if
(and
(/= "" block)
(setq sel (ssget '((0 . "POINT"))))
)
(progn
(setq vars '("CMDECHO" "OSMODE" "ATTREQ")
vals (mapcar 'getvar vars)
)
(mapcar 'setvar vars '(0 0 0))
(repeat (setq i (sslength sel))
(command "_.-insert" block "_S" 1.0 "_R" 0.0
(trans (cdr (assoc 10 (entget (ssname sel (setq i (1- i)))))) 0 1)
)
)
(mapcar 'setvar vars vals)
)
)
(princ)
)
Ask if you need any part of the code explained.