Jump to content

Recommended Posts

Posted

Hello every one

I have many drawing sheets on an AutoCAD file and I need a lisp to automatically "print them to pdf". I want to be able to choose where to print from, by a "rectangle". For example, I draw a rectangle around different specific parts in an AutoCAD file and the lisp automatically changes where I specify by this rectangles, to pdf format.

Now, I need to do it manually every time for each sheet, and it is so time consuming. Every setting is constant since I need to print in A1 size and my special plot style table. I should add that I only need to print to pdf from "model" layout. I mean, I don't  want to print from different layouts.

I have attached a sample of my files here. As an example, I want to change each of these frames to pdf, but all together and in separated pdf files. Now, I have to select each one separately, every time, and when the number of these sheets are a lot, it takes a lot of time.

I don't know a lot about this programming language and I appreciate your help by heart.

Drawing1.dwg

Posted

I have plot titles in model but try not to use it. A better way is to make a rectang at the required scale using your A1 sheet, the A1 title block is saved in layouts at 1:1 scale then a mview is used to view the model at desired scale. It is a 2 step process make rectangs then make layouts so you can add more as you go along. 

 

This video is step 1, then just select all rectangs which are on a layer and make matching layouts. The code I have takes into account that you may have different orientation, Portrait or Landscape, even down to the rectang can be on an angle and Mview matches.

 

Ok the sample dwg has been screwed with the 6000 is 4so 1st step is rescale back to match 6000 or 6.0 then make a retang at scale. Put title block in layout at 1:1 ie 841x594 - edges. 

 

 

I do charge a small fee as the code needs to be setup to match your title block. I am metric ignore scale in movie.

Multiradio2col34.png.e8f8746b7256073461193bead0dea7a0.png

 

Have a look at this dwg.

 

 

 

 

Drawing1-2.dwg

  • Like 3
Posted
On 9/15/2024 at 3:18 AM, BIGAL said:

I have plot titles in model but try not to use it. A better way is to make a rectang at the required scale using your A1 sheet, the A1 title block is saved in layouts at 1:1 scale then a mview is used to view the model at desired scale. It is a 2 step process make rectangs then make layouts so you can add more as you go along. 

 

This video is step 1, then just select all rectangs which are on a layer and make matching layouts. The code I have takes into account that you may have different orientation, Portrait or Landscape, even down to the rectang can be on an angle and Mview matches.

 

Ok the sample dwg has been screwed with the 6000 is 4so 1st step is rescale back to match 6000 or 6.0 then make a retang at scale. Put title block in layout at 1:1 ie 841x594 - edges. 

 

 

I do charge a small fee as the code needs to be setup to match your title block. I am metric ignore scale in movie.

Multiradio2col34.png.e8f8746b7256073461193bead0dea7a0.png

 

Have a look at this dwg.

 

 

 

 

Drawing1-2.dwg 83.71 kB · 1 download

Actually I don't get what you mean.

It is great to be able to first add some rectangles in different  parts of the sheet. But how can I finally change them to pdf?

Posted

Once you have all the rectangs at desired scale, you make layouts from them using a lisp. Then as you have layouts you can plot them all in one go again using a lisp, I have used this on 88 layouts, just watched the pdf's coming out. 

 

I will have another look at your dwg, the obvious is to change all objects to true size. the details at 1:100 as they need a small viewport will look at that. 

Posted (edited)

@BIGAL

I found a good lisp and changed it a little, so that its result changed to what I was looking for. 

I will send the lisp and an AutoCAD sample here.

According to this lisp, I only need to draw a block called "PDFA1" around the sheets I want to plot to pdf, and run the lisp "PDFA1'. (I changed the name of the block and the lisp to be the same as each other so that I will never forget it :)))) . After running the lisp, it automatically plot all of them to A1 size.

Just 2 other questions: 

1- This lisp plot the sheets in a reverse order. I mean from the end to the beginning. So, when I want to merge the pdfs to one, I have to do it in a reverse order. Is it possible to change the code so that it plot the sheets to pdf from the beginning to the end?

2- When I delete one of this rectangle blocks (I mean block PDFA1) and add it again, after plotting, it goes to the beginning. I mean It is plotted as the first object. Why does it happen? And is it possible to prevent it? I want the sheets to always be plotted in order.  

 

PDFA1.rar testA.rar

Edited by shokoufeh
Posted
2 hours ago, shokoufeh said:

@BIGAL

I found a good lisp and changed it a little, so that its result changed to what I was looking for. 

I will send the lisp and an AutoCAD sample here.

According to this lisp, I only need to draw a block called "PDFA1" around the sheets I want to plot to pdf, and run the lisp "PDFA1'. (I changed the name of the block and the lisp to be the same as each other so that I will never forget it :)))) . After running the lisp, it automatically plot all of them to A1 size.

Just 2 other questions: 

1- This lisp plot the sheets in a reverse order. I mean from the end to the beginning. So, when I want to merge the pdfs to one, I have to do it in a reverse order. Is it possible to change the code so that it plot the sheets to pdf from the beginning to the end?

2- When I delete one of this rectangle blocks (I mean block PDFA1) and add it again, after plotting, it goes to the beginning. I mean It is plotted as the first object. Why does it happen? And is it possible to prevent it? I want the sheets to always be plotted in order.  

 

PDFA1.rar 759 B · 2 downloads testA.rar 857.58 kB · 2 downloads


1 - just reverse lst after making it, BUT number 2 - because you are not sorting the list at all, it just adds last inserted to beginning of lst (or end if you reverse), I edited the code a bit so its sorts by X axis from left to right, test it now if it works for you. I have a similar thing for my needs, but I added the block attribute number, so each block has a number and even if they are not in the same row (sorting from left to right), I sort pages by that number. But if this works for you no need for complicating it, just saying how it also can be done if you have layouts in multiple rows.
 

(vl-load-com)
(defun c:PDFA1 (/ dwg file hnd i len llpt lst mn mx ss tab urpt)
    (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 (vl-sort lst '(lambda (x y) (< (car (cadr x)) (car (cadr y))))))
            (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)
)

 

  • Like 1
Posted
16 minutes ago, lastknownuser said:


1 - just reverse lst after making it, BUT number 2 - because you are not sorting the list at all, it just adds last inserted to beginning of lst (or end if you reverse), I edited the code a bit so its sorts by X axis from left to right, test it now if it works for you. I have a similar thing for my needs, but I added the block attribute number, so each block has a number and even if they are not in the same row (sorting from left to right), I sort pages by that number. But if this works for you no need for complicating it, just saying how it also can be done if you have layouts in multiple rows.
 

(vl-load-com)
(defun c:PDFA1 (/ dwg file hnd i len llpt lst mn mx ss tab urpt)
    (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 (vl-sort lst '(lambda (x y) (< (car (cadr x)) (car (cadr y))))))
            (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)
)

 

Thanks a lot

I used this lisp but it still is not what I want. Just like you, I have sheets in different rows, too, and this lisp prints from bottom to the top. Actually, the problem I had with the order  is solved in this lisp. But the problem with the copied blocks is not. And another problem emerged, which is, the sheets are ploted from the last row. 

For example, in the sample file I attached, the sheets are ploted in this  order: 4-7-1-8-5-2-9-6-3

The reason why 4 and 7 are disordered is that I have deleted 4 and added it again.

testA.rar

Posted
3 minutes ago, shokoufeh said:

Thanks a lot

I used this lisp but it still is not what I want. Just like you, I have sheets in different rows, too, and this lisp prints from bottom to the top. Actually, the problem I had with the order  is solved in this lisp. But the problem with the copied blocks is not. And another problem emerged, which is, the sheets are ploted from the last row. 

For example, in the sample file I attached, the sheets are ploted in this  order: 4-7-1-8-5-2-9-6-3

The reason why 4 and 7 are disordered is that I have deleted 4 and added it again.

testA.rar 857.56 kB · 1 download


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)
)


 

  • Like 2
Posted
42 minutes ago, lastknownuser said:


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)
)


 

WOW 👌

It worked great

Exactly what I was looking for 

Thanks a lot 🙏

  • Like 1
Posted
1 hour ago, lastknownuser said:


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)
)


 

I have another question (out of curiosity) :

How can I make the lisp to be customizable?

Actually not every settings, I only want to be able to choose between plot styles, paper sizes and drawing orientation.

How is it possible that the lisp asks me to choose between for example 2 plot style tables I have defined, choose whether  I want to plot "portrait" or "landscape", and choose between 3 different paper sizes?  

Posted
16 hours ago, shokoufeh said:

I have another question (out of curiosity) :

How can I make the lisp to be customizable?

Actually not every settings, I only want to be able to choose between plot styles, paper sizes and drawing orientation.

How is it possible that the lisp asks me to choose between for example 2 plot style tables I have defined, choose whether  I want to plot "portrait" or "landscape", and choose between 3 different paper sizes?  


It can be done using DCL forms which is more work or writing to command prompt using initget as the lisp asks for certain options, which is simpler.
Add this to beginning, edit to your needs. It can also show default value, like here in plotstyle example.
 

(initget 1 "name1 name2")
(setq plotstyle (getkword "\nChoose plot style [name1/name2] <name1>: "))
(initget 1 "A1 A2 A3 A4")
(setq papersize (getkword "\nChoose paper size [A1/A2/A3/A4]: "))
(initget 1 "Portrait Landscape")
(setq draworient (getkword "\nChoose orientation [Portrait/Landscape]: "))

And change plot command to this

(command "-plot"
                         "yes"
                         (car x)
                         "DWG TO PDF.PC3"
			 papersize
                         "Millimeters"
			 draworient
                         "No"
                         "Window"
                         llpt
                         urpt
                         "Fit"
                         "Center"
                         "yes"
			 plotstyle
                         "yes"
                         ""
                )


I did not test this so not sure it will work, so write if something is wrong or have other question.

Posted (edited)
45 minutes ago, lastknownuser said:


It can be done using DCL forms which is more work or writing to command prompt using initget as the lisp asks for certain options, which is simpler.
Add this to beginning, edit to your needs. It can also show default value, like here in plotstyle example.
 

(initget 1 "name1 name2")
(setq plotstyle (getkword "\nChoose plot style [name1/name2] <name1>: "))
(initget 1 "A1 A2 A3 A4")
(setq papersize (getkword "\nChoose paper size [A1/A2/A3/A4]: "))
(initget 1 "Portrait Landscape")
(setq draworient (getkword "\nChoose orientation [Portrait/Landscape]: "))

And change plot command to this

(command "-plot"
                         "yes"
                         (car x)
                         "DWG TO PDF.PC3"
			 papersize
                         "Millimeters"
			 draworient
                         "No"
                         "Window"
                         llpt
                         urpt
                         "Fit"
                         "Center"
                         "yes"
			 plotstyle
                         "yes"
                         ""
                )


I did not test this so not sure it will work, so write if something is wrong or have other question.

45 minutes ago, lastknownuser said:


It can be done using DCL forms which is more work or writing to command prompt using initget as the lisp asks for certain options, which is simpler.
Add this to beginning, edit to your needs. It can also show default value, like here in plotstyle example.
 

(initget 1 "name1 name2")
(setq plotstyle (getkword "\nChoose plot style [name1/name2] <name1>: "))
(initget 1 "A1 A2 A3 A4")
(setq papersize (getkword "\nChoose paper size [A1/A2/A3/A4]: "))
(initget 1 "Portrait Landscape")
(setq draworient (getkword "\nChoose orientation [Portrait/Landscape]: "))

And change plot command to this

(command "-plot"
                         "yes"
                         (car x)
                         "DWG TO PDF.PC3"
			 papersize
                         "Millimeters"
			 draworient
                         "No"
                         "Window"
                         llpt
                         urpt
                         "Fit"
                         "Center"
                         "yes"
			 plotstyle
                         "yes"
                         ""
                )


I did not test this so not sure it will work, so write if something is wrong or have other question.

Method initget  is exactly what I am looking for. I changed the code to this but it has error. Where should I add the first part?  

 

PDFA1 - Copy.lsp

Edited by shokoufeh
Posted
9 minutes ago, shokoufeh said:

Method initget  is exactly what I am looking for. I changed the code to this but it has error. Where should I add the first part?  

 

PDFA1 - Copy.lsp 3.19 kB · 0 downloads


Maybe when asking for paper size use just A1, A2,... key words, then define exact paper size option like this.
 

(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

 

Posted (edited)
26 minutes ago, lastknownuser said:


Maybe when asking for paper size use just A1, A2,... key words, then define exact paper size option like this.
 

(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

 

I changed the code and it worked great 👌.

Thank you.

But, is it possible to define two blocks, one for portrait and one for landscape sheets, and change the lisp so that after run, it plots both landscape and portrait, together? I mean, is it possible to define the plot command in something like "if" (I am unfamiliar with lisp language, that's why my questions are childish)?

 

And the last question, while the pdf name exists, does the program overwrite it? Totally, how does the program work for defining the name?

Edited by shokoufeh
Posted

Just a comment I have work with any size and orientation as you are reading a "TITLE Block" you know its name and scale so can work out the plot parameters, same with hard copy or say to pdf. Happy to talk but everything in the world is not necessarily free.

 

 

  • Agree 1
Posted
2 minutes ago, BIGAL said:

Just a comment I have work with any size and orientation as you are reading a "TITLE Block" you know its name and scale so can work out the plot parameters, same with hard copy or say to pdf. Happy to talk but everything in the world is not necessarily free.

 

 

I agree with you. I have been using different lisps during this years, but this is the first time I am trying to dive into this programing language. I may should have stopped this topic sooner.

However, thanks  for mentioning.

Posted (edited)
2 hours ago, shokoufeh said:

I changed the code and it worked great 👌.

Thank you.

But, is it possible to define two blocks, one for portrait and one for landscape sheets, and change the lisp so that after run, it plots both landscape and portrait, together? I mean, is it possible to define the plot command in something like "if" (I am unfamiliar with lisp language, that's why my questions are childish)?

 

And the last question, while the pdf name exists, does the program overwrite it? Totally, how does the program work for defining the name?


You can use the same block, and actually I wanted to mention that, by the paper size it is defined if its portrait or landscape right? So you don't need to choose orientation variable but can be determined from size. Here is something quick it might work like you want it
 

EDIT: wrong code


But yeah a lot can be done here depending on what you have in the first place and want in the end. We are here building the code you posted, but for example if I knew all the details before, what options you need, I'd personally do a lot differently. And for a more "complete" solution this would take more time and testing, but I hope this helped a bit.

Edited by lastknownuser
Posted
8 minutes ago, lastknownuser said:


You can use the same block, and actually I wanted to mention that, by the paper size it is defined if its portrait or landscape right? So you don't need to choose orientation variable but can be determined from size. Here is something quick it might work like you want it
 

(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 papersize) 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)))
                )
	        (setq papersize (nth 3 x))
	        (cond ((or (= papersize "ISO full bleed A1 (841.00 x 594.00 MM)")
			   (= papersize "ISO full bleed A2 (594.00 x 420.00 MM)")
			   (= papersize "ISO full bleed A3 (420.00 x 297.00 MM)")
			   (= papersize "ISO full bleed A4 (297.00 x 210.00 MM)"))
		       (setq draworient "Landscape")
		       )
		      ((or (= papersize "ISO full bleed A1 (594.00 x 841.00 MM)")
			   (= papersize "ISO full bleed A2 (420.00 x 594.00 MM)")
			   (= papersize "ISO full bleed A3 (297.00 x 420.00 MM)")
			   (= papersize "ISO full bleed A4 (210.00 x 297.00 MM)"))
		       (setq draworient "Portrait")
		       )
		      );cond
                (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
                         "yes"
                         ""
                )
                (if (/= (caddr x) "Model")
                    (command "No" "No" file "no" "Yes")
                    (command
                        file
                        "no"
                        "Yes"
                    )
                )
            )
        )
    )
    (princ)
)


But yeah a lot can be done here depending on what you have in the first place and want in the end. We are here building the code you posted, but for example if I knew all the details before, what options you need, I'd personally do a lot differently. And for a more "complete" solution this would take more time and testing, but I hope this helped a bit.

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.  

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...