I have a lisp below that I want to use to create layout for plotting. It also deletes the layout if it already exists so a new updated layout is created. My problem is apparently AutoCAD does not run these commands mediately and when I try to switch to the new layout within the lisp the lisp error because the layout does not yet exist. Can anyone help me with this?
(DEFUN C:DFS ()
(COMMAND "ZOOM" "E")
(COMMAND "-LAYER" "A" "S" "ONE" "" "" "")
(COMMAND "LAYOUT" "D" "DFS Continental")
(COMMAND "LAYOUT" "T" "DFS Continental")
(setvar "CTAB" (strcat "DFS CONTINENTAL"))
(COMMAND "-LAYER" "F" "**" "")
(COMMAND "-LAYER" "T" "DATE" "")
(COMMAND "MS")
(COMMAND "COPY" "ALL" "" "0,0" "0,0")
(COMMAND "CHSPACE" "P" "")
(COMMAND "PS")
(COMMAND "-LAYER" "U" "**" "")
(COMMAND "-LAYER" "A" "R" "ONE" "" "")
(COMMAND "-LAYER" "A" "D" "ONE" "" "")
(COMMAND "VPLAYER" "F" "DATE" "ALL" "")
(COMMAND "REGEN")
(COMMAND "QSAVE")
(princ)
)