Completed auto plot that saves to specific folder

Completed auto plot that saves to specific folder

jcr96
Contributor Contributor
3,126 Views
13 Replies
Message 1 of 14

Completed auto plot that saves to specific folder

jcr96
Contributor
Contributor

Ive been working and asking for help about this auto plot lisp. It works perfectly no problems but it sends the pdf to the folder the dwg file is in which is fine but it would be far more convenient if it saved to a different folder. I know how to change the location to a subfolder in the current dwg's folder but as far as going up to a previous folder, that is what I cant seem to find and ive been looking through all forums to get my solution but none. 

To best understand where im trying to save the pdf file, my office creates a separate folder for each project and name it by its "address", in the address folder> there is a subfolder called "CAD" where the drawing is, and another sub folder called "PDF", where a > subsub folder "Preliminary Design" is where they go to be separated by specific submittals and its in this folders that I want the pdf to save to not the "CAD" folder.

                         "CAD"  > dwg file  (current location)  

"ADDRESS">

                         "PDF">  "Preliminary Design"(desired folder)

The issue is that the pdfs are saving into the "cad" folder and its the dwgprefix part of the equation that can differentiate the specific job the pdfs are coming from and save it to the dwg files location but how do I specify from that starting point to go up to the previous folder, the "address" folder and into the "PDF" folder and down deeper into the sub folder called "Preliminary Design". I have used a lisp that does just this before but when I left that office I didn't copy that command for myself and I regret it, so if anyone can understand and be able to figure out how to do this id really appreciate it. 

Below is the list, mind the plot style:


(defun c:dpdf (/ file)
  (setvar "cmdecho" 1)
  (setq file (strcat (getvar 'DWGPREFIX) (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) ".pdf"))
  (if (findfile file)(vl-file-delete file))
  (command "-plot" "yes" "" "DWG TO PDF.PC3" "ARCH D (24.00 x 36.00 Inches)" "Inches" "Landscape" "yes" "window" "0,0" "36,24" "1:1" "0,0" "yes" "SCD SHADER.stb" "yes" "no" "yes" "no" (getvar "CTAB") "No" "yes")
)

0 Likes
Accepted solutions (2)
3,127 Views
13 Replies
Replies (13)
Message 2 of 14

Moshe-A
Mentor
Mentor

@jcr96  hi,

 

the following function return the path after stripping out all characters from "\\cad\\...."

does this puts you on the direction to continue on your own?

 

moshe

 

 

(defun test (/ prefix p)
 (setq prefix (getvar "dwgprefix"))
 (setq p (vl-string-search (strcase "\\cad\\") (strcase prefix)))
 (substr prefix 1 (1+ p))
)
0 Likes
Message 3 of 14

jcr96
Contributor
Contributor

@Moshe-A,

Thank you for helping, I might be able to continue but I am not quite understanding what you mean when you say its stripping all from \\CAD\\. Can you explain that a little more so i can understand whats doing what to add that to my function

0 Likes
Message 4 of 14

ronjonp
Mentor
Mentor

Are you familiar with sheet set manager? You can set your output folder for your PDF's within the PDF publish options.

0 Likes
Message 5 of 14

Sea-Haven
Mentor
Mentor

Just a subtle change may explain

 

(defun test (/ prefix p)
(setq prefix (getvar "dwgprefix"))
(setq p (vl-string-search (strcase "\\Downloads\\") (strcase prefix)))
(setq prefix (strcat (substr prefix 1 (1+ p)) "pdf\\"))
)
0 Likes
Message 6 of 14

Moshe-A
Mentor
Mentor

@jcr96  hi,

 

just run (test) function and see what it returns?!

0 Likes
Message 7 of 14

jcr96
Contributor
Contributor

@Moshe-A 

I have input your list but it ignores all of it and continues to save the PDFs into the same folder as the dwg file being used. I tried playing with the locations to see if it could be a problem with which folders are being called out but still nothing there is no difference then the lisp I first posted.

After it plots it shows this error:

Command: ; error: extra right paren on input

But I don't think it has to do with why it wont save the PDFs in the right folder. 

0 Likes
Message 8 of 14

Moshe-A
Mentor
Mentor
Accepted solution

@jcr96  hi,

 

check this

 

enjoy

moshe

 

 

(defun c:dpdf (/ up_folder ; local function
	         file)

 (defun up_folder (prefix / p)
  (if (setq p (vl-string-search (strcase "\\cad\\") (strcase prefix)))
   (substr prefix 1 p)
  )
 ); up_folder
  
 (setvar "cmdecho" 1)
 (setq file (strcat (up_folder (getvar 'DWGPREFIX)) "\\pdf\\Preliminary Design\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) ".pdf"))
 (if (findfile file)(vl-file-delete file))
 (command "-plot" "yes" "" "DWG TO PDF.pc3" "ARCH D (24.00 x 36.00 Inches)" "Inches" "Landscape" "yes"
	   "window" "0,0" "36,24" "1:1" "0,0" "yes" "SCD SHADER.stb" "yes" "no" file "no" "yes")
)
0 Likes
Message 9 of 14

jcr96
Contributor
Contributor

sorry @Moshe-A , same issue, I had to add a few parentheses to the end to get it to work but still it ignores the up folder lisp. Your lisp is compatible it doesn't give any issue its just the command wont recognize it for some reason.

0 Likes
Message 10 of 14

Moshe-A
Mentor
Mentor

@jcr96 ,

 

it works fine here.  what AutoCAD version do have? post the tree folders.

 

moshe

 

0 Likes
Message 11 of 14

Scottu2
Advocate
Advocate
Accepted solution

Hello jcr96,

 

Just specifying (getvar "CTAB") you get the current tab name like MODEL, Layout1, or Layout2.

The file is written to the current directory because its only the name of the tab.

Replace the (getvar "CTAB") with the variable that contains the new directory path + tab name.

Also, its important to detect Model vs Layouts since the (command "-plot" ... )  requires a slightly different line statement.

 

(defun c:dpdf (/ file)
  (setvar "cmdecho" 1)
  (setq file (strcat (getvar 'DWGPREFIX) (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) ".pdf"))
  (if (findfile file)(vl-file-delete file))
  (command "-plot" "yes" "" "DWG TO PDF.PC3" "ARCH D (24.00 x 36.00 Inches)" "Inches" "Landscape" "yes" "window" "0,0" "36,24" "1:1" "0,0" "yes" "SCD SHADER.stb" "yes" "no" "yes" "no" (getvar "CTAB") "No" "yes")
)

0 Likes
Message 12 of 14

jcr96
Contributor
Contributor

@Moshe-A 

 

Im using AutoCad 2016

for the location of the DWG file:

\\SERVER1\Users\Server\Documents\NewScdServer\SCD\Customer Files\2019\11900 N. Balboa Blvd\CAD

 

for the desired location of the PDF:

\\SERVER1\Users\Server\Documents\NewScdServer\SCD\Customer Files\2019\11900 N. Balboa Blvd\PDF\PRELIMINARY DESIGN

0 Likes
Message 13 of 14

jcr96
Contributor
Contributor

@Scottu2, You were right I added the variables from  @Moshe-A  to the file name section and it works perfectly now. 

Thank You very very much

Here is the completed lisp:

 

(defun c:pdf (/ up_folder ; local function
          file)
 (defun up_folder (prefix / p)
  (if (setq p (vl-string-search (strcase "\\cad\\") (strcase prefix)))
   (substr prefix 1 p)
  )
 ); up_folder
 
 (setvar "cmdecho" 1)
 (setq file (strcat (up_folder (getvar 'DWGPREFIX)) "\\pdf\\Preliminary Design\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) ".pdf"))
(COMMAND "-PLOT"
"Yes" ;Detailed plot configuration?
"" ;Get a layout name
"DWG To PDF.pc3" ;Enter an output device name
"ARCH D (24.00 x 36.00 INCHES)" ;Enter paper size
"inches" ;Enter paper units
"Landscape" ;Enter drawing orientation
"No" ;Plot upside down?
"window" ;Enter plot area
"0,0"
"36,24"
"1:1" ;Enter plot scale
"0,0" ;Enter plot offset (x,y)
"Yes" ;Plot with plot styles?
"SCD SHADER.stb" ;Enter plot style table name or
"yes" ;Plot with lineweights?
"No" ;Scale lineweights with plot scale?
"yes" ;Plot paper space first?
"No" ;Hide paperspace objects?
(setq file (strcat (up_folder (getvar 'DWGPREFIX)) "\\pdf\\Preliminary Design\\" (getvar "CTAB") ".pdf")) ;Name of file
"No" ;Save changes to page setup
"yes" ;Proceed with plot
)
)
)
0 Likes
Message 14 of 14

phyoak11
Community Visitor
Community Visitor

Hello, 

 

I am also trying to do what you were trying to do exactly. (Saving PDFs into dedicated location which is a sub-folder of project. To clarify, inside each project folder will have sub folders. ( one for Cad and one for PDF)  When it comes to LISP , I am an absolute beginner.  Anyway, I upload your final version as it is. and when I run it , it is giving me an error saying "error: bad argument type: stringp nil". I am using 2021 version.  I don't know what went wrong. I have included my folder path in there.  If you or anyone can assist me, I would really appreciate it. 

 

my folder structure is as shown below:

 

CAD File location - \RPXXXXX.XX1 PK\60 CADD\2 DRG\2 CI

PDF destination (preferred) - \RPXXXXX.XX1 PK\60 CADD\4PDF

 

Thanks everyone. 

0 Likes