Jump to content

help me to create lisp to export multiple DWG to separate PDF


mostafa badran

Recommended Posts

Here's a break down to create PDFs using a script and script pro.

If you have a lisp routine that already has the printing to PDF set up, you simply need to load it and run it from the script.

http://www.cadtutor.net/forum/showthread.php?76974-Up-and-Running-with-the-2013-Core-Console&highlight=scriptpro

 

~Greg

Link to comment
Share on other sites

  • 2 weeks later...

Mostafa, how many DWG are you wanting to print, and how hard/easy is it to get a list of them. Is it always the same set of drawings like a certain project, or will it be dynamic every time? I worked on a project recently where we needed to print several pages of one DWG into one PDF, the opposite of what you want, but maybe our approach will work. We did in fact use the publish routine, I cheated, and wrote a DSD with LSP. You could manually make a publish setup, save that DSD and then modify the code below to write a DSD that does what you need.

 

(defun c:PUBLISH_PDF ( / file ;file name for TEMP.DSD
           OldFda ;system variable FILEDIA
           pathtxt ;path where drawing is saved to write TEMP.DSD
           nosheets ;number of PDF pages to print
           *error* ;error trap
           ) ;end variables

(vl-load-com)

(defun *error* ( msg )
   (setvar "FILEDIA" OldFda) ;sets system variable FILEDIA back to original value
   (setvar "EXPERT" Save_Expert) ;sets system variable EXPERT back to original value
       (princ "error: ")
       (princ msg)
       (princ)
   )

(setvar "CTAB" "Layout1") ;changes to paperspace and tab named Layout1

(setq OldFda (getvar "FILEDIA")) ;reads current system variable FILEDIA value
(setvar "FILEDIA" 0) ;sets FILEDIA to 0 so no dialog boxes popup

(setq Save_Expert (getvar "EXPERT")) ;reads current system variable EXPERT value
(setvar "EXPERT" 2) ;sets EXPERT to 2 so no dialog boxes popup

(command "._-PSETUPIN" "c:\\folder\\template.dwt" "*") ;imports all page setups from drawing template c:\folder\template.dwt
(setvar "EXPERT" Save_Expert) ;sets system variable EXPERT back to original value
(setq pathtxt (strcat (getvar "dwgprefix") "TEMP.DSD")) ;sets path for DSD file from current drawing saved location
(setq file (open (strcat (getvar "dwgprefix") "TEMP.DSD") "w")) ;opens DSD file for writing

;I USED A SELECTION SET HERE TO PICK A BORDER IN PAPERSPACE TO RECOGNIZE HOW MANY PAGES TO PRINT
;YOU'll NEED YOUR WAY OF SELECTING YOUR MULTIPLE DRAWINGS

;**********START OF DSD FILE**********

;**********START HEADER**********

(write-line "[DWF6Version]" file)
(write-line "Ver=1" file)
(write-line "[DWF6MinorVersion]" file)
(write-line "MinorVer=1" file)

;**********END OF HEADER**********

;**********START OF LAYOUTS/DWG TO PLOT********** !!!repeat this section for each of your layouts or dwgs to plot

(write-line "[DWF6Sheet:PDF Sheet 1]" file)
(write-line (strcat "DWG=" (getvar "dwgprefix")(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)) ".dwg")file)
(write-line "Layout=Layout1" file) ;layout to plot
(write-line "Setup=Sheet_1" file) ;page setup name to use
(write-line (strcat "OriginalSheetPath=" (strcat(getvar "dwgprefix")(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))".dwg") )file)
(write-line "Has Plot Port=0" file)
(write-line "Has3DDWF=0" file)

;**********END OF 'ONE' LAYOUT TO PLOT********** !!!repeat previous section for each of your layouts or dwgs to plot

;**********START OF DSD FOOTER**********

(write-line "[Target]" file)
(write-line "Type=6" file) ;change to "TYPE=5" for multiple output files, "TYPE=6" for single output file
(write-line (strcat "DWF=" (strcat(getvar "dwgprefix")(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))".pdf") )file)
(write-line (strcat "OUT="(strcat(getvar "dwgprefix")  )) file)
(write-line "PWD=" file)

;**********END OF DSD FOOTER**********

;**********END OF DSD FILE**********

(close file) ;closes DSD file
(command "_.delay" 2000) ;system delay before starting publish command so DSD file closes
(command "-Publish" pathtxt ) ;start publish command with TEMP.DSD file just created
(setvar "FILEDIA" OldFda) ;sets system variable FILEDIA back to original value
(command "_.delay" 2000) ;system delay before deleting TEMP.DSD so publish routine has time to release it
(vl-file-delete pathtxt) ;deletes TEMP.DSD file

;  (startapp "explorer /e," (getvar "dwgprefix")) ;comment out this line if you don't want file explorer to open with PDF location
(princ)

);defun

 

Hopefully this will get you pointed in the right direction. I'll be making a post shortly asking how to optimize my code, as my selection set routine(not shown here) is very inefficient.

 

~HowieZ

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...