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

plot lisp

31 REPLIES 31
Reply
Message 1 of 32
lisaj98052
6724 Views, 31 Replies

plot lisp

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

Labels (2)
31 REPLIES 31
Message 21 of 32
ec-cad
in reply to: paullimapa

You could be correct on that. OP can make a choice.

 

ECCAD

Message 22 of 32
kthmarks
in reply to: paullimapa

@paullimapa I'm using 2024.  But...in retrospect, I may have had the pdf files open which is why I was getting inconstant results.  If so...I am an idiot.  I don't do this all the time so I'm grateful for this forum and guys like you and @ec-cad  for taking the time to help me.

Message 23 of 32
paullimapa
in reply to: kthmarks

glad you got it resolved...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 24 of 32
kthmarks
in reply to: lisaj98052

@paullimapa you are correct, I didn't think to have a promp tasking overwrite the files.  So now that I have it, I think it's the way to go.  @ec-cad, thanks for writing this for me.  One of these days, I'll get the hang of it, vlide helps, but not enough.

Message 25 of 32
ec-cad
in reply to: kthmarks

Don't dispare. I've been coding Lisp for about 39 years now. So, you just need a bit more practice.

If you think that Paulli or I solved the issue, please mark it so.

 

ECCAD

 

Message 26 of 32
kthmarks
in reply to: lisaj98052

Yes, thank you I will....lastly, if I want to add the file name + layout to the pdf, why wouldn't the below line work?

(setq file (strcat (getvar "DWGPREFIX") Layout ".pdf") (vl-filename-base (getvar 'dwgname)) ".pdf")) ;Name of file

VLIDE says....; error: bad variable name in SETQ: (VL-FILENAME-BASE (GETVAR ( ... )))

Message 27 of 32
kthmarks
in reply to: lisaj98052

@ec-cad PS...I don't see that the "Solution" button is available.  Maybe because this is an old thread?  I tagged at as new but don't see that it's available.

Message 28 of 32
DGCSCAD
in reply to: lisaj98052

The syntax is a bit off in your filename + layout code.

Here's a version based off of @ec-cad 's penned code. It incorporates Lee Mac's "check if a PDF is open", and also uses the correct syntax for adding the filename + layout:

 

I have not tested this, but it should be ok...

 

(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

	  (if (_FileOpen-p fname) 									; Check to see if the PDF is open
	      (princ (strcat "\nPDF file " fname " is currently in use. Please close the file."))	; if yes, then prompt
	      (progn 											; if not, then delete
                (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") (vl-filename-base (getvar "dwgname")) "-" Layout ".pdf") ; Directory to save
        "No" ; save changes to page setup?
        "Yes" ; proceed with plot?
     ); command
    ); progn
   ); if
); foreach
 (setvar 'cmdecho cmd)
 (princ)
)

(defun _FileOpen-p ( filename )
  (not (vl-file-rename filename filename))
)

 

Code from Lee Mac thread:

https://www.cadtutor.net/forum/topic/32298-i-need-a-way-to-check-if-a-pdf-file-is-open/

 

AutoCad 2018 (full)
Win 11 Pro
Message 29 of 32
paullimapa
in reply to: kthmarks

If your purpose is to include the dwg filename before the layout name then change the line of code to:

(setq file (strcat (getvar "DWGPREFIX")(vl-filename-base (getvar 'dwgname)) Layout ".pdf")) ;Name of file and layout name 

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 30 of 32
ec-cad
in reply to: kthmarks

vl-filename-base  - is expecting just the layoutname.pdf, not including the Path I think.

Would return just 'layoutname - without the .pdf

I could be wrong on that, just paste (setq file (strcat (vl-filename-base (getvar 'dwgname)) ".pdf"))

to the Command Line, and see what it does.

If 'Layout contains a string value of the Layout needed, then the first part of that line :

 (setq file (strcat (getvar "DWGPREFIX") Layout ".pdf")) ;     note added ) on end..

Adds the 'layout already, so it would return something like:  "C:\\myfolder\\layoutname.pdf"

into the variable 'file

 

I see Paulli has you covered for drawingname + layout..

ECCAD

Message 31 of 32
ec-cad
in reply to: kthmarks

I don't think you really want the 'dwgprefix at all. If you want the output file = dwgname_layout.pdf

Try this one:

(setq file (strcat (vl-filename-base (getvar 'dwgname)) "_" layout  ".pdf")) ;Name of file

Should return file = "yourdrawing_layout.pdf".

You would need to append the 'dwgprefix to generate a filename to check if exists.

e.g.

(setq outfile (strcat (getvar 'dwgprefix)(vl-filename-base (getvar 'dwgname)) "_" layout  ".pdf"))

Note: the 'dwgprefix will have "\\" on the end automatically.

That would return something like:

"c:\\folder\\yourdrawing_layout.pdf"

 

ECCAD

Message 32 of 32
Sea-Haven
in reply to: lisaj98052

Just a comment we plot single pdf's and use a plot lisp, you can though use Ghostscript to rejoin all the pdf's back into one pdf. The joining is done via lisp. 

 

Here is an example. Does plot layouts by range so can do 1 or as many as you have. Needs Multi getvals.lsp

SeaHaven_0-1729035977392.png

Just add the correct file name code.

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report