Jump to content

Recommended Posts

Posted
5 minutes ago, shokoufeh said:

Thanks

The reason why I didn't explain completely in the beginning, was that I didn't know how lisps work and how to program it, and I was not even sure about what I need 😕

Here, I mean a situation that for example I define 2 blocks. one for portrait plot and one for landscape plot. for example blocks names "PDF-Port" and "PDF-Land". So the program  doesn't need to ask the orientation from the user, and it can understand which sheets to plot in which orientation.  


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.

  • Like 1
Posted (edited)
12 minutes ago, lastknownuser said:


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.

It worked great. Thanks a lot for your help 🙏

 

Edited by shokoufeh
  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...