Sorry posted the wrong version where I was testing something else, here is the code I wanted to post in my previous post as it was explained there, auto detect if portrait or landscape, try this.
(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)
(initget 1 "name1 name2")
(setq plotstyle (getkword "\nChoose plot style [name1/name2]: "))
(initget 1 "A1 A2 A3 A4")
(setq papersize (getkword "\nChoose paper size [A1/A2/A3/A4]: "))
(cond ((= papersize "A1")
(setq papersize "ISO full bleed A1 (841.00 x 594.00 MM)")
)
((= papersize "A2")
(setq papersize "ISO full bleed A2 (594.00 x 420.00 MM)")
)
((= papersize "A3")
(setq papersize "ISO full bleed A3 (420.00 x 297.00 MM)")
)
((= papersize "A4")
(setq papersize "ISO full bleed A4 (297.00 x 210.00 MM)")
)
);cond
(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)))
)
(if (< (- (car llpt) (car urpt)) (- (cadr llpt) (cadr urpt)))
(setq draworient "Landscape")
(setq draworient "Portrait")
);if
(command "-plot"
"yes"
(car x)
"DWG TO PDF.PC3"
papersize
;"ISO full bleed A1 (841.00 x 594.00 MM)"
"Millimeters"
draworient
;"Landscape"
"No"
"Window"
llpt
urpt
"Fit"
"Center"
"yes"
plotstyle
;"acad.ctb"
;"Standard-A1.ctb"
"yes"
""
)
(if (/= (caddr x) "Model")
(command "No" "No" file "no" "Yes")
(command
file
"no"
"Yes"
)
)
)
)
)
(princ)
)
And completely understandable, you asked for help, I just wanted to say a lot can be done but all details need to be known to start the right way from the beginning.