Can't figure out what's wrong with this LISP

Can't figure out what's wrong with this LISP

Anonymous
Not applicable
2,054 Views
12 Replies
Message 1 of 13

Can't figure out what's wrong with this LISP

Anonymous
Not applicable

Hello,

 

I would describe my LISP skills as very rudimentary if that at all.  I wrote this LISP trying to simplify the plotting procedure for something I do several times a day, but it doesn't seem to work.  When I type everything in the command line, it works all the way up to the "savename" variable I created.  Currently, when the LISP finishes running, it gives me a prompt for the file name and I thought the "savename" variable I created would automatically create this name.  Anybody have any ideas as to how to fix this?

 

Directory the CAD file I would work from would be like this:
C:\Work\LISP_TEST\CAD\FAV

Directory the PDF would be automatically placed would be like this:

C:\Work\LISP_TEST\PDF\FAV

The PDF name should be identical to the DWG file name.

 

 

 

 

(defun c:CU ( / ppath newpath savename)
(vl-load-com)
(setvar "filedia" 0)
(setq ppath (getvar "dwgprefix"))
(setq newpath (vl-string-subst "\\PDF\\" "\\CAD\\" ppath))
(setq savename (strcat newpath (vl-filename-base (getvar "dwgname"))))
(command "-export"
"p"
"c"
"n"
savename
)
(setvar "filedia" 1)
(princ)
)

0 Likes
Accepted solutions (1)
2,055 Views
12 Replies
Replies (12)
Message 2 of 13

Satish_Rajdev
Advocate
Advocate

Your savename variable is missing this :

(setq savename (strcat newpath "\\" (vl-filename-base (getvar "dwgname"))))

Do you want to export PDF? If yes then why did you assign "C" in the below line? Because AutoCAD offers other option which doesn't start from "C".

(command "-export" "p" "c" "n" savename)

Command:-EXPORT
Enter file format [Dwf/dwfX/Pdf] <dwfX>p
Enter plot area [Display/Extents/Window] <Window>:

Please let me know your goal, what exactly you want to export? 

 

Best Regards,
Satish Rajdev


REY Technologies | Linked IN | YouTube Channel


 

0 Likes
Message 3 of 13

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

When I type everything in the command line, it works all the way up to the "savename" variable I created.  Currently, when the LISP finishes running, it gives me a prompt for the file name and I thought the "savename" variable I created would automatically create this name.  Anybody have any ideas as to how to fix this?


Are you sure "it works" when typed at the command line?

Your savename variable does indeed contain the filename to be created (but not totally acurate)

But it still prompt for it, because its failing before it gets there.

As "C" is NOT a valid option for the PDF export, its rejected and the next response is evaluated, which again is NOT a correct response for (Display,Extents,Window), then it evaluates your filename as a third "attempt" which of course is still not correct. (but it might continue after, as D,E & W are more likely to be part of it). Only then does the function continue to the next question, but you are out of responses ...

 

@Satish_Rajdev already pointed out the flaws, but for some reference, here's part of what i use for creating PDF's, which has a little extra. My DWG's are either a single drawing drawn in modelspace, or a set of drawings drawn in paperspace.

 

This routine checks which is active & plots either the single modelspace or all layouts.

I changed the export path to reflect yours. For modelspace it uses the "Extents" option. (Best choice in most cases). Saved as a separate file (like exportpdf.lsp) it can be used with a batch process to create PDF's for a whole bunch of DWG's.

 

(setq pdffile 
   (strcat 
      (vl-string-subst "\\PDF\\" "\\CAD\\" (getvar "dwgprefix"))
      "\\" 
      (vl-filename-base (getvar "dwgname")) 
      ".pdf"
   )
)
(if (= (getvar "TILEMODE") 0)
   (progn
      ; plot paperspace (multiple sheets)
      (princ "\nPlot all layouts")
      (command "-export" "p" "a" pdffile)
   )
   (progn
      ; Plot modelspace (1 sheet)
      (princ "\nPlot model")
      (command "-export" "p" "e" "n" pdffile)
   )
)

 

0 Likes
Message 4 of 13

Anonymous
Not applicable

@roland.r71 @Satish_Rajdev

Thank you for your responses. 

 

For some clarification, I use this LISP only on the paper sheet and not on the model page.  Due to that, I use C (current layout) instead of D (display), E (extent), or W (window).  I'm looking to just PDF one paper sheet with the DWG name as the PDF name and at that specific file location.

 

I don't think I need the "\\".  It's creating extra "\\" into the savename.  Please see attached.  Even with the slash or if I change the code to be like @roland.r71, I still get the same prompt to enter a file name whether I'm in the paper space or model space.

0 Likes
Message 5 of 13

roland.r71
Collaborator
Collaborator

Correct. You can remove the extra "\\"

With the extra \ the filename becomes invalid (so it will keep asking for a filename)

0 Likes
Message 6 of 13

roland.r71
Collaborator
Collaborator
(vl-load-com) ; this is best put in acaddoc.lsp, IMHO
(defun c:CU ( / pdffile)
(setq pdffile (strcat (vl-string-subst "\\PDF\\" "\\CAD\\" (getvar "dwgprefix")) (vl-filename-base (getvar "dwgname")) ".pdf" ) )
(command "-export" "_P" "_C" "_N" pdffile)
(princ)
)

 This will do

0 Likes
Message 7 of 13

Anonymous
Not applicable

I tried that code and it still doesn't work.  It places the PDF in "My Documents" folder and adds the tab name to the pdf name.

 

I'm thinking it might not be the LISP and be an ACA 2019 or computer setting.

0 Likes
Message 8 of 13

roland.r71
Collaborator
Collaborator

Yeah there was a 'bug' with the pasted code, which i just changed, so try again (as it works for me)

0 Likes
Message 9 of 13

Anonymous
Not applicable

Just tried it again.  Still doesn't work.  I added the "_N", the "filedia" set to 0, and removing the "" last time too and it still didn't work.

now I'm really thinking it's my setup.

0 Likes
Message 10 of 13

roland.r71
Collaborator
Collaborator

That's wierd.

The code works for me, as is.

No need to change filedia to 0 & the PDF ends up next to my DWG.

(Using ACAD2014)

0 Likes
Message 11 of 13

Anonymous
Not applicable

With the just the file name?  No tab name?

 

The LISP should also populate the PDF in a separate folder.  Pretty much the same path, but instead of

C:\Work\LISP_TEST\CAD\FAV

it should place it in this folder

C:\Work\LISP_TEST\PDF\FAV

 

Only difference is changing CAD to PDF.

 

Maybe it's the AutoCAD Architectural 2019 I'm using.  I've never used an Architectural version until recently.

0 Likes
Message 12 of 13

roland.r71
Collaborator
Collaborator
Accepted solution

Yep. Just the filename. [edit: I didn't replicate the path, so it ends up next to the dwg file]

 

& on top of that... I just tried your original code, which is hardly different from mine, and i couldn't see anything realy wrong, so I just tried to see what happens.

 

It works! Smiley Very Happy

 

so, yeah, it's not your code that's wrong. There's something else going on.

 

edit2:

Ok, I just checked to see if the path would change correctly, and it does.

With your own code too.

0 Likes
Message 13 of 13

Anonymous
Not applicable

@roland.r71

ahh okay.  I'll have to try it on a different version of AutoCAD.  Thank you for your help.

0 Likes