That is probably the reason just like I wrote, last inserted is first in list, and yes this happens here because you have multiple rows. Blocks 1, 4, 7 are not sorted between them. Here is multiple sorting, form left to right, and top to bottom, try this. With block numbering you have more flexibility, but again this is simpler here because block doesn't need to be edited.
(vl-load-com)
(defun c:PDFA1 (/ lst lst_sort lst1 lst2 n Ysort dwg file hnd i len llpt lst mn mx ss tab urpt)
(setq lst nil)
(if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "PDFA1"))))
(progn
(repeat (setq i (sslength ss))
(setq hnd (ssname ss (setq i (1- i)))
tab (cdr (assoc 410 (entget hnd)))
lst (cons (list hnd (cdr (assoc 10 (entget hnd))) tab) lst)
)
)
(setq lst_sort nil)
(setq n 0)
(while (< n (length lst))
(if (not (vl-remove-if-not '(lambda (y) (equal (cadr (cadr (nth n lst))) y 0.01)) Ysort))
(setq Ysort (cons (cadr (cadr (nth n lst))) Ysort))
);if
(setq n (1+ n))
);while
(setq Ysort (vl-sort Ysort '(lambda (x y) (> x y))))
(setq n 0)
(while (< n (length Ysort))
(setq lst1 (vl-remove-if-not '(lambda (x) (equal (nth n Ysort) (cadr (cadr x)) 0.01)) lst))
(setq lst2 (vl-sort lst1 '(lambda (x y) (< (car (cadr x)) (car (cadr y))))))
(setq lst_sort (append lst_sort lst2))
(setq n (1+ n))
);while
(setq i 0)
(foreach x lst_sort
(setq file (strcat (getvar 'DWGPREFIX)
(substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4))
"-"
(itoa (setq i (1+ i)))
".pdf"
)
)
(if (findfile file)
(vl-file-delete file)
)
(vla-getboundingbox (vlax-ename->vla-object (car x)) 'mn 'mx)
(setq llpt (vlax-safearray->list mn)
urpt (vlax-safearray->list mx)
len (distance llpt (list (car urpt) (cadr llpt)))
)
(command "-plot"
"yes"
(car x)
"DWG TO PDF.PC3"
"ISO full bleed A1 (841.00 x 594.00 MM)"
"Millimeters"
"Landscape"
"No"
"Window"
llpt
urpt
"Fit"
"Center"
"yes"
"Standard-A1.ctb"
"yes"
""
)
(if (/= (caddr x) "Model")
(command "No" "No" file "no" "Yes")
(command
file
"no"
"Yes"
)
)
)
)
)
(princ)
)