请选择 进入手机版 | 继续访问电脑版
天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 20|回复: 0

lisp源码:生成任意尺寸的pdf纸张

[复制链接]
  • TA的每日心情
    开心
    13 小时前
  • 签到天数: 25 天

    [LV.4]偶尔看看III

    72

    主题

    64

    回帖

    746

    积分

    管理员

    积分
    746
    发表于 2024-3-19 22:13:46 | 显示全部楼层 |阅读模式
    以及帖子下各位大神(如mj000,直接大白话讲出了实现这个功能的原理)的讨论,我写出了生成任意尺寸pdf纸张的lisp程序。纯lisp源码

    1. ;; 将字符串或表写入文件 (快于 write-line 函数)
    2. (Defun vldos-writefile
    3.                        (Fil          TXT            Mode      /
    4.                         list->string            FilObj    FilPth
    5.                         FilSys          OpnFil    Line
    6.                        )
    7.   (Defun list->string (slist / line rtn)
    8.     (if        (= (type slist) 'str)
    9.       (setq rtn slist)
    10.       (progn
    11.         (setq rtn "")
    12.         (foreach line slist
    13.           (if (= rtn "")
    14.             (setq rtn line)
    15.             (setq rtn (strcat rtn "\r\n" line))
    16.           )
    17.         )
    18.       )
    19.     )
    20.     rtn
    21.   )
    22.   (if TXT
    23.     (progn
    24.       (if (and Mode (findfile Fil))
    25.         (vl-file-delete Fil)
    26.       )
    27.       (if (setq FilSys (vlax-create-object "Scripting.FileSystemObject"))
    28.         (progn
    29.           (if (null (setq FilPth (findfile Fil)))
    30.             (setq OpnFil (vlax-invoke-method
    31.                            FilSys "CreateTextFile" Fil 0 0);;;
    32.             )
    33.             (setq FilObj (vlax-invoke FilSys "GetFile" FilPth)
    34.                   OpnFil (vlax-invoke FilObj "OpenAsTextStream" 8 0)
    35.             )
    36.           )
    37.           (if OpnFil
    38.             (progn
    39.               (vlax-invoke OpnFil "Write" (list->string TXT))
    40.               (vlax-invoke OpnFil "Close")
    41.               (vlax-release-object OpnFil)
    42.               (if (= (type FilObj) 'vla-object)
    43.                 (vlax-release-object FilObj)
    44.               )
    45.               (vlax-release-object FilSys)
    46.             )
    47.           )
    48.         )
    49.       )
    50.       (if (setq Filpth (findfile Fil))
    51.         (setq FilPth (vldos-formatpath filpth))
    52.       )
    53.     )
    54.   )
    55.   filpth
    56. )

    57. (Defun vldos-formatpath        (string)
    58.   (while (vl-string-search "/" string)
    59.     (setq string (vl-string-subst "\" "/" string))
    60.   )
    61.   (while (vl-string-search "\\\" string)
    62.     (setq string (vl-string-subst "\" "\\\" string))
    63.   )
    64.   (setq string (strcase string))
    65.   string
    66. )

    67. ;;;(MJ:delim "aa 10 b10x20.2" "")返回("aa 10 b10x20.2")
    68. (defun MJ:delim (str delim / l1 l2)
    69.   (setq str (vl-string->list str) delim (vl-string->list delim))
    70.   (while str
    71.     (if (not (member (car str) delim))
    72.              (setq l1 (cons (car str) l1))
    73.              (if l1 (setq l2 (cons (vl-list->string (reverse l1)) l2) l1 nil))
    74.     )
    75.     (setq str (cdr str))
    76.   )
    77.   (if l1 (setq l2 (cons (vl-list->string (reverse l1)) l2)))
    78.   (reverse l2)
    79. )
    80. (defun LM:SubstNth ( a n l / i )
    81.     (setq i -1)
    82.     (mapcar '(lambda ( x ) (if (= (setq i (1+ i)) n) a x)) l)
    83. )


    84. (defun pmp_add_picsize(pname wid hit odir)
    85.   ;;输入图纸的宽、高和左右上下边距,写一个pmp文件,返回文件名
    86.   (setq origpmp
    87.          '(
    88. "PIAFILEVERSION_2.0,PC3VER1\n"
    89. "meta{\n"
    90. " user_defined_model_pathname="C:\\Users\\loki\\AppData\\Roaming\\Autodesk\\AutoCAD 2013 - Simplified Chinese\\R19.0\\chs\\Plotters\\PMP Files\\DWG To PDF.pmp\n"
    91. " user_defined_model_basename="\n"
    92. " driver_pathname="C:\\Program Files\\Autodesk\\AutoCAD 2013\\drv\\pdfplot11.hdi\n"
    93. " driver_version="1.1-11.0.55.0 [v018-1]\n"
    94. " driver_tag_line="PDF Plot - by Autodesk\n"
    95. " toolkit_version=1\n"
    96. " driver_type=3\n"
    97. " canonical_family_name="Autodesk ePlot\n"
    98. " show_custom_first=FALSE\n"
    99. " truetype_as_text=TRUE\n"
    100. " canonical_model_name="pdf\n"
    101. " localized_family_name="Autodesk ePlot (PDF)\n"
    102. " localized_model_name="PDF\n"
    103. " file_only=TRUE\n"
    104. " model_abilities="000550055000\n"
    105. " udm_description="\n"
    106. " short_net_name="\n"
    107. " friendly_net_name="\n"
    108. " dm_driver_version=0\n"
    109. " default_system_cfg=FALSE\n"
    110. " platform="2,6,1\n"
    111. " locale="4B00409\n"
    112. "}\n"
    113. "mod{\n"
    114. " media{\n"
    115. "  abilities="500005500500505555000005550000000550000500000500000\n"
    116. "  caps_state="000000000000000000000000000000000000000000000000000\n"
    117. "  ui_owner="11111111111111111111110\n"
    118. "  size_max_x=5080.0\n"
    119. "  size_max_y=5080.0\n"
    120. " }\n"
    121. "}\n"
    122. "del{\n"
    123. " media{\n"
    124. "  abilities="500005500500505555000005550000000550000500000500000\n"
    125. "  caps_state="000000000000000000000000000000000000000000000000000\n"
    126. "  ui_owner="11111111111111111111110\n"
    127. "  size_max_x=5080.0\n"
    128. "  size_max_y=5080.0\n"
    129. " }\n"
    130. "}\n"
    131. "udm{\n"
    132. " calibration{\n"
    133. "  _x=1.0\n"
    134. "  _y=1.0\n"
    135. " }\n"
    136. " media{\n"
    137.   "  abilities="500005500500505555000005550000000550000500000500000\n"
    138.   "  caps_state="000000000000000000000000000000000000000000000000000\n"
    139.   "  ui_owner="11111111111111111111110\n"
    140.   "  size_max_x=5080.0\n"
    141.   "  size_max_y=5080.0\n"
    142. "  size{\n"
    143. "   0{\n"
    144. "    caps_type=2\n"
    145. "    name="UserDefinedMetric (800.00 x 600.00 纵向 )\n"
    146. "    localized_name=""
    147. "    media_description_name="UserDefinedMetric 纵向 800.00W x 600.00H - (0, 0) x (800, 600) =480000 纵向 x\n"
    148. "    media_group=15\n"
    149. "    landscape_mode=TRUE\n"
    150. "   }\n"
    151. " }\n"
    152. "  description{\n"
    153. "   0{\n"
    154. "    caps_type=2\n"
    155. "    name="UserDefinedMetric 纵向 800.00W x 600.00H - (0, 0) x (800, 600) =480000 纵向 x\n"
    156. "    media_bounds_urx="
    157. "    media_bounds_ury="
    158. "    printable_bounds_llx=0.0\n"
    159. "    printable_bounds_lly=0.0\n"
    160. "    printable_bounds_urx="
    161. "    printable_bounds_ury="
    162. "    printable_area="
    163. "    dimensional=TRUE\n"
    164. "}}}}\n"
    165. "hidden{\n"
    166. " media{\n"
    167. "  abilities="500005500500505555000005550000000550000500000500000\n"
    168. "  caps_state="000000000000000000000000000000000000000000000000000\n"
    169. "  ui_owner="11111111111111111111110\n"
    170. "  size_max_x=5080.0\n"
    171. "  size_max_y=5080.0\n"
    172. " }\n"
    173. "}\n"
    174.            )
    175.         )
    176. (setq namen 58 tf0 68)
    177. (setq newpmp (LM:SubstNth (strcat(nth  namen  origpmp)pname "\n") namen origpmp));;;修改图纸名
    178. (setq wid1(rtos wid 2 1)
    179.       hit1(rtos hit 2 1)
    180.       wid2 wid1
    181.       hit2 hit1
    182.       area(rtos (* wid hit) 2 1)
    183.       )
    184. (setq newpmp (LM:SubstNth (strcat(nth  tf0  newpmp)wid1 "\n") tf0 newpmp))
    185. (setq newpmp (LM:SubstNth (strcat(nth  (+ tf0 1)  newpmp)hit1 "\n") (+ tf0 1) newpmp))
    186. (setq newpmp (LM:SubstNth (strcat(nth  (+ tf0 4)  newpmp)wid2 "\n") (+ tf0 4) newpmp))
    187. (setq newpmp (LM:SubstNth (strcat(nth  (+ tf0 5)  newpmp)hit2 "\n") (+ tf0 5) newpmp))
    188. (setq newpmp (LM:SubstNth (strcat(nth  (+ tf0 6)  newpmp)area "\n") (+ tf0 6) newpmp))
    189. (vldos-writefile odir (apply 'strcat newpmp) t)
    190.           
    191. )
    192. (princ 111)
    193. (defun pc3_add_pdfsize(pmpfile tfname wid hit pc3odir)
    194. (setq pc3orig'(
    195.   "PIAFILEVERSION_2.0,PC3VER1\n"
    196. "meta{\n"
    197. " user_defined_model_pathname= ""
    198. " user_defined_model_basename= "\n"
    199. " driver_pathname= "D: \\Program Files \\Autodesk \\AutoCAD 2018 \\drv \\pdfplot14.hdi\n"
    200. " driver_version= "1.0-16.0.47.0 [v018-1]\n"
    201. " driver_tag_line= "PDF Plot - by Autodesk\n"
    202. " toolkit_version=1\n"
    203. " driver_type=3\n"
    204. " canonical_family_name= "Autodesk ePlot\n"
    205. " show_custom_first=FALSE\n"
    206. " truetype_as_text=TRUE\n"
    207. " canonical_model_name= "pdf\n"
    208. " localized_family_name= "Autodesk ePlot (PDF)\n"
    209. " localized_model_name= "PDF\n"
    210. " file_only=TRUE\n"
    211. " model_abilities= "000550055000\n"
    212. " udm_description= "\n"
    213. " short_net_name= "\n"
    214. " friendly_net_name= "\n"
    215. " dm_driver_version=0\n"
    216. " default_system_cfg=FALSE\n"
    217. " platform= "2,10,0\n"
    218. " locale= "4B00409\n"
    219. " config_description= "\n"
    220. " config_autospool=FALSE\n"
    221. "}\n"
    222. "media{\n"
    223. " selection_method=2\n"
    224. " type= "\n"
    225. " dm_orientation=1\n"
    226. " actual_printable_bounds_llx=5.0\n"
    227. " actual_printable_bounds_lly=17.0\n"
    228. " actual_printable_bounds_urx=205.0\n"
    229. " actual_printable_bounds_ury=280.0\n"
    230. " number_of_copies=1\n"
    231. " size{\n"
    232. "  name= "ISO_A4_(210.00_x_297.00_MM)\n"
    233. "  group=4\n"
    234. "  landscape_mode=FALSE\n"
    235. "  longplot_reduction=1.0\n"
    236. "  media_description{\n"
    237. "   printable_bounds_llx=5.0\n"
    238. "   printable_bounds_lly=17.0\n"
    239. "   printable_bounds_urx=205.0\n"
    240. "   printable_bounds_ury=280.0\n"
    241. "   printable_area=52600.0\n"
    242. "   dimensional=TRUE\n"
    243. "   media_bounds{\n"
    244. "    urx=210.0\n"
    245. "    ury=297.0\n"
    246. "   }\n"
    247. "  }\n"
    248. " }\n"
    249. "}\n"
    250. "io{\n"
    251. " type=2\n"
    252. " pathname= "\n"
    253. " allsysvalid=FALSE\n"
    254. " plot_to_file=TRUE\n"
    255. "}\n"
    256. "res_color_mem{\n"
    257. " name= "RGB\n"
    258. " num_colors=16777216\n"
    259. " color_depth=24\n"
    260. " num_undithered_colors=16777216\n"
    261. " color_system=1\n"
    262. " dm_color=1\n"
    263. " lines_overwrite=TRUE\n"
    264. " resolution{\n"
    265. "  name= "Default\n"
    266. "  phys_resolution_x=400.0\n"
    267. "  phys_resolution_y=400.0\n"
    268. "  addr_resolution_x=1.0\n"
    269. "  addr_resolution_y=1.0\n"
    270. "  effective_resolution_x=400.0\n"
    271. "  effective_resolution_y=400.0\n"
    272. " }\n"
    273. "}\n"
    274. "custom{\n"
    275. " 0{\n"
    276. "  name= "Custom_Raster_Resolution\n"
    277. "  value=FALSE\n"
    278. " }\n"
    279. " 1{\n"
    280. "  name= "Custom_DWF_Resolution\n"
    281. "  value=FALSE\n"
    282. " }\n"
    283. " 2{\n"
    284. "  name= "Custom_Monochrome_Resolution\n"
    285. "  value=FALSE\n"
    286. " }\n"
    287. " 3{\n"
    288. "  name= "Custom_Gradient_Resolution\n"
    289. "  value=FALSE\n"
    290. " }\n"
    291. " 4{\n"
    292. "  name= "Gradient_Limit\n"
    293. "  value=400\n"
    294. " }\n"
    295. " 5{\n"
    296. "  name= "Monochrome_Raster_Limit\n"
    297. "  value=400\n"
    298. " }\n"
    299. " 6{\n"
    300. "  name= "Raster_Limit\n"
    301. "  value=400\n"
    302. " }\n"
    303. " 7{\n"
    304. "  name= "All_As_Geometry\n"
    305. "  value=TRUE\n"
    306. " }\n"
    307. " 8{\n"
    308. "  name= "Capture\n"
    309. "  value=1\n"
    310. " }\n"
    311. " 9{\n"
    312. "  name= "Hardcopy_Resolution\n"
    313. "  value=400\n"
    314. " }\n"
    315. " 10{\n"
    316. "  name= "Font_Capture\n"
    317. "  value=FALSE\n"
    318. " }\n"
    319. " 11{\n"
    320. "  name= "Include_Layer\n"
    321. "  value=TRUE\n"
    322. " }\n"
    323. " 12{\n"
    324. "  name= "Resolution\n"
    325. "  value=14\n"
    326. " }\n"
    327. "}\n"
    328. "\n"))
    329. (pmp_add_picsize tfname wid hit pmpfile)
    330. (setq newpc3 (LM:SubstNth (strcat(nth  2  pc3orig)pmpfile "\n") 2 pc3orig))
    331. (vldos-writefile pc3odir (apply 'strcat newpc3) t)
    332.   )
    333. ;;测试
    334. ;(pc3_add_pdfsize "K:\\textpmp.pmp" "newpdf1"2180 1580
    335. ;                  "K:\\textpc3.pc3")
    336. (defun c:tt()
    337.   (setq wid(getdist "\n输入宽度")
    338.         hit (getdist "\n 输入高度"))
    339.   (princ (strcat (rtos wid 2 2) " x "(rtos hit 2 2)))
    340. (pmp_add_picsize "mysize123" wid hit "K:\\CAD资料\\我的LISP程序院内版\\专门应用\\批量打印pdf\\24新思路操作pmp\\textpmp.pmp"))
    复制代码

     

     

     

     

    lisp源码:生成任意尺寸的pdf纸张
    哎...膜结构车棚,签到来了1...
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网_中国空间膜结构协会

    GMT+8, 2024-3-29 22:17 , Processed in 0.064444 second(s), 21 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表