I'm trying to create a lisp that will automatically create pdf's. I will eventually have 4 commands (or buttons) forLetter portrait landscape and portrait, and 11x17 portrait and landscape.
I need to be able to specify where the drawings need to be saved (this company has a really bad file structure!)
I've got it to somewhat work but it doesnt ask me where to save the pdf, it just puts it in the drawing directory.
This is what I got so far:
(defun c:PDF.lsp (/) (command "-plot""y""""DWG To PDF.pc3""""I""L""N""E""1:1""Center""Y""Colour.ctb""Y""Y""N""N""?"))
Please help!
Solved! Go to Solution.
Solved by markruys2. Go to Solution.
(setenv "PlotToFilePath" "X:\\your\\path\\here\\")
???
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
This is what I got so far, and it works perfectly EXCEPT it doesnt ask me where to put the pdf.
I dont want to specify a default folder or anything like that. I NEED the dialog box to appear, and let me specify it manually!
(defun c:PDF(/)
(command "tilemode" "0")
(command "-plot" "y" "" "Dwg To PDF.pc3" "ANSI expand B (11.00 x 17.00 Inches)" "I"
"" "N" "e" "1:1" "" "Y" "" "Y" "N" "N" "N" (strcat "" (getvar "dwgname")) "y" "Y")
)
@dsm_dude wrote:...it works perfectly EXCEPT it doesnt ask me where to put the pdf.
I dont want to specify a default folder or anything like that. I NEED the dialog box to appear, and let me specify it manually!
....
Look into (getfiled) using (getvar 'dwgname) for the default argument. I haven't used it for specifying new files, but Help says you can do that [without, of course, giving an example].
Can the above lisp program be modified so that it doesn't include ".dwg " with the pdf's filename and to have a preset directory path where it puts the pdf file (eg. U:\0000-1 project 01\01. Issued\)
Thanks
1. PDF file name:
And
(setq dns (getvar "dwgname")
dns1 (substr dns 1 (- (strlen dns) 4)) )
before the command, and use dns1 in the command;
Or, use
(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname") ) 4))
for (getvar "dwgname") in the command arguments
2.. Path: use Scott's or Kents replies, or experiment.
@dsm_dude wrote:You gonna have to put that in simpler terms. I'm just now trying to learn how to do this!
Read up on the (getfiled) function in the AutoLISP Reference in Help. It wants this syntax [see the Reference for descriptions of all the pieces]:
(getfiled title default ext flags)
Without trying it out, I think if you replace the
(strcat "" (getvar "dwgname"))
[which should really be simply (getvar "dwgname")] in your plot command sequence with:
(getfiled "PDF File Location:" (getvar "dwgname") ".pdf" 0)
it should let you navigate around to whatever folder/directory you want to put it in. You should probably experiment with that 'flags' argument at the end, in case you want it to warn you if the file already exists, etc.
One of many things I've regretted, that I've never learnt how to write lisp so could follow stevor suggestion because I dont know which parts of the lisp program to replace an d the part I did replace, the program failed.
When I've used kents suggestion of replacing ;-
"MEDIUM.CTB" "Y" "N" "N" "N" (strcat "" (getvar "dwgname")) "y" "Y")
with
"MEDIUM.CTB" "Y" "N" "N" "N" (getfiled "PDF File Location:" (getvar "dwgname") ".pdf" 0) "y" "Y")
I'm getting an Autocad message dialogue saying :- Invalid search pattern *.pdf
when I OK the dialogue, I get :-
Command: y Unknown command "Y". Press F1 for help.
Command: Y Unknown command "Y". Press F1 for help.
I also notice that the filename I think it wants to create is called \test1-layout1.pdf (i'd prefer not to have the layout name in the filename)
Thanks
@Anonymous wrote:....
When I've used kents suggestion...
....
I'm getting an Autocad message dialogue saying :- Invalid search pattern *.pdf
....
Sorry about that -- it doesn't want the dot/period with the file extension. I hope it will work this way:
... (getfiled "PDF File Location:" (getvar "dwgname") "pdf" 0) ...
It nows it want to "OPEN" not "SAVEAS" up a pdf file (pre-empted filename (which is the drawing I'm in test-01.dwg :- "TEST-01-DWG.PDF" ) and save this plot overwriting a selected pdf file (which wont be one with this current drawing's filename) ?.
@Anonymous wrote:It nows it want to "OPEN" not "SAVEAS" up a pdf file (pre-empted filename (which is the drawing I'm in test-01.dwg :- "TEST-01-DWG.PDF" ) and save this plot overwriting a selected pdf file (which wont be one with this current drawing's filename) ?.
I wouldn't expect it to offer "Saveas" if you're in a Plot command.
I'm not positive [I don't plot using macros or Lisp routines], but I think if you:
:: use the dialog box only to navigate to the folder or directory where you want the .PDF result to go [that's what you wanted added to the routine], and
:: do not select a file name in that folder/directory, but just leave that default file name in place, and
:: even though the button may say "Open," and that's not really what you're doing, pick on it anyway,
it may work the way you want. If not, I think someone else will need to help you. Or look at Help for (getfiled) -- it says you can use it to make a new file, but I didn't notice details about how to distinguish that from selecting an existing one; maybe they're in there somewhere, possibly involving the 'flag' argument.
(defun c:PDF(/)
;; make sure filename is ok before plotting
(if (setq filename (getfiled "enter actobat file name" "" "pdf" 1))
(progn
(command "tilemode" "0")
(command "-plot" "y" "" "Dwg To PDF.pc3" "ANSI expand B (11.00 x 17.00 Inches)" "I"
"" "N" "e" "1:1" "" "Y" "" "Y" "N" "N" "N" filename "y" "Y") ))
(princ) )
What do I need to do if I want it to look at a partial path and keep the pdf name?
If I chnage this:
(if (setq filename (getfiled "enter actobat file name" "" "pdf" 1))
to this:
(if (setq filename (getfiled "enter actobat file name" "I:\\mypath\\here" "pdf" 1))
It will not retain the name?