Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

plot lisp

lisaj98052
Enthusiast
Enthusiast

plot lisp

lisaj98052
Enthusiast
Enthusiast

I have this code that I that some else developed (Thank to who ever made this)it works great to plot all the tabs. I'm tryng to figure out a way to plot them to a specified folder. I'm rusty with coding use to be much better but I just don't use cad Autocad as much as I use too.

Seem like I need to add something like this

 

change C:test ( / cmd) to C:test ( / cmd pathn)

and this 

"(if (setq pathn (getfiled "C:\CADD\#####"))"   

 

That as far as I got not sure how to add this to the lisp below. I think it's the correct idea.

I have tried it a few different way and keep breaking the original that works.

;___________________________________________________________________________

(defun C:test ( / cmd)
(setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
(foreach Layout (layoutlist)
(command "_.-PLOT"
"No" ; Detailed plot configuration? [Yes/No] <No>: No
Layout ; Enter a layout name or [?] <Layout1>:
"" ; Enter a page setup name
"DWG To PDF.pc3" ; Enter an output device name or [?] <DWG To PDF.pc3>:
(strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save (strcat (getvar "DWGPREFIX") Layout ".pdf")
"No" ; save changes to page setup?
"Yes" ; proceed with plot?
); command
); foreach
(setvar 'cmdecho cmd)
(princ)
); defun C:test

0 Likes
Reply
6,422 Views
31 Replies
Replies (31)

maratovich
Advisor
Advisor

Maybe you can use a ready-made printing method?

Convenient and intuitive interface?

 

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

lisaj98052
Enthusiast
Enthusiast

if you are referring to sheet set, it is slow and combersome. you have to select each sheet individually to edit the data unless you export to excel and use a third party software to edit and reimport. I have started to use Autocad Core to do my plotting hands down faster. does not open each sheet. The only down side is it print to the dwg folder.

 

Thanks for the response.

 

0 Likes

maratovich
Advisor
Advisor

No, this is not a sheet set.

This is a ready-made program for printing.

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

Sea-Haven
Mentor
Mentor

Maratovich plotting routine is very extensive and better than this simple save somewhere.

 

 

; check that pdf directory exists
(setq dwgpre (strcat (getvar "dwgprefix") "\pdf"))
(if (= (vl-file-directory-p dwgpre) nil)
(vl-mkdir dwgpre)
)

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

 

0 Likes

Jonathan3891
Advisor
Advisor

I created this many years ago and I still use it today.

 

(defun c:iplot (/ psize)
   (initget 1 "11x17 24x36 PDF") ; [1 = no enter allowed]
   (setq psize (getkword (strcat "\nSelect Plot [11x17/24x36/PDF]:")))
   (cond
      ((= psize "11x17") (iplot_11x17))
      ((= psize "24x36") (iplot_24x36))
      ((= psize "PDF")  (iplot_PDF))
      )
	  )

(defun iplot_11x17 ()
    (command "-plot"
	     "yes"
	     ""
	     "default windows system printer.pc3" ;Printer Name
	     "11\" x 17\""  ;Paper Size
	     "Inches" ;Paper Units
	     "Landscape" ;Orientation
	     "No" ;Plot Upside Down?
	     "Extents" ;Plot Area
	     "Fit" ;Plot Scale
	     "Center" ;Plot Offset
	     "Yes" ;Use Plot Style?
	     "structural 11x17.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?
	     "Yes" ;Continue to Plot?
	     )
  )

(defun iplot_24x36 ()
    (command "-plot"
	     "yes"
	     ""
	     "OPDHP5100.pc3" ;Printer Name
	     "Arch D (Landscape)"  ;Paper Size
	     "Inches" ;Paper Units
	     "Landscape" ;Orientation
	     "No" ;Plot Upside Down?
	     "Extents" ;Plot Area
	     "1:1" ;Plot Scale
	     "Center" ;Plot Offset
	     "Yes" ;Use Plot Style?
	     "Structural 11x17.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?
	     "Yes" ;Continue to Plot?
	     )
  )

(defun iplot_PDF (/ fnm)
  (if (setq fnm (getfiled "Specify Save Location" "" "pdf" 1))
    (progn
    (command "-plot"
	     "yes"
	     ""
	     "Dwg To PDF.pc3" ;Printer Name
	     "ARCH D (36.00 x 24.00 Inches)"  ;Paper Size
	     "Inches" ;Paper Units
	     "Landscape" ;Orientation
	     "No" ;Plot Upside Down?
	     "Extents" ;Plot Area
	     "Fit" ;Plot Scale
	     "Center" ;Plot Offset
	     "Yes" ;Use Plot Style?
	     "Structural 11x17.ctb" ;Plot Style Name
	     "Yes" ;Plot Lineweights?
	     "No" ;Scale Lineweights?
	     "No" ;Paper Space First?
	     "No" ;Hide Paper Space?
	     fnm
	     "No" ;Plot to File?
	     "Yes" ;Continue to Plot?
	     )
    )
    )
  (princ)
  )

 


Jonathan Norton
Blog | Linkedin
0 Likes

Jonathan3891
Advisor
Advisor

This should do what you were going for in your original post.

 

(defun c:test (/)
  (foreach layout (layoutlist)
    (setvar 'CTab layout)
    (command "-plot"
	     "Y" ;Detailed Plot Configuration?
	     ""
	     "DWG To PDF.pc3" ;Printer Name
	     "ANSI B (11.00 x 17.00 Inches)" ;Paper Size
	     "Inches" ;Paper Units
	     "Landscape" ;Orientation
	     "No" ;Plot Upside Down?
	     "Extents" ;Plot Area
	     "Fit" ;Plot Scale
	     "Center" ;Plot Offset
	     "Yes" ;Plot With Plotstyle?
	     "monochrome.ctb" ;Plot Style Name
	     "yes" ;Plot Lineweights?
	     "No" ;Scale Lineweights?
	     "No" ;Hide Paper Space?
	     "No" ;Plot to File?
	     "" ;Name of File
	     "No" ;Save Page Setup?
	     "Yes" ;Continue to PLot?
	     )
    );foreach
  );defun

Jonathan Norton
Blog | Linkedin

Sea-Haven
Mentor
Mentor

Thanks Johnathan I have multiple plot options all based on the -Plot command including pdf, tiff, png

 

Plot range of layouts, plot individual pdfs but at same time make 1 pdf with all (hint Ghostscript) 

 

Even have a multi story building plot depending on who you are "username" will plot to correct plotter/printer on your floor so for all floors only have 1 program on server.

 

Enter like 99 and does all

screenshot306.png

0 Likes

Mike_Ishman
Observer
Observer

Jonathan; Your iplot LISP routine works great. I primarily only make pdf plots so I parced down your code to what is shown below (and attached). Instead on needing to select a folder directory to save the pdf too, I'd like to have the folder path already determined. How can I add in a specific folder directory for the save location of the pdf file?

 

;=================================================
;Partial code taken from iplot.lsp created by Jonathan Norton.
;This routine creates a pdf plot using the settings specified.
;This is an alternate to using the GUI of a page setup.
;=================================================

(defun C:plotpdf (/ fnm)
(if (setq fnm (getfiled "Specify Save Location" "" "pdf" 1))
(progn
(command "-plot"
"yes"
""
"Dwg To PDF.pc3" ;Printer Name
"ANSI D (34.00 x 22.00 Inches)" ;Paper Size
"Inches" ;Paper Units
"Landscape" ;Orientation
"No" ;Plot Upside Down?
"Window" ;Plot Area
"0.000000,0.000000" ;Lower left corner of window
"34.000000,22.000000" ;Upper right corner of window
"1:1" ;Plot Scale
"Center" ;Plot Offset
"Yes" ;Use Plot Style?
"BA_Standard.ctb" ;Plot Style Name
"Yes" ;Plot Lineweights?
"No" ;Scale Lineweights?
"No" ;Paper Space First?
"No" ;Hide Paper Space?
fnm
"No" ;Plot to File?
"Yes" ;Continue to Plot?
)
"\n:: Type "plotpdf" to run"
)
)
(princ)
)

0 Likes

Jonathan3891
Advisor
Advisor

Wow, this is a blast from the past! Let me edit the code and I'll get back to you!


Jonathan Norton
Blog | Linkedin
0 Likes

Jonathan3891
Advisor
Advisor

@Mike_Ishman give this a try.

 

You will need to update the path and reset the plot style name.

 

 

(defun C:plotpdf (/ fnm)

  (setq fnm (strcat "C:\\TEST\\" (vl-filename-base (getvar 'dwgname)) ".pdf")) ;Set Path & File Name

  ;Start Plotting
  (command "-plot"
	   "yes"
	   ""
	   "Dwg To PDF.pc3" ;Printer Name
	   "ANSI D (34.00 x 22.00 Inches)" ;Paper Size
	   "Inches" ;Paper Units
	   "Landscape" ;Orientation
	   "No" ;Plot Upside Down?
	   "Window" ;Plot Area
	   "0.000000,0.000000" ;Lower left corner of window
	   "34.000000,22.000000" ;Upper right corner of window
	   "1:1" ;Plot Scale
	   "Center" ;Plot Offset
	   "Yes" ;Use Plot Style?
	   "monochrome.ctb" ;Plot Style Name
	   "Yes" ;Plot Lineweights?
	   "No" ;Scale Lineweights?
	   "No" ;Paper Space First?
	   "No" ;Hide Paper Space?
	   fnm
	   "No" ;Plot to File?
	   "Yes" ;Continue to Plot?
	   )
  "\n:: Type "plotpdf" to run"
  (princ)
);defun

 

 

 


Jonathan Norton
Blog | Linkedin
0 Likes

Sea-Haven
Mentor
Mentor

Another makes a pdf directory under the dwg location.

 

;Plots layouts by range
; By Alan H Feb 2014

(defun AH:pltlays ( / val1 val2 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))

) ; end repeat

) ; defun

(AH:pltlays)


(princ)

 

0 Likes

Mike_Ishman
Observer
Observer

Worked perfect, thank you.

kthmarks
Contributor
Contributor

@Jonathan3891 If you don't mind....I'm working through one of these, what part of your lisp tells the routine to ignore overwriting an existing pdf?  I have a simple routine the plots only specific named layouts but hangs when there is an existing file.

 

(defun C:RRR ( / cmd)
(setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
(foreach Layout (List "Cover Page" "Demo")
(command "_.-PLOT"
"No" ; Detailed plot configuration? [Yes/No] <No>: No
Layout ; Enter a layout name or [?] <Layout1>:
"" ; Enter a page setup name
"DWG To PDF.pc3" ; Enter an output device name or [?] <DWG To PDF.pc3>:
(strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save (strcat (getvar "DWGPREFIX") Layout ".pdf")
"No" ; save changes to page setup?
"Yes" ; proceed with plot?
); command
); foreach
(setvar 'cmdecho cmd)
(princ)
)

0 Likes

paullimapa
Mentor
Mentor

review the plot sequence of commands very carefully and you're see where your error is:

paullimapa_0-1728936019596.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

ec-cad
Advocate
Advocate

If it is stopping because the .dxf file exists, you need to either 'delete' the .dxf, or check if it exists.

Here's a sample route to check if it exists. It's up to you to 'delete' it if you are updating it.

You could use (vl-delete fname) if updating.

 

 

 

(defun C:RRR ( / cmd)
 (setq cmd (getvar 'cmdecho))
 (setvar 'cmdecho 0)
 (foreach Layout (List "Cover Page" "Demo")
  (setq fname (strcat (getvar "DWGPREFIX") Layout ".pdf"))
  (if (not (findfile fname))
   (progn
    (command "_.-PLOT"
       "No" ; Detailed plot configuration? [Yes/No] <No>: No
       Layout ; Enter a layout name or [?] <Layout1>:
        "" ; Enter a page setup name
        "DWG To PDF" ; Enter an output device name or [?] <DWG To PDF.pc3>:
        (strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save (strcat (getvar "DWGPREFIX") Layout ".pdf")
        "No" ; save changes to page setup?
        "Yes" ; proceed with plot?
     ); command
    ); progn
   ); if
); foreach
 (setvar 'cmdecho cmd)
 (princ)
)

 

 

ECCAD

0 Likes

kthmarks
Contributor
Contributor

wow.  Thanks guys for the responses.  I got two completely different directions here.  @paullimapa the routine works with the correct file/layout names.  It just errors when the file exists so I'm not sure to look for my mistake.

@ec-cad I loaded your routine and if the file does exist, if just does nothing, Maybe a message that says file exists, do you want to overwrite?  I have no clue how to do that.  I was hoping it would just be a Y/N in the command string somewhere.

0 Likes

paullimapa
Mentor
Mentor

Curious as to what version of AutoCAD you're using. In older versions I've notice the PLOT sequence may not work if the output file exists. I would have to code in a sequence to check and delete the existing output file name.

I've tested in 2020 through 2025 and now the plot sequence actually automatically overwrites existing matching output file names. Your existing C:RRR code works flawlessly as long as you do have layout names matching "Cover Page" and "Demo".

So I'm not sure if your problem relates to current versions of AutoCAD. But I've included the sections of code that would do the check and delete the matching output file in your system. Hopefully you have permissions to delete and make sure the PDF file is NOT currently opened by any viewer:

; RRR plot list of layouts 
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/plot-lisp/m-p/13085554#M473012
(defun C:RRR ( / cmd)
(vl-load-com) ; load vl functions
(setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
(foreach Layout (List "Cover Page" "Demo")
(if (findfile (strcat (getvar "DWGPREFIX") Layout ".pdf")) ; check if file exists
 (progn ; then delete it
  (princ (strcat "\nFile Exists will Delete: " (strcat (getvar "DWGPREFIX") Layout ".pdf"))) ; print message
  (vl-file-delete (strcat (getvar "DWGPREFIX") Layout ".pdf")) ; delete file
 )
)
(command "_.-PLOT"
"No" ; Detailed plot configuration? [Yes/No] <No>: No
Layout ; Enter a layout name or [?] <Layout1>:
"" ; Enter a page setup name
"DWG To PDF.pc3" ; Enter an output device name or [?] <DWG To PDF.pc3>:
(strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save (strcat (getvar "DWGPREFIX") Layout ".pdf")
"No" ; save changes to page setup?
"Yes" ; proceed with plot?
); command
); foreach
(setvar 'cmdecho cmd)
(princ)
)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

ec-cad
Advocate
Advocate

Paulli,

Your solution doesn't 'ask' if OP wants to delete the file.

Perhaps this method will work, if OP needs that feature.

Untested.

 

(defun C:RRR ( / cmd)
 (setq cmd (getvar 'cmdecho))
 (setvar 'cmdecho 0)
 (foreach Layout (List "Cover Page" "Demo")
  (setq fname (strcat (getvar "DWGPREFIX") Layout ".pdf"))
   (if (findfile fname) ; check if file exists
    (progn
     (setq ans (strcase (getstring (strcat "\nFile " fname " exists, do you want to over-write it ? Y or N <Y>:"))))
      (if (or (= ans "")(= ans nil)(= ans "Y")); then delete it
        (progn
          (princ (strcat "\nDeleted File: " fname)) ; print message
          (vl-file-delete fname); delete file
        ); progn
       ); if
      (if (= ans "N")
       (princ (strcat "\nSkipping Existing File: " fname)) ; print message
      ); if
     ); progn
    ); if

;; Continue with Plot if .pdf file does not exist..
  (if (not (findfile fname))
   (progn
    (command "_.-PLOT"
       "No" ; Detailed plot configuration? [Yes/No] <No>: No
       Layout ; Enter a layout name or [?] <Layout1>:
        "" ; Enter a page setup name
        "DWG To PDF" ; Enter an output device name or [?] <DWG To PDF.pc3>:
        (strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save (strcat (getvar "DWGPREFIX") Layout ".pdf")
        "No" ; save changes to page setup?
        "Yes" ; proceed with plot?
     ); command
    ); progn
   ); if
); foreach
 (setvar 'cmdecho cmd)
 (princ)
)

 

ECCAD

0 Likes

paullimapa
Mentor
Mentor

As OP stated

ā€œwhat part of your lisp tells the routine to ignore overwriting an existing pdf?ā€

I interpret ā€œignore overwritingā€ to mean delete without prompting 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes