使用发布到多个PDF(&P)
全部的在其他lisp例程的帮助下,我们提出了一种使用Publish制作多页PDF的方法,无需使用第三方程序。这是给大家看和使用的。它可以工作,并且做我们希望它做的事情,但我们还没有弄清楚如何在发布完成后删除DWG文件,所以如果有人能弄明白这一点,那将是非常棒的。
(defun c:pdfpub (/ ob ss bn mn mx)
;; This was created by combining a multitude of different lisp routines by Lee Mac, RLX, Lee Ambrosius, Stephan BMR and howiez69
(vl-load-com)
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
;; Get the PlotConfigurations collection
(setq plotCfgs (vla-get-PlotConfigurations doc))
;; Check to see if the pagesetup already exists
(setq plotCfg (vl-catch-all-apply 'vla-Item (list plotCfgs "PDFSetup")))
;; If the page setup exists, the variable will be of type VLA-OBJECT
(if (/= (type plotCfg) 'VLA-OBJECT)
;; Create a page setup for model or paper space accordingly
(if (= (getvar "TILEMODE") 0)
(setq plotCfg (vla-Add plotCfgs "PDFSetup" :vlax-false))
(setq plotCfg (vla-Add plotCfgs "PDFSetup" :vlax-true))
)
)
;;(vla-put-Name plotCfg "PDFSetup")
(vla-RefreshPlotDeviceInfo plotCfg)
;; Set the plot device
(vla-put-ConfigName plotCfg "DWG To PDF.pc3")
;; Set the paper size
(vla-put-CanonicalMediaName plotCfg "ARCH_full_bleed_C_(24.00_x_18.00_Inches)")
;; Set the plot units (inches, millimeters, pixels)
(vla-put-PaperUnits plotCfg acInches)
;; Set what to plot
;; - If using acView, set the ViewToPlot property
;; - If using acWindow, call GetWindowToPlot
(if (= (getvar "TILEMODE") 0)
(progn
(vla-put-PlotType plotCfg acLayout)
;; Set scale
(vla-put-UseStandardScale plotCfg :vlax-true)
(vla-put-StandardScale plotCfg ac1_1)
)
(progn
(vla-put-PlotType plotCfg acExtents)
;; Set scale
(vla-put-UseStandardScale plotCfg :vlax-true)
(vla-put-StandardScale plotCfg acScaleToFit)
)
)
;; Hide paperspace objects
(vla-put-PlotHidden plotCfg :vlax-false)
;; Set the plot origin
(setq origin (vlax-make-safearray vlax-vbDouble '(0 . 1)))
(vlax-safearray-fill origin (list 0.5 0.5))
(vla-put-PlotOrigin plotCfg origin)
;; Set the plot rotation
(vla-put-PlotRotation plotCfg ac0degrees)
;; Set viewport plot behavior
(vla-put-PlotViewportBorders plotCfg :vlax-false)
(vla-put-PlotViewportsFirst plotCfg :vlax-true)
;; Set lineweight behavior
(vla-put-PlotWithLineweights plotCfg :vlax-true)
(vla-put-ScaleLineweights plotCfg :vlax-true)
;; Set plot styles behavior
(vla-put-PlotWithPlotStyles plotCfg :vlax-true)
(vla-put-ShowPlotStyles plotCfg :vlax-true)
;; Center the plot on the page
(if
(= :vlax-false (vla-get-CenterPlot plotCfg))
(vla-put-CenterPlot plotCfg :vlax-true)
)
(if (= (getvar "PSTYLEMODE") 0)
(vla-put-StyleSheet plotCfg "acad.stb")
(vla-put-StyleSheet plotCfg "TFC.ctb")
)
;; Assign the page setup to the current layout
(vla-CopyFrom (vla-get-ActiveLayout doc) plotCfg)
(vl-cmdf "UCS" "")
(setq cnt 0)
(if (not (setq folder (getfolder "Select folder to save views")))
(setq folder (getvar 'dwgprefix))(setq folder (strcat folder "\\")))
(if (and (progn
(initget "B")
(setq ob (entsel "\nSelect Block/B for blockname: "))
(cond
((eq ob "B")
(setq bn (getstring "\nEtner Block Name: "))
)
((and (eq (type ob) 'LIST)
(vlax-method-applicable-p (vlax-ename->vla-object (car ob)) 'getboundingbox))
(setq bn (cdr (assoc 2 (entget (car ob))))))))
(tblsearch "BLOCK" bn)
bn
(setq ss(ssget "_X" (list '(0 . "INSERT")'(410 . "Model")(cons 2 bn))))
)
(progn
(vla-zoomextents (vlax-get-acad-object))
(repeat (setq i (sslength ss))
(setq cnt (1+ cnt))
(vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'mn'mx)
(setq tmp (ssget "_C" (trans (vlax-safearray->list mx) 0 1) (trans (vlax-safearray->list mn) 0 1)))
(vl-cmdf "_.-wblock" (strcat folder (itoa cnt) "-" (vl-filename-base (getvar 'dwgname)) ".dwg") "" "0,0"
tmp "")
(command "oops")
)
)
(princ "\nNo Blocks Selected: ")
)(princ)
(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)
)
(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
(setvar "EXPERT" Save_Expert) ;sets system variable EXPERT back to original value
(setq pathtxt (strcat folder "TEMP.DSD")) ;sets path for DSD file from current drawing saved location
(setq file (open (strcat folder "TEMP.DSD") "w")) ;opens DSD file for writing
;**********START OF DSD FILE**********
;**********START HEADER**********
(write-line "" file)
(write-line "Ver=1" file)
(write-line "" 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
(setq cnt2 0)
(repeat (setq i2 (sslength ss))
(setq cnt2 (1+ cnt2))
(setq dname (strcat ""))
(write-line dname file)
(write-line (strcat "DWG=" folder (itoa cnt2) "-" (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)) ".dwg")file)
(write-line "Layout=Model" file) ;layout to plot
(write-line (strcat "OriginalSheetPath=" (strcat folder (itoa cnt2) "-" (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))".dwg") )file)
(write-line "Has Plot Port=0" file)
(write-line "Has3DDWF=0" file)
(setq i2 (1- i2))
)
;**********END OF 'ONE' LAYOUT TO PLOT********** !!!repeat previous section for each of your layouts or dwgs to plot
;**********START OF DSD FOOTER**********
(write-line "" file)
(write-line "Type=6" file) ;change to "TYPE=6" for multiple output files, "TYPE=5" for single output file
(write-line (strcat "DWF=" (strcat folder(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))".pdf") )file)
(write-line (strcat "OUT="(strcat folder)) 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
(princ)
)
(defun getfolder(msg / fl sh)
(if (and (setq sh (vlax-create-object "Shell.Application"))(setq fl (vlax-invoke sh 'browseforfolder 0 msg 0 "")))
(setq fl (vlax-get-property (vlax-get-property fl 'self) 'path))(setq fl nil))(release_me (list sh)) fl)
(defun release_me(lst)
(mapcar '(lambda (x)(if (and (= 'vla-object (type x))(not (vlax-object-released-p x)))(vlax-release-object x))(set (quote x) nil)) lst))
(princ)
谢谢
布瑞恩
页:
[1]