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

Plot PDF lisp.

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
Jonathan3891
12149 Views, 15 Replies

Plot PDF lisp.

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!


Jonathan Norton
Blog | Linkedin
15 REPLIES 15
Message 2 of 16
scot-65
in reply to: Jonathan3891

(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.


Message 3 of 16
Jonathan3891
in reply to: scot-65

I want the dialog box to open......


Jonathan Norton
Blog | Linkedin
Message 4 of 16
Jonathan3891
in reply to: Jonathan3891

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")
)

 


Jonathan Norton
Blog | Linkedin
Message 5 of 16
Kent1Cooper
in reply to: Jonathan3891


@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].

Kent Cooper, AIA
Message 6 of 16
Jonathan3891
in reply to: Kent1Cooper

You gonna have to put that in simpler terms. I'm just now trying to learn how to do this!


Jonathan Norton
Blog | Linkedin
Message 7 of 16
cadee
in reply to: Jonathan3891

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

Message 8 of 16
stevor
in reply to: cadee

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.

S
Message 9 of 16
Kent1Cooper
in reply to: Jonathan3891


@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.

Kent Cooper, AIA
Message 10 of 16
cadee
in reply to: Jonathan3891

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

Message 11 of 16
Kent1Cooper
in reply to: cadee


@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) ...

Kent Cooper, AIA
Message 12 of 16
cadee
in reply to: Kent1Cooper

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) ?.

Message 13 of 16
Kent1Cooper
in reply to: cadee


@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.

Kent Cooper, AIA
Message 14 of 16
markruys2
in reply to: Kent1Cooper

 

 

(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) )

Message 15 of 16
Jonathan3891
in reply to: markruys2

Thanks Markruys, that works perfect.

 

Can you explain to me what you did?

Spoiler
 

 


Jonathan Norton
Blog | Linkedin
Message 16 of 16
Jonathan3891
in reply to: Jonathan3891

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?


Jonathan Norton
Blog | Linkedin

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

Post to forums  

Autodesk Design & Make Report

”Boost