Here are 2 versions for you to look and study... First is based on your example using command functions, but then after execution you'll get memory occupied with entities - polylines... To avoid this I'd suggest second one - using (vla-copy) function - Visual Lisp extensions...
(defun c:sp ( / cmdfun cmderr ss )
(defun cmdfun ( tokenslist flag ) ;;; tokenslist - command parameters list of strings ;;; flag - if "t" specified, upon successful execution returns t, otherwise if "nil" specified, return is always nil no matter what outcome of function execution is - it should be successful anyway if specified tokenslist was hardcoded correctly... ;;;
(if command-s
(if flag
(if (not (vl-catch-all-error-p (vl-catch-all-apply (function command-s) tokenslist)))
flag
)
(apply (function command-s) tokenslist)
)
(if flag
(apply (function vl-cmdf) tokenslist)
(apply (function command) tokenslist)
)
)
)
(defun cmderr ( linenum ) ;;; linenum - integer representing line number at which used (cmdfun) failed with success execution ;;;
(prompt (strcat "\ncommand execution failure... error at line " (itoa linenum) " ..."))
)
(if (not (tblsearch "LAYER" "Border"))
(if (not (cmdfun (list "_.-LAYER" "_make" "Border" "color" "6" "" "lt" "Continuous" "" "") t))
(cmderr 24)
)
)
(if (setq ss (ssget "_x" (list (cons 0 "*POLYLINE") (cons 8 "Polygon"))))
(progn
(if (not (cmdfun (list "_.COPYBASE" "_non" "0,0,0" ss "") t))
(cmderr 30)
)
(if (not (cmdfun (list "_.PASTECLIP" "_non" "0,0,0") t))
(cmderr 33)
)
(if (not (cmdfun (list "_.CHPROP" ss "" "la" "Border" "") t))
(cmderr 36)
)
)
)
(princ)
)
(defun c:sp ( / ss i ex )
(if (vl-catch-all-error-p (vl-catch-all-apply (function vlax-get-acad-object) nil)))
(vl-load-com)
)
(if (not (tblsearch "LAYER" "Border"))
(entmake (list (cons 0 "LAYER") (cons 2 "Border") (cons 62 6)))
)
(if (setq ss (ssget "_x" (list (cons 0 "*POLYLINE") (cons 8 "Polygon"))))
(repeat (setq i (sslength ss))
(setq ex (entget (vlax-vla-object->ename (vla-copy (vlax-ename->vla-object (ssname ss (setq i (1- i))))))))
(entupd (cdr (assoc -1 (entmod (subst (cons 8 "Border") (assoc 8 ex) ex)))))
)
)
(princ)
)
I hope it's now a little clearer to you... Keep going with study...
M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)