Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Batch Plot to pdf in model space

76 REPLIES 76
SOLVED
Reply
Message 1 of 77
Anonymous
16916 Views, 76 Replies

Batch Plot to pdf in model space

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).
76 REPLIES 76
Message 2 of 77
paullimapa
in reply to: Anonymous

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
Message 3 of 77
hmsilva
in reply to: Anonymous


@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

Message 4 of 77
Anonymous
in reply to: hmsilva

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.

Message 5 of 77
hmsilva
in reply to: Anonymous

Could you please attach a sample dwg?

 

Henrique

EESignature

Message 6 of 77
Anonymous
in reply to: hmsilva

Here is the drawing.

Message 7 of 77
hmsilva
in reply to: Anonymous


@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
in reply to: hmsilva

 

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

Message 9 of 77
Anonymous
in reply to: Anonymous

Woowww its working..Smiley Very Happy

Thank you very much.

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

Message 10 of 77
hmsilva
in reply to: Anonymous


@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

Message 11 of 77
Anonymous
in reply to: hmsilva

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

Message 12 of 77
hmsilva
in reply to: Anonymous


@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
in reply to: hmsilva

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

Message 14 of 77
WauterM.
in reply to: hmsilva

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

 

 

Message 15 of 77
kajanthangavel
in reply to: hmsilva

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

 



?

Message 16 of 77
maratovich
in reply to: kajanthangavel

Attach an example of your title block file.

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
Message 17 of 77
kajanthangavel
in reply to: maratovich

There it that sample file.

Message 18 of 77
maratovich
in reply to: kajanthangavel

 

 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
Message 19 of 77
Anonymous
in reply to: hmsilva

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.

Message 20 of 77
maratovich
in reply to: Anonymous

Try this : Revers - Automatic batch printing

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta