乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 58|回复: 0

[编程交流] 使用发布到多个PDF(&P)

[复制链接]

39

主题

180

帖子

141

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
195
发表于 2022-7-5 15:30:28 | 显示全部楼层 |阅读模式
全部的
 
在其他lisp例程的帮助下,我们提出了一种使用Publish制作多页PDF的方法,无需使用第三方程序。这是给大家看和使用的。它可以工作,并且做我们希望它做的事情,但我们还没有弄清楚如何在发布完成后删除DWG文件,所以如果有人能弄明白这一点,那将是非常棒的。
 
  1. (defun c:pdfpub (/ ob ss bn mn mx)
  2. ;; This was created by combining a multitude of different lisp routines by Lee Mac, RLX, Lee Ambrosius, Stephan BMR and howiez69
  3.      (vl-load-com)
  4. (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  5.    ;; Get the PlotConfigurations collection
  6.    (setq plotCfgs (vla-get-PlotConfigurations doc))
  7.    ;; Check to see if the pagesetup already exists
  8.    (setq plotCfg (vl-catch-all-apply 'vla-Item (list plotCfgs "PDFSetup")))
  9.    ;; If the page setup exists, the variable will be of type VLA-OBJECT
  10.    (if (/= (type plotCfg) 'VLA-OBJECT)
  11.        ;; Create a page setup for model or paper space accordingly
  12.        (if (= (getvar "TILEMODE") 0)  
  13.            (setq plotCfg (vla-Add plotCfgs "PDFSetup" :vlax-false))
  14.            (setq plotCfg (vla-Add plotCfgs "PDFSetup" :vlax-true))
  15.        )
  16.    )
  17.    ;;(vla-put-Name plotCfg "PDFSetup")
  18.    (vla-RefreshPlotDeviceInfo plotCfg)
  19.    ;; Set the plot device
  20.    (vla-put-ConfigName plotCfg "DWG To PDF.pc3")
  21.    ;; Set the paper size
  22.    (vla-put-CanonicalMediaName plotCfg "ARCH_full_bleed_C_(24.00_x_18.00_Inches)")
  23.    ;; Set the plot units (inches, millimeters, pixels)
  24.    (vla-put-PaperUnits plotCfg acInches)
  25.    ;; Set what to plot
  26.    ;; - If using acView, set the ViewToPlot property
  27.    ;; - If using acWindow, call GetWindowToPlot
  28.    (if (= (getvar "TILEMODE") 0)
  29.        (progn
  30.            (vla-put-PlotType plotCfg acLayout)
  31.            ;; Set scale
  32.            (vla-put-UseStandardScale plotCfg :vlax-true)
  33.            (vla-put-StandardScale plotCfg ac1_1)         
  34.        )
  35.        (progn
  36.            (vla-put-PlotType plotCfg acExtents)
  37.            ;; Set scale
  38.            (vla-put-UseStandardScale plotCfg :vlax-true)
  39.            (vla-put-StandardScale plotCfg acScaleToFit)
  40.            )
  41.    )
  42.    ;; Hide paperspace objects
  43.    (vla-put-PlotHidden plotCfg :vlax-false)
  44.    ;; Set the plot origin
  45.    (setq origin (vlax-make-safearray vlax-vbDouble '(0 . 1)))
  46.    (vlax-safearray-fill origin (list 0.5 0.5))
  47.    (vla-put-PlotOrigin plotCfg origin)
  48.    ;; Set the plot rotation
  49.    (vla-put-PlotRotation plotCfg ac0degrees)
  50.    ;; Set viewport plot behavior
  51.    (vla-put-PlotViewportBorders plotCfg :vlax-false)
  52.    (vla-put-PlotViewportsFirst plotCfg :vlax-true)
  53.    ;; Set lineweight behavior
  54.    (vla-put-PlotWithLineweights plotCfg :vlax-true)
  55.    (vla-put-ScaleLineweights plotCfg :vlax-true)
  56.    ;; Set plot styles behavior
  57.    (vla-put-PlotWithPlotStyles plotCfg :vlax-true)
  58.    (vla-put-ShowPlotStyles plotCfg :vlax-true)
  59.    ;; Center the plot on the page
  60.    (if
  61.    (= :vlax-false (vla-get-CenterPlot plotCfg))
  62.    (vla-put-CenterPlot plotCfg :vlax-true)
  63.    )
  64.    (if (= (getvar "PSTYLEMODE") 0)
  65.        (vla-put-StyleSheet plotCfg "acad.stb")
  66.        (vla-put-StyleSheet plotCfg "TFC.ctb")
  67.    )
  68.    ;; Assign the page setup to the current layout
  69.    (vla-CopyFrom (vla-get-ActiveLayout doc) plotCfg)
  70.    (vl-cmdf "UCS" "")
  71.    (setq cnt 0)
  72.    (if (not (setq folder (getfolder "Select folder to save views")))
  73.    (setq folder (getvar 'dwgprefix))(setq folder (strcat folder "\")))
  74.             (if (and (progn
  75.                 (initget "B")
  76.           (setq ob (entsel "\nSelect Block/B for blockname: "))
  77.                (cond
  78.                ((eq ob "B")
  79.                    (setq bn (getstring "\nEtner Block Name: "))
  80.                    )
  81.                ((and (eq (type ob) 'LIST)
  82.               (vlax-method-applicable-p (vlax-ename->vla-object (car ob)) 'getboundingbox))
  83.                      (setq bn (cdr (assoc 2 (entget (car ob))))))))
  84. (tblsearch "BLOCK" bn)
  85.                bn     
  86.                (setq ss  (ssget "_X" (list '(0 . "INSERT")'(410 . "Model")(cons 2 bn))))
  87.                      )
  88. (progn
  89.          (vla-zoomextents (vlax-get-acad-object))
  90.        (repeat (setq i (sslength ss))
  91. (setq cnt (1+ cnt))
  92. (vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'mn'mx)
  93.                      (setq tmp (ssget "_C" (trans (vlax-safearray->list mx) 0 1) (trans (vlax-safearray->list mn) 0 1)))
  94.   (vl-cmdf "_.-wblock" (strcat folder (itoa cnt) "-" (vl-filename-base (getvar 'dwgname)) ".dwg") "" "0,0"  
  95.            tmp "")
  96.                          (command "oops")
  97.    )
  98.    )         
  99.               (princ "\nNo Blocks Selected: ")
  100.          )(princ)
  101.     (defun *error* ( msg )
  102.    (setvar "FILEDIA" OldFda) ;sets system variable FILEDIA back to original value
  103.    (setvar "EXPERT" Save_Expert) ;sets system variable EXPERT back to original value
  104.        (princ "error: ")
  105.        (princ msg)
  106.        (princ)
  107.    )
  108. (setq OldFda (getvar "FILEDIA")) ;reads current system variable FILEDIA value
  109. (setvar "FILEDIA" 0) ;sets FILEDIA to 0 so no dialog boxes popup
  110. (setq Save_Expert (getvar "EXPERT")) ;reads current system variable EXPERT value
  111. (setvar "EXPERT" 2) ;sets EXPERT to 2 so no dialog boxes popup
  112. (setvar "EXPERT" Save_Expert) ;sets system variable EXPERT back to original value
  113. (setq pathtxt (strcat folder "TEMP.DSD")) ;sets path for DSD file from current drawing saved location
  114. (setq file (open (strcat folder "TEMP.DSD") "w")) ;opens DSD file for writing
  115. ;**********START OF DSD FILE**********
  116. ;**********START HEADER**********
  117. (write-line "[DWF6Version]" file)
  118. (write-line "Ver=1" file)
  119. (write-line "[DWF6MinorVersion]" file)
  120. (write-line "MinorVer=1" file)
  121. ;**********END OF HEADER**********
  122. ;**********START OF LAYOUTS/DWG TO PLOT********** !!!repeat this section for each of your layouts or dwgs to plot
  123. (setq cnt2 0)
  124.        (repeat (setq i2 (sslength ss))
  125. (setq cnt2 (1+ cnt2))
  126. (setq dname (strcat "[DWF6Sheet:PDF Sheet " (itoa cnt2) "]"))
  127. (write-line dname file)
  128. (write-line (strcat "DWG=" folder (itoa cnt2) "-" (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)) ".dwg")file)
  129. (write-line "Layout=Model" file) ;layout to plot
  130. (write-line (strcat "OriginalSheetPath=" (strcat folder (itoa cnt2) "-" (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))".dwg") )file)
  131. (write-line "Has Plot Port=0" file)
  132. (write-line "Has3DDWF=0" file)
  133. (setq i2 (1- i2))
  134. )
  135. ;**********END OF 'ONE' LAYOUT TO PLOT********** !!!repeat previous section for each of your layouts or dwgs to plot
  136. ;**********START OF DSD FOOTER**********
  137. (write-line "[Target]" file)
  138. (write-line "Type=6" file) ;change to "TYPE=6" for multiple output files, "TYPE=5" for single output file
  139. (write-line (strcat "DWF=" (strcat folder(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))".pdf") )file)
  140. (write-line (strcat "OUT="(strcat folder)) file)
  141. (write-line "PWD=" file)
  142. ;**********END OF DSD FOOTER**********
  143. ;**********END OF DSD FILE**********
  144. (close file) ;closes DSD file
  145. (command "_.delay" 2000) ;system delay before starting publish command so DSD file closes
  146. (command "-Publish" pathtxt ) ;start publish command with TEMP.DSD file just created
  147. (setvar "FILEDIA" OldFda) ;sets system variable FILEDIA back to original value
  148. (command "_.delay" 2000) ;system delay before deleting TEMP.DSD so publish routine has time to release it
  149. (vl-file-delete pathtxt) ;deletes TEMP.DSD file
  150. (princ)
  151. )
  152.   (defun getfolder  (msg / fl sh)
  153.    (if (and (setq sh (vlax-create-object "Shell.Application"))(setq fl (vlax-invoke sh 'browseforfolder 0 msg 0 "")))
  154.    (setq fl (vlax-get-property (vlax-get-property fl 'self) 'path))(setq fl nil))(release_me (list sh)) fl)
  155. (defun release_me  (lst)
  156. (mapcar '(lambda (x)(if (and (= 'vla-object (type x))(not (vlax-object-released-p x)))(vlax-release-object x))(set (quote x) nil)) lst))
  157. (princ)

 
谢谢
布瑞恩
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-14 21:05 , Processed in 0.589236 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表