Thanks, @hak_vz, so the code below might be work in some cases:
(defun c:test (/ boundaryPnt layername oldlayer flag ss)
(setq layername "templayer")
(setq oldlayer (getvar "CLAYER")) ; Save origin layer name
(setq flag (tblsearch "LAYER" layername)) ; Looking for existing
(if (null flag) (progn (command "_.-layer" "m" layername ""))) ; Creat new layer if not exist
(setvar "CLAYER" layername) ; Change current layer to <layername>
(setq boundaryPnt (getpoint "\nGet point"))
(command "_.-boundary" "A" "O" "P" "" boundaryPnt "")
(setq ss (ssget "_X" (list (cons 8 layername))))
(command "_.move" ss)
;; Other code
(setvar "CLAYER" oldlayer) ; Change back to the origin layer to layername
;; (command "_.-laydel" "_N" layername "" "_Y") ; Delete temp layer and all the objects in the layer(if you want)
)
Ref:
creating-layer-and-styles-with-autolisp
ssget