Batch Plot to pdf in model space

Batch Plot to pdf in model space

Anonymous
Not applicable
26,091 Views
76 Replies
Message 1 of 77

Batch Plot to pdf in model space

Anonymous
Not applicable

Please help me, 

I want to know is there any lisp for printing multiple blocks to pdf at once?
I have hundreds of drawing and each drawing have many title blocks in model/Layout in different size (all title blocks are in blocks named A1). So if i use publish command, i have to open all 100 drawings and make page setup for all title blocks. It is waste of time. So i am looking for a program which print a specific  blocks one by one (instead of selecting a window/layout/extends) in model or layout converting to pdf at once. Hope you understand the matter. Help would be appreciated (I am really sorry for my poor English).
0 Likes
Accepted solutions (2)
26,092 Views
76 Replies
Replies (76)
Message 2 of 77

paullimapa
Mentor
Mentor

So apparently the person who set all these title blocks up in model space & paper space with different scales really need to be trained to do it properly and consistantly. Since there is no consistancy, there is no lisp routine that can do this automated for you. You would have to open each drawing and set it all up properly so you can use the Publish command the next go around.

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 77

hmsilva
Mentor
Mentor

@Anonymous wrote:

Please help me, 

I want to know is there any lisp for printing multiple blocks to pdf at once?
I have hundreds of drawing and each drawing have many title blocks in model/Layout in different size (all title blocks are in blocks named A1). So if i use publish command, i have to open all 100 drawings and make page setup for all title blocks. It is waste of time. So i am looking for a program which print a specific  blocks one by one (instead of selecting a window/layout/extends) in model or layout converting to pdf at once. Hope you understand the matter. Help would be appreciated (I am really sorry for my poor English).

Hello arukaroor and welcome to the Autodesk Community!

 

Firstly, I fully agree with Paul Li's.

 

To plot one dwg at a time, and ss a starting point, if your title blocks are not dynamic, perhaps something like this will do the trick...

Untested...

 

(vl-load-com)
(defun c:demo (/ dwg file hnd i len llpt lst mn mx sc ss tab urpt)
    (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "A1"))))
        (progn
            (repeat (setq i (sslength ss))
                (setq hnd (ssname ss (setq i (1- i)))
                      tab (cdr (assoc 410 (entget hnd)))
                      lst (cons (cons tab hnd) lst)
                )
            )
            (setq lst (vl-sort lst '(lambda (x y) (> (car x) (car y)))))
            (setq i 0)
            (foreach x lst
                (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 (cdr x)) 'mn 'mx)
                (setq llpt (vlax-safearray->list mn)
                      urpt (vlax-safearray->list mx)
                      len  (distance llpt (list (car urpt) (cadr llpt)))
                      sc   (fix (/ 841.0 len))
                )
                (command "-plot"
                         "yes"
                         (car x)
                         "DWG TO PDF.PC3"
                         "ISO A1 (841.00 x 594.00 MM)"
                         "Millimeters"
                         "Landscape"
                         "No"
                         "Window"
                         llpt
                         urpt
                         (strcat (itoa sc) ":1")
                         "Center"
                         "yes"
                         "grayscale.ctb"
                         "yes"
                         ""
                )
                (if (/= (car x) "Model")
                    (command "No" "No" file "no" "Yes")
                    (command
                        file
                        "no"
                        "Yes"
                    )
                )
            )
        )
    )
    (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 4 of 77

Anonymous
Not applicable

Hi hmsilva,

Thanks for your replay.

I copy this code and paste in to a notepad then save as .lsp file. after i load and type demo but its not working. Actually i dont have deep knowledge in lisp. Can u tell me is there any way to load this.

0 Likes
Message 5 of 77

hmsilva
Mentor
Mentor

Could you please attach a sample dwg?

 

Henrique

EESignature

0 Likes
Message 6 of 77

Anonymous
Not applicable

Here is the drawing.

0 Likes
Message 7 of 77

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Here is the drawing.


arukaroor,

are all dwg's in A3, and all in Model space?

 

(vl-load-com)
(defun c:demo (/ dwg file hnd i len llpt lst mn mx ss tab urpt)
    (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "A1-"))))
        (progn
            (repeat (setq i (sslength ss))
                (setq hnd (ssname ss (setq i (1- i)))
                      tab (cdr (assoc 410 (entget hnd)))
                      lst (cons (cons tab hnd) lst)
                )
            )
            (setq lst (vl-sort lst '(lambda (x y) (> (car x) (car y)))))
            (setq i 0)
            (foreach x lst
                (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 (cdr 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 A3 (420.00 x 297.00 MM)"
                         "Millimeters"
                         "Landscape"
                         "No"
                         "Window"
                         llpt
                         urpt
                         "Fit"
                         "Center"
                         "yes"
                         "grayscale.ctb"
                         "yes"
                         ""
                )
                (if (/= (car x) "Model")
                    (command "No" "No" file "no" "Yes")
                    (command
                        file
                        "no"
                        "Yes"
                    )
                )
            )
        )
    )
    (princ)
)

 

 

Henrique

 

EESignature

Message 8 of 77

Anonymous
Not applicable

 

hmsilva,

Some times i have to print in A1 and some times in A2 or A3. So i am suggesting to make pdf all in A1 size so i can print any size. In this drawing all title blocks are in model but some other drawings in layout. Smiley Sad

0 Likes
Message 9 of 77

Anonymous
Not applicable

Woowww its working..Smiley Very Happy

Thank you very much.

Can you add an option to select model / layout and page size also.

0 Likes
Message 10 of 77

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Woowww its working..Smiley Very Happy

Thank you very much.

Can you add an option to select model / layout and page size also.


arukaroor,

the demo will plot also layouts, if the "A1-" block exist.

Paper sizes, correct scale.... I could not find in your titleblock something that allows the code to select the correct paper size/scale...

 

Henrique

EESignature

0 Likes
Message 11 of 77

Anonymous
Not applicable

hmsilva,

 

I modified the paper size and ctb. Now i can plot any size and any block. You saved my time Man Very HappyMan Very HappyMan Very Happy

 

Thanks a lot........

0 Likes
Message 12 of 77

hmsilva
Mentor
Mentor

@Anonymous wrote:

hmsilva,

 

I modified the paper size and ctb. Now i can plot any size and any block. You saved my time Man Very HappyMan Very HappyMan Very Happy

 

Thanks a lot........


You're welcome, arukaroor

Glad it's useful for you! 🙂

 

Henrique

EESignature

Message 13 of 77

Anonymous
Not applicable

Dear Henrique,

 

Thank for the code.

 

Can you please help by changing the same code to give print to a printer instead of pdf.

 

Regards,

Fred

0 Likes
Message 14 of 77

WauterM.
Explorer
Explorer

Thanks a lot for this piece of code ! 

 

My company still plots the production drawings in modelspace but with this tool i'm winning a lot of time. (considering 50+ drawings per project)

I was just wondering if there is a way to ajust this too only print blocks that are selected ?

So if I for instance have layoutblocks for an A4 print and for an A3 print, I can do those seperatly?

 

I'm not familiar with the syntax of Lisp otherwise I would have just edited your code.

 

Greets,

 

Wauter

 

 

0 Likes
Message 15 of 77

kajanthangavel
Advocate
Advocate

it working. thank a lot. but it plotting reverse order.  how can i change plot order


@hmsilva wrote:

@Anonymous wrote:

Here is the drawing.


arukaroor,

are all dwg's in A3, and all in Model space?

 

(vl-load-com)
(defun c:demo (/ dwg file hnd i len llpt lst mn mx ss tab urpt)
    (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "A1-"))))
        (progn
            (repeat (setq i (sslength ss))
                (setq hnd (ssname ss (setq i (1- i)))
                      tab (cdr (assoc 410 (entget hnd)))
                      lst (cons (cons tab hnd) lst)
                )
            )
            (setq lst (vl-sort lst '(lambda (x y) (> (car x) (car y)))))
            (setq i 0)
            (foreach x lst
                (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 (cdr 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 A3 (420.00 x 297.00 MM)"
                         "Millimeters"
                         "Landscape"
                         "No"
                         "Window"
                         llpt
                         urpt
                         "Fit"
                         "Center"
                         "yes"
                         "grayscale.ctb"
                         "yes"
                         ""
                )
                (if (/= (car x) "Model")
                    (command "No" "No" file "no" "Yes")
                    (command
                        file
                        "no"
                        "Yes"
                    )
                )
            )
        )
    )
    (princ)
)

 

 

Henrique

 



?

0 Likes
Message 16 of 77

maratovich
Advisor
Advisor

Attach an example of your title block file.

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 17 of 77

kajanthangavel
Advocate
Advocate

There it that sample file.

0 Likes
Message 18 of 77

maratovich
Advisor
Advisor

 

 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
Message 19 of 77

Anonymous
Not applicable

i got this error after using obove lisp

on the dwg uploded above 

 

Command: DEMO
Unknown command "DEMO". Press F1 for help.

Command: C:\Users\ali.usman\Downloads\NDW9578-17.pdf Unknown command "USMAN\DOWNLOADS\NDW9578-17.PDF". Press F1 for help.

Command: no Unknown command "NO". Press F1 for help.

Command: Yes Unknown command "YES". Press F1 for help.

0 Likes
Message 20 of 77

maratovich
Advisor
Advisor

Try this : Revers - Automatic batch printing

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes