LISP To Plot Layout Tabs In Order

LISP To Plot Layout Tabs In Order

Anonymous
Not applicable
5,344 Views
13 Replies
Message 1 of 14

LISP To Plot Layout Tabs In Order

Anonymous
Not applicable
Hello, I have a very simple LISP routine that iterates through each layout tab in AutoCAD, and plots them via "command". Simple! It works just fine, but the layouts are being plotted in Alphabetical order as opposed to the order they are in AutoCAD! Here is the LISP that I am running... (defun c:PLOTALL (/ ) (foreach layoutname (layoutlist ) (command "._layout" "set" layoutname ) (command "-plot" "yes" layoutname "Canon iR-ADV C5045/5051 UFR II" ;printer name "11x17" ;paper size "Inches" ;paper units "Landscape" ;Orientation "No" ;Plot upsidedown "Extents" ;Plot area "Fit" ;Plot scale "Center" ;Plot offset "Yes" ;Use plot styles? "Black.ctb" ;plot style name "Yes" ;Plot lineweights? "No" ;Scale lineweights? "No" ;paper space first? "No" ;Hide paper space? "No" ;Plot to file? "No" ;Save page setup? "Y" ;Continue to plot? ) ) end defun ) Attached is also the LISP file if needed... Is there a solution that I might be able to use to make the command plot the layouts in the order they appear in AutoCAD as opposed to alphabetical order? --Thanks as always!
0 Likes
Accepted solutions (1)
5,345 Views
13 Replies
Replies (13)
Message 2 of 14

hmsilva
Mentor
Mentor
Accepted solution

Hi TomTom111,

 

change

(foreach layoutname (layoutlist)

 

to

(vl-load-com)
(vlax-for layt (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
  (if (> (vla-get-TabOrder layt) 0)
    (setq layt_lst (cons (cons (vla-get-TabOrder layt) (vla-get-Name layt)) layt_lst))
  )
)
(setq layt_lst (vl-sort layt_lst '(lambda (x y) (< (car x) (car y)))))
(foreach layt layt_lst
  (setq layoutname (cdr layt))

 

 

Hope this helps,
Henrique

EESignature

Message 3 of 14

Anonymous
Not applicable
Works like a charm. Thanks for the quick reply!
0 Likes
Message 4 of 14

hmsilva
Mentor
Mentor

@Anonymous wrote:
Works like a charm. Thanks for the quick reply!

You're welcome, TomTom111
Glad I could help

Henrique

EESignature

0 Likes
Message 5 of 14

Anonymous
Not applicable
So upon using the code, i find that it prints each sheet twice before continuing to the next layout. I'm not able to see where the code is making this error. Sorry for the copy/paste of my code, but my insert code button will not show up, and i can't figure it out for the life of me! I will also attach the lisp file. (defun c:PLOTALL (/ ) (vl-load-com) (vlax-for layt (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object))) (if (> (vla-get-TabOrder layt) 0) (setq layt_lst (cons (cons (vla-get-TabOrder layt) (vla-get-Name layt)) layt_lst)) ) ) (setq layt_lst (vl-sort layt_lst '(lambda (x y) (< (car x) (car y))))) (foreach layt layt_lst (setq layoutname (cdr layt)) (command "._layout" "set" layoutname ) (command "-plot" "yes" layoutname "Canon iR-ADV C5045/5051 UFR II" ;printer name "11x17" ;paper size "Inches" ;paper units "Landscape" ;Orientation "No" ;Plot upsidedown "Extents" ;Plot area "Fit" ;Plot scale "Center" ;Plot offset "Yes" ;Use plot styles? "Black.ctb" ;plot style name "Yes" ;Plot lineweights? "No" ;Scale lineweights? "No" ;paper space first? "No" ;Hide paper space? "No" ;Plot to file? "No" ;Save page setup? "Y" ;Continue to plot? ) ) )
0 Likes
Message 6 of 14

hmsilva
Mentor
Mentor

@Anonymous wrote:
So upon using the code, i find that it prints each sheet twice before continuing to the next layout. I'm not able to see where the code is making this error. Sorry for the copy/paste of my code, but my insert code button will not show up, and i can't figure it out for the life of me! I will also attach the lisp file.

Hi TomTom111,

 

I dond't have AutoCAD, to test your code, but,

 

  1. When we are dealing with lists, it is advisable to localize our variables...
  2. You don't need to set the layout, prior to -plot command, when plotting a Layout, the plot command, will set that layout.

Test the following (untested) code.

 

(defun c:PLOTALL (/ layoutname layt_lst)
  (vl-load-com)
  (vlax-for layt (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
    (if (> (vla-get-TabOrder layt) 0)
      (setq layt_lst (cons (cons (vla-get-TabOrder layt) (vla-get-Name layt)) layt_lst))
    )
  )
  (setq layt_lst (vl-sort layt_lst '(lambda (x y) (< (car x) (car y)))))
  (foreach layt layt_lst
    (setq layoutname (cdr layt))
    ;(command "._layout" "set" layoutname)
    (command "-plot"
             "yes"
             layoutname
             "Canon iR-ADV C5045/5051 UFR II" ;printer name
             "11x17" ;paper size
             "Inches" ;paper units
             "Landscape" ;Orientation
             "No" ;Plot upsidedown
             "Extents" ;Plot area
             "Fit" ;Plot scale
             "Center" ;Plot offset
             "Yes" ;Use plot styles?
             "Black.ctb" ;plot style name
             "Yes" ;Plot lineweights?
             "No" ;Scale lineweights?
             "No" ;paper space first?
             "No" ;Hide paper space?
             "No" ;Plot to file?
             "No" ;Save page setup?
             "Y" ;Continue to plot?
            )
  )
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 7 of 14

Anonymous
Not applicable

A while ago I was searching and ended up using this sort of code to do exactly what is required here. I can't remember but this may have even been the exact post I come across.

 

Turns out I now have a need to use the same routines I created but only on a select bunch of the multiple layouts in the file. For example in a drawing of 50 layout tabs the user might only want to layouts 1, 12,13 and 32. I realise publish can do this but I want my staff to use this routine which pre sets print settings.

 

Ideally a dialogue box allowing users to pick from a list would work best.

 

Hope this is not a big change.

 

Regards,

0 Likes
Message 8 of 14

Homecad2007
Enthusiast
Enthusiast

Hi there did you ever get a lisp routine to work for this?  I was looking for the same type of idea

0 Likes
Message 9 of 14

Homecad2007
Enthusiast
Enthusiast

Hi there did you ever get a lisp routine to work for this?  I was looking for the same type of idea

 

Thanks

Tony

0 Likes
Message 10 of 14

Sea-Haven
Mentor
Mentor

I did a bit different plot a range if you put a big number for last will do all. This is a pdf version but just replace the plot part.

 

;Plots layouts by range
; By Alan H Feb 2014

(defun AH:pltlays ( / val1 val2 plotnames dwgname lendwg pdfname lay numlay numend dwgpre)
(SETVAR "PDMODE" 0)
(setvar "plottransparencyoverride" 2)
(setvar "fillmode" 1)
(setvar "textfill" 1)
(setq plotnames '())

; check that pdf directory exists
(setq dwgpre (strcat (getvar "dwgprefix") "\pdf"))
(if (= (vl-file-directory-p dwgpre) nil)
(vl-mkdir dwgpre)
)
(SETQ LAYOUTS (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))
(SETQ COUNT (- (VLA-GET-COUNT LAYOUTS) 1))

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq vals (AH:getvalsm  (list "Enter plot range" "Enter start tab number" 6 4 "1" "Enter end tab number" 6 4 (RTOS COUNT 2 0))))

(setq numlay (atoi (nth 0 vals)))
(setq numend (atoi (nth 1 vals)))

(setq len (+ (- numend numlay) 1))

(setq dwgname (GETVAR "dwgname"))
(setq lendwg (strlen dwgname))
(setq dwgname (substr dwgname 1 (- lendwg 4)))

(repeat len
(vlax-for lay LAYOUTS
(if (= numlay (vla-get-taborder lay))
  (setvar "ctab" (vla-get-name lay))
) ; if

(setq pdfname (strcat dwgpre "\\" dwgname "-" (getvar "ctab") ".pdf" ))
) ; for

(setvar "textfill" 1)
(setvar "fillmode" 1)
(setvar "PLOTTRANSPARENCYOVERRIDE" 2)
    (COMMAND "-PLOT"  "Y"  "" "dwg to Pdf"
	       "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE"  "N"   "W"  "-6,-6" "807,560" "1=2"  "C"
	       "y" "Acad.ctb" "Y"	"n" "n" "n" pdfName "N" "y"
    )
    
(setq numlay (+ numlay 1))
(setq plotnames (cons pdfname plotnames))
) ; end repeat
(setq trgfile (strcat (getvar "dwgprefix") "pdf\\" dwgname "-D" (nth 0 vals) "-D" (nth 1 vals) ".pdf"))

(setq plotnames (reverse plotnames))

(IF (= (length plotnames) 1)
(princ)
(progn
(if (not combinepdf)(load "mergepdfs"))
(combinepdf gsExe plotnames trgFile )
)
)

) ; defun

(AH:pltlays)


(princ)

 Needs the multi getvals for the pop updcl. 

0 Likes
Message 11 of 14

maratovich
Advisor
Advisor

@Homecad2007 wrote:

Hi there did you ever get a lisp routine to work for this?  I was looking for the same type of idea


Use this - Revers 

You can choose any sort.

Any file name can be specified.

 

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

john.uhden
Mentor
Mentor

Pardon me for chiming in so late (as in after the fact), but how about using Sheet Set Manager?  Then just publish.

John F. Uhden

0 Likes
Message 13 of 14

Homecad2007
Enthusiast
Enthusiast

Thanks for your reply...so I created sheets using the sheet manager in the template file I have.  I Published the set and saved a DSD file.

In my lisp routine I call the dsd file but it is printing the sheets from the template file that are of course blank.  How do I print the the sheet names in the current file that I am in.

Example I want A1, A2 A3 and A4 layouts printed all together in PDF for every drawing.  Still not sure the best way to do this

 

Thanks in advance

Tony

0 Likes
Message 14 of 14

Sea-Haven
Mentor
Mentor

A1, A2 and A3 can be done starting with A1 and using scale, A3 is 1:2 of a A1. A4 would be done as a Portrait where as other sizes are Landscape. I have never come across a mix of sheet sizes if we had std detail dwgs in A4  size would insert into a A1, 4 fit. Then all would plot at A1 etc. If we wanted A4 would print those as a sperate set.

 

I dont use publish sheetsets but have single dwg's so have a menu with about 5 options preset with sheet size and correct printer/plotter.

0 Likes