乐筑天下

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

[编程交流] 需要使用mapcar的帮助

[复制链接]

15

主题

243

帖子

228

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-5 22:39:48 | 显示全部楼层 |阅读模式
嘿,大家好,我不得不在这个cad-to-excel程序中添加大量数据,我在过去很长一段时间里一直在工作。。。
 
下面是现在硬编码到例程中的数据列表示例
  1. (setq x1tr-t1 (list "Valve, Gate, NPT, 800#, A352-LCB/LCC or A350-LF2 Body, SS Wedge, HF-SS Seat, API Trim 10, 12 or 16, HW Op., Reduced Port, Bolted Bonnet- OS&Y, Graphite Packing, Solid Wedge, API-600 & 598, ASME B16.34 & B16.10, 500ppm VOC" "150" "1100" "quoting 1/2" Newco 18T- LF24/3NCRP"))
  2. (SETQ X1TR-T1-2 (LIST "Valve, Gate, NPT, 800#, A-182 F316/A-351Gr.CF8M Body, SS Stem/Wedge/Seat/Bonnet, API Trim 10, 12 or 16, HW Op., Red. Port, Sealed SS Bolted Extended Bonnet, Graphite/TFE Packing, Flex Wedge, API-600 & 598, ASME B16.34 & B16.10, 500ppm VOC" "250" "550" "DSI 4121F12-18"))
  3. (SETQ X1TR-T1-3 (LIST "Valve, Floating Ball, NPT, 2000#, A-216Gr.WCB Body, SS Stem/Ball, PTFE Seats, -20 to 400 F, Lever Op., Red. Port, Hydrocarbon Trim, Anti-blowout Stem, API-607, ASME B16.34, 500ppm VOC, Bubble Tight Seal" "250" "550" "DSI 4121F12-18"))
  4. (SETQ X1TR-T1-4 (LIST "Valve, Trunnion Ball, 300# RF, A-216Gr.WCB/A-105 Body, SS Stem/Ball, Hydrocarbon Compatible Seat/O-Rings/Packing, -20 to 400 F, Gear Op., Red. Port, Anti-blowout Stem, API-607, ASME B16.34 & B16.10, 500ppm VOC, Bubble Tight Seal" "250" "550" "DSI 4121F12-18"))
  5. (SETQ X1TR-T1-5 (LIST "Valve, Globe, SW, 800#, A352-LCB/LCC or A350-LF2 Body, SS Disc, HF- SS Seat, MS Stem, API Trim 10, 12 or 16, 800#, -50 to 800 F, HW Op., Bolted Bonnet-OS&Y, Graphite Packing, API-602 & 598, ASME B16.34 & B16.10, 500ppm VOC" "250" "550" "Newco 18TLF24/3NCRP"))
  6. (SETQ X1TR-S2L (LIST "Valve, Piston Check, NPT, A-182 F316/A-351Gr.CF8M Body, SS Piston/Disc, SS Spring, API Trim 10, 12 or 16, 800#, -20 to 800 F, Bolted Bonnet, Std. Port, Renew. Seats, API-602 & 598, ASME B16.34" "150" "1100" "OIC 8GT6LUSEG"))
  7. (SETQ X1TR-2SL-2 (LIST "Valve, Floating Ball, 300# RF, A-216Gr.WCB/A-105 Body, SS Stem/Ball, Hydrocarbon Compatible Seat/O-Rings/Packing, -20 to 400 F, Lever Op. \(Gear Op>8" 300#\), Full Port, Anti-blowout Stem, API-607, ASME B16.34 & B16.10, 500ppm VOC, Bubble Tight Seal" "150" "1100" "OIC 8GT6LUSEG"))
  8. (SETQ X1TR-S2 (LIST "Valve, Gate, NPT, 800#, A-182 F316/A-351Gr.CF8M Body, SS Stem/Wedge/Seat/Bonnet, API Trim 10, 12 or 16, HW Op., Red. Port, Sealed SS Bolted Extended Bonnet, Graphite/TFE Packing, Flex Wedge, API-600 & 598, ASME B16.34 & B16.10, 500ppm VOC" "150" "1100" "OIC 8GT6LUSEG"))
  9. (SETQ X1TR-S2-2 (LIST "Valve, Piston Check, NPT, A-182 F316/A-351Gr.CF8M Body, SS Piston/Disc, SS Spring, API Trim 10, 12 or 16, 800#, -20 to 800 F, Bolted Bonnet, Std. Port, Renew. Seats, API-602 & 598, ASME B16.34" "150" "1100" "OIC 8GT6LUSEG"))
  10. (SETQ X4S-C1 (LIST "Valve, Gate, NPT, 800#, A-182 F316/A-351Gr.CF8M Body, SS Stem/Wedge/Seat/Bonnet, API Trim 10, 12 or 16, HW Op., Red. Port, Sealed SS Bolted Extended Bonnet, Graphite/TFE Packing, Flex Wedge, API-600 & 598, ASME B16.34 & B16.10, 500ppm VOC" "175" "1100" "OIC 8GL6LUSWG-EB"))
  11. (SETQ X4S-C1-2 (LIST "Valve, Butterfly, Insert Type, 300# RF, A-182 F316/A-351Gr.CF8M Body Extended Stem, SS, 17-4 PH or Inconel Shaft/Disc/Pins/Retainers/Rings, Cryogenic Trim to -320 F or Specified, PTFE or Kel-F Packing, ASME B16.34, API-609, Offset to be Specified by Engineer" "175" "1100" "OIC 8GL6LUSWG-EB"))
  12. (SETQ X4S-C1-3 (LIST "Valve, Swing Check, SW, 800#, A-182 F316/A-351Gr.CF8M Body, SS Disc/Pins, API Trim 10, 12 or 16, Cryogenic Trim to -320F unless otherwise indicated, SS Bolted Bonnet, Std. Port, Renew. Seats, API-600 & 598, ASME B16.34 & B16.10" "175" "1100" "OIC 8GL6LUSWG-EB"))
  13. (setq X4S-H1 (list "Valve, Globe, SW, 800#, A-105 Body, CS/13Cr Disc, HF-CS Seat, MS Stem, API Trim 5 or 8, -20 to 800 F, HW Op., Bolted Bonnet-OS&Y, Graphite Packing, Renew, Seats, API-602 & 598, ASME B16.34, 500ppm VOC" "175" "1100" "DSI 4211A8-18"))
  14. (setq X4S-H2 (list "Valve, Globe, SW, 800#, A-105 Body, CS/13Cr Disc, HF-CS Seat, MS Stem, API Trim 5 or 8, -20 to 800 F, HW Op., Bolted Bonnet-OS&Y, Graphite Packing, Renew, Seats, API-602 & 598, ASME B16.34, 500ppm VOC" "175" "1100" "DSI 4211A8-18"))
  15. (SETQ X4S-H2-3 (LIST "Valve, Trunnion Ball, 300# RF, A-216Gr.WCB/A-105 Body, SS Stem/Ball, Hydrocarbon Compatible Seat/O-Rings/Packing, -20 to 400 F, Gear Op., Full Port, Anti-blowout Stem, API-607, ASME B16.34 & B16.10, 500ppm VOC, Bubble Tight Seal" "175" "1100" "DSI 4211A8-18"))

 
我目前正在使用(car)(cadr)(caddr)和(caddr)获取数据。这些数据的结构都是相同的。
这是使用数据的例程的一部分,我想知道如何合并mapcar语句,这样就不必为每个数据段(在50-100之间)做四个表达式,这是一个重复循环。这是一个很大的处理过程,我相信这会减慢程序的速度,我知道mapcar是我用来缩短它的工具,但我只是没有练习,需要一些帮助来应用它。
 
不过,下面是子功能,其中有两个较长的方法(我认为会)来完成任务,因为您可以想象,将相同的行添加到我的所有数据条目中将创建大约500行新代码,我认为仅使用几行和mapcar即可完成相同的任务:
  1. (defun doTYPE ( vallist / c cell namedata)
  2. (if
  3. (setq cell (strcat "K" (itoa (vl-bb-ref 'excelrow))))
  4. (acet-ui-progress-init "Writing valve TYPES to Excel." (length vallist))
  5. );if
  6. (setq c 0)
  7. (setq len (length vallist))
  8. (setq cell (string_ cell))
  9. (repeat len
  10. (setq data (nth c vallist))
  11. (setq typedata (cadr data))
  12. (putcell cell typedata)
  13. (if (= typedata "U2TR-H2")
  14. (progn
  15. (setq desccell (strcat "I" (itoa (vl-bb-ref 'excelrow))))
  16. (setq descdata (car u2tr-h2))
  17. (PUTCELL desccell descdata)
  18. (setq tempcell (strcat "F" (itoa (vl-bb-ref 'excelrow))))
  19. (setq tempdata (cadr u2tr-h2))
  20. (PUTCELL tempcell tempdata)
  21. (setq presscell (strcat "E" (itoa (vl-bb-ref 'excelrow))))
  22. (setq pressdata (caddr u2tr-h2))
  23. (PUTCELL presscell pressdata)
  24. (setq mfrcell (strcat "A" (itoa (vl-bb-ref 'excelrow))))
  25. (setq mfrdata (cadddr u2tr-h2))
  26. (putcell mrfcell mrfdata)
  27. );PROGN
  28. );IF U2TR-H2
  29. (setq X1TR-H2 (list "Valve, Gate, NPT, 800#, A-105 Body, CS/13Cr Wedge, HF-CS Seat, MS Stem, API Trim 5 or 8, -20 to 800 F, HW Op., Red. Port, Bltd. Bonnet-OS&Y, Graphite Packing, Solid Wedge, Renew. Seats, API-602 & 598, ASME B16.34,
  30. 500ppm VOC" "595" "1100" "DSI 4121A8-18"))
  31. (if (= typedata "X1TR-H2")
  32. (progn
  33. (setq desccell (strcat "I" (itoa (vl-bb-ref 'excelrow))))
  34. (setq descdata (car X1TR-H2))
  35. (PUTCELL desccell descdata)
  36. (setq tempcell (strcat "F" (itoa (vl-bb-ref 'excelrow))))
  37. (setq tempdata (cadr X1TR-H2))
  38. (PUTCELL tempcell tempdata)
  39. (setq presscell (strcat "E" (itoa (vl-bb-ref 'excelrow))))
  40. (setq pressdata (caddr X1TR-H2))
  41. (PUTCELL presscell pressdata)
  42. (setq mfrcell (strcat "A" (itoa (vl-bb-ref 'excelrow))))
  43. (setq mfrdata (cadddr X1TR-H2))
  44. (PUTCELL mrfcell mrfdata)
  45. );PROGN
  46. );IF X1TR-H2
  47. (setq cell (string_ cell))
  48. (acet-ui-progress-safe c)
  49. (setq c (1+ c))
  50. );repeat
  51. (acet-ui-progress-done)
  52. (if (= c len)(dotag vallist));;goto do-tag sub
  53. );defun doname

 
现在它的行为很奇怪。。。看一看:
  1. Command: (setq mfrcell (strcat "A" (itoa (vl-bb-ref 'excelrow))))
  2. "A6"
  3. Command: (setq mfrdata (cadddr X1TR-H2))
  4. "DSI 4121A8-18"
  5. Command: (PUTCELL mrfcell mrfdata)
  6. ; error: bad argument type: stringp nil
  7. ;;not sure why routine did not put "DSI 4121A8-18" because...
  8. Command: !MFRDATA
  9. "DSI 4121A8-18"
  10. Command: !MFRCELL
  11. "A6"
  12. Even though these are showing as strings to me the routine gave a stringp nil error. So, I tried it manually, and it worked. The correct string was placed into the correct excel field, using:
  13. Command: (PUTCELL "A6" "DSI 4121A8-18")
  14. This one worked! Why, why why :/

 
这两个任务,我确实需要一些帮助。
 
任何人
回复

使用道具 举报

7o7

0

主题

93

帖子

93

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 23:09:08 | 显示全部楼层
也许你把“单元格”值放到一个有数据的单元格中,excel不允许你覆盖它。
回复

使用道具 举报

35

主题

2471

帖子

2447

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
174
发表于 2022-7-5 23:23:19 | 显示全部楼层
请注意,您颠倒了变量名称中的一些字母(“fr”与“rf”):
  1. (setq m[color=red]fr[/color]cell (strcat "A" (itoa (vl-bb-ref 'excelrow))))
  2. (setq m[color=red]fr[/color]data (cadddr X1TR-H2))
  3. (PUTCELL m[color=red]rf[/color]cell m[color=red]rf[/color]data)
回复

使用道具 举报

15

主题

243

帖子

228

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-5 23:32:20 | 显示全部楼层
谢谢Msasu!
 
 
7o7-Excel允许您覆盖现有单元格内容,但无论如何谢谢您!
回复

使用道具 举报

15

主题

243

帖子

228

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-5 23:40:56 | 显示全部楼层
好的,成交!没有使用mapcar,但有一个替代方案。。。一个或四个辅助函数。
来,看看。我告诉你,当我计算出最后一行,程序按预期运行时,我感到非常高兴。
这是一种方法,使用与我在上面发布的相同的数据列表
  1. (if vallist
  2. (acet-ui-progress-init "Writing valve TYPES to Excel." (length vallist))
  3. );if
  4. (setq c 0)
  5. (setq len (length vallist))
  6. (repeat len
  7. (setq cella (CELL-ADDR "K"))
  8. (setq data (nth c vallist))
  9. (setq cell (itoa (vl-bb-ref 'excelrow)))
  10. (setq typedata (cadr data))
  11. (putcell cella typedata)
  12. (setq typekey (read typedata))
  13.    (putcell (cell-addr "I") (desc-data typekey))
  14.    (PUTCELL (cell-addr "F") (temp-data typekey))
  15.    (PUTCELL (cell-addr "E") (press-data typekey))
  16.    (PUTCELL (cell-addr "A") (mfr-data typekey))
  17. (setq cell (string_ cell))
  18. (setq cellb (atoi cell))
  19. (vl-bb-set 'excelrow cellb)
  20. (acet-ui-progress-safe c)
  21. (setq c (1+ c))
  22. );repeat
  23. (acet-ui-progress-done)
  24. (setvar "cmdecho" 0)
  25. (princ "\n\t\t*************************************************************")(princ)
  26. (princ "\n\t\t***\tAutoExcel Report \t*******************************")(princ)
  27. (princ (strcat "\n\t\t***\t" (itoa (length @dupeslist)) " unique items duplicated in excel file \t\t***"))(princ)
  28. (princ "\n\t\t***\t")
  29. (princ lst)
  30. (princ "\n\t\t***\tThese items have had their cells colored Grey\t***")(princ)
  31. (princ "\n\t\t***\tFinished!\t\t\t\t\t*****************************")(princ)
  32. (princ "\n\t\t*************************************************************")(princ)
  33. (if vallist (setq svflg 1))
  34. (setq vallist nil)
  35. (vl-bb-set 'dupeslist nil)
  36. (setq @dupeslist nil)
  37. (setq @excel_row "6")
  38. (setq *excelApp% nil)
  39. (princ "\n")
  40. ;;end of excel input, routine will alert to user that it is complete
  41. (princ)
  42. (setq *error* nil)
  43. (gc)
  44. );defun dotype

 
我只是想说声谢谢,然后就过去了。喔!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 06:42 , Processed in 0.351785 second(s), 62 queries .

© 2020-2025 乐筑天下

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