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

LISP to Automate DWG to PDF

26 REPLIES 26
SOLVED
Reply
Message 1 of 27
Anonymous
12048 Views, 26 Replies

LISP to Automate DWG to PDF

Hello All,

 

I'm new to AutoCAD, LISP, and this forum. I'm hoping someone out there can help me out. 

 

I'm trying to write multiple DWG's to PDF using DWG to PDF.PC3.  I would like it to autosave and not prompt me to save each PDF.  I can have up to 150+ PDF's.

 

I have done a lot of searching on this forum and others and have come up with a start. Here is what I have so far that does not work.  Any ideas on how to fix? Any help would be much appreciated.

 

(setvar "cmdecho" 1)

(Command "-plot")
(Command "yes")
         (Command "")   
         (Command "DWG TO PDF.PC3")  
         (Command "ARCH D (36.00 x 24.00 Inches)")
         (Command "Inches")
         (Command "Landscape")
         (Command "yes")
         (Command "Extents")
         (Command "1:1")
         (Command ".113427,.113168")
         (Command "yes")
         (Command "OMS.ctb")
         (Command "yes")
         (Command "no")
         (Command "no")
         (Command "Yes")
         (Command "No")
         (Command "no")
         (Command "yes")

(ade_errclear)
(setvar "cmdecho" 1)
(setvar "filedia" 1)
(princ)
)

26 REPLIES 26
Message 2 of 27
hmsilva
in reply to: Anonymous

Hello joseamans and welcome to the Autodesk Community!

 

For the plot command, try something like this

 

(Command "-plot"
         "yes" ; Detailed plot configuration? [Yes/No] <No>:
         "" ; Enter a layout name or [?] <Model>:
         "DWG TO PDF.PC3" ; Enter an output device name or [?] <None>:
         "ARCH D (36.00 x 24.00 Inches)" ; Enter paper size or [?] <ISO A4 (210.00 x 297.00 MM)>:
         "Inches" ; Enter paper units [Inches/Millimeters] <Millimeters>:
         "Landscape" ; Enter drawing orientation [Portrait/Landscape] <Portrait>:
         "yes" ; Plot upside down? [Yes/No] <No>:
         "Extents" ; Enter plot area [Display/Extents/Limits/View/Window] <Display>:
         "1:1" ; Enter plot scale (Plotted Millimeters=Drawing Units) or [Fit] <Fit>:
         ".113427,.113168" ; Enter plot offset (x,y) or [Center] <11.00,11.00>:
         "yes" ; Plot with plot styles? [Yes/No] <Yes>:
         "OMS.ctb" ; Enter plot style table name or [?] (enter . for none) <>:
         "yes" ; Plot with lineweights? [Yes/No] <Yes>:
         "no" ; Enter shade plot setting [As displayed/Wireframe/Hidden/Visual styles/Rendered] <As displayed>:
         (strcat (getvar 'DWGPREFIX) (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) ".pdf")
         "no" ; Save changes to page setup [Yes/No]? <N>
         "Yes" ; Proceed with plot [Yes/No] <Y>:
)

 

Hope this helps,
Henrique

EESignature

Message 3 of 27
Anonymous
in reply to: hmsilva

Thanks Henrique. As AutoCAD ran through I got an error

; error: malformed list on input
Message 4 of 27
Anonymous
in reply to: Anonymous

I'm almost there with this code, but it asks me to save each PDF.  Is there an autosave command?

 

(if (setq filename (getfiled "enter actobat  file name" ""  "pdf" 1))

  (progn


(command "tilemode" "0")
(command "-plot" "y" "" "Dwg To PDF.pc3" "ARCH D (36.00 x 24.00 Inches)" "I"
"L" "Y" "e" "1:1" ".113427,.113168" "Y" "OMS.ctb" "Y" "N" "N" "Y"   filename "y" "Y") ))
(princ) )

Message 5 of 27
hmsilva
in reply to: Anonymous


@Anonymous wrote:
Thanks Henrique. As AutoCAD ran through I got an error

; error: malformed list on input

Try the attached code

 

Henrique

EESignature

Message 6 of 27
Anonymous
in reply to: hmsilva

Thanks agian, still getting:

 

; error: malformed list on input

Message 7 of 27
hmsilva
in reply to: Anonymous


@Anonymous wrote:

Thanks agian, still getting:

 

; error: malformed list on input


Now, I'm getting confused...

Did you saved the 'demo.lsp', and load the code I've post?

The code is not 'malformated'

 

Henrique

EESignature

Message 8 of 27
Anonymous
in reply to: hmsilva

Does it matter where I save it?  When I saved it to my folder where the other LISP files reside I get this error when I try to run it.....

 

; error: no function definition: DEMO

 

Thank you again for all your help.

 

Message 9 of 27
Anonymous
in reply to: Anonymous

Since this code works, expect for it prompts me to save each pdf, is there any way it can be edited to auto save?

 

(if (setq filename (getfiled "enter actobat  file name" ""  "pdf" 1))

  (progn


(command "tilemode" "0")
(command "-plot" "y" "" "Dwg To PDF.pc3" "ARCH D (36.00 x 24.00 Inches)" "I"
"L" "Y" "e" "1:1" ".113427,.113168" "Y" "OMS.ctb" "Y" "N" "N" "Y"   filename "y" "Y") ))
(princ) )

Message 10 of 27
hmsilva
in reply to: Anonymous


@Anonymous wrote:

Does it matter where I save it?  When I saved it to my folder where the other LISP files reside I get this error when I try to run it.....

 

; error: no function definition: DEMO


What I was trying to ask, was not the place where you did save the file, but the way you did save the file.

The 'demo.lsp' is a functional code, if you select the file and saveas to the folder where your other LISP files reside, without opening the file, copy and paste in other file, the code will not error...

 


@Anonymous wrote:

Since this code works, expect for it prompts me to save each pdf, is there any way it can be edited to auto save?

 

(if (setq filename (getfiled "enter actobat  file name" ""  "pdf" 1))

  (progn


(command "tilemode" "0")
(command "-plot" "y" "" "Dwg To PDF.pc3" "ARCH D (36.00 x 24.00 Inches)" "I"
"L" "Y" "e" "1:1" ".113427,.113168" "Y" "OMS.ctb" "Y" "N" "N" "Y"   filename "y" "Y") ))
(princ) )


joseamans,

 

in the demo.lsp the command "-plot" is similar to this code, the only difference is, it will generate the '.pdf' file in the same folder where the '.dwg' is and with the '.dwg' file name, without user intervention...

 

Could you please attach the code that is giving error.

 

Henrique

EESignature

Message 11 of 27
Anonymous
in reply to: hmsilva


@hmsilva wrote:

@Anonymous wrote:

Does it matter where I save it?  When I saved it to my folder where the other LISP files reside I get this error when I try to run it.....

 

; error: no function definition: DEMO


What I was trying to ask, was not the place where you did save the file, but the way you did save the file.

The 'demo.lsp' is a functional code, if you select the file and saveas to the folder where your other LISP files reside, without opening the file, copy and paste in other file, the code will not error...

 


@Anonymous wrote:

Since this code works, expect for it prompts me to save each pdf, is there any way it can be edited to auto save?

 

(if (setq filename (getfiled "enter actobat  file name" ""  "pdf" 1))

  (progn


(command "tilemode" "0")
(command "-plot" "y" "" "Dwg To PDF.pc3" "ARCH D (36.00 x 24.00 Inches)" "I"
"L" "Y" "e" "1:1" ".113427,.113168" "Y" "OMS.ctb" "Y" "N" "N" "Y"   filename "y" "Y") ))
(princ) )


joseamans,

 

in the demo.lsp the command "-plot" is similar to this code, the only difference is, it will generate the '.pdf' file in the same folder where the '.dwg' is and with the '.dwg' file name, without user intervention...

 

Could you please attach the code that is giving error.

 

Henrique


Thanks again Henrique for trying to help me out.  Again I'm new to all this and trying to do my best.

 

I did a save as on your demo.lsp and placed it in the folder with my other lsp files and ran through my normal process for loading my other lsp file.

 

Screen Grab.jpg

 

When I select the demo.lsp I get the error I mentioned above.

 

Attached is the full code I was given to start with.  Other things are going on but I'm focused on the last section with the -plot command.  This is the section I've been trying to modify so there does not need to be user intervention.

 

Thanks again Henrique.  Your support is great.

 

Message 12 of 27
hmsilva
in reply to: Anonymous

Your code, with the plot command revised...

 

Edit: V1 had a wrong '.ctb' file, V2 will test if '.pdf' file already exists, and if so, delete the file before creating the new one.

 

Hope this helps,
Henrique

EESignature

Message 13 of 27
Anonymous
in reply to: hmsilva

I think you almost got it.  The code runs but the PDF's do not save.  Looking at the command line I see two commands that come up as "unknown commands".  I think that is causing issues.....

 

Enter a layout name or [?] <Layout1>: Enter an output device name or [?] <DWG
To PDF.pc3>: DWG TO PDF.PC3 Enter paper size or [?] <ANSI A (11.00 x 8.50
Inches)>: ARCH D (36.00 x 24.00 Inches) Enter paper units [Inches/Millimeters]
<Inches>: Inches Enter drawing orientation [Portrait/Landscape] <Landscape>:
Landscape Plot upside down? [Yes/No] <No>: yes Enter plot area
[Display/Extents/Limits/View/Window] <Extents>: Extents Enter plot scale
(Plotted Inches=Drawing Units) or [Fit] <1:1>: 1:1 Enter plot offset (x,y) or
[Center] <0.11,0.11>: .113427,.113168 Plot with plot styles? [Yes/No] <Yes>:
yes Enter plot style table name or [?] (enter . for none) <OMS.ctb>: acad.ctb
Plot with lineweights? [Yes/No] <Yes>: yes Scale lineweights with plot scale?
[Yes/No] <No>: no Plot paper space first? [Yes/No] <No>:
C:\Users\p20185\Desktop\Inspections\Test\D-11211002X0-H.pdf
Command: no Unknown command "NO".  Press F1 for help.
Command: Yes Unknown command "YES".  Press F1 for help.

Message 14 of 27
hmsilva
in reply to: Anonymous

Could you please try the V2 version?

The codes run without issues, on this side...

 

Henrique

EESignature

Message 15 of 27
Anonymous
in reply to: hmsilva


hmsilva wrote:

Could you please try the V2 version?

The codes run without issues, on this side...

 

Henrique


I saved V2 and still the same unknown commands:

 

C:\USERS\P20185\DESKTOP\INSPECTIONS\TEST\D-11210002X0-04.pdf
Command: no Unknown command "NO".  Press F1 for help.
Command: Yes Unknown command "YES".  Press F1 for help.
Command: _.qsave

Message 16 of 27
hmsilva
in reply to: Anonymous

Try the V3...

 

Henrique

 

EESignature

Message 17 of 27
Anonymous
in reply to: hmsilva

THANK YOU!!!!!!!  That does it!!!!  Where can I send a thank you gift???

Message 18 of 27
hmsilva
in reply to: Anonymous


@Anonymous wrote:

THANK YOU!!!!!!!  That does it!!!!  Where can I send a thank you gift???


You're welcome, joseamans!
Glad I could help, but you'll have to pay a beer Smiley Happy

Henrique

EESignature

Message 19 of 27
Anonymous
in reply to: hmsilva

Hi I saw what you guys share, I'm trying to get a kisp similar to this, I ran the one you sure but it doesnt work for me I'm really new in this and Im not so familiar, Im not very sure of the syntax that I need to use to run the lisp, is there any advise that you can give me to run the Lisp.

 

I try running it with "omsplot6" but it doesnt work, is there an explantion that you can give me, I will appreciate it a lot.

 

Thanks.

Message 20 of 27
serkancavuslar
in reply to: Anonymous

https://youtu.be/TLQJKIaf4T8

 

New MultiPlot Print and Pdf

Serkan ÇAVUŞLAR
CplCAD / Türkiye

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report