乐筑天下

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

[编程交流] Lisp在specify上计算块数

[复制链接]

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 06:58:00 | 显示全部楼层 |阅读模式
如何操作此lisp以仅计算特定层上的块?
 
我的所有图层都以“E_…”开头例如E_电源、E_灯等。
 
我得到了这个Lisp程序的网站,它的工作像一个梦。。。如果可以将if更改为仅在名称以“E_…”开头的图层上识别和计数块,则会更有帮助
 
谢谢
 
回复

使用道具 举报

9

主题

383

帖子

82

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
355
发表于 2022-7-6 07:03:54 | 显示全部楼层
  1. (defun c:test (/ SS)
  2. (if (setq SS (ssget "_X"
  3.               (list (cons 0 "INSERT") (cons 410 (getvar "CTAB")) (cons 8 "E_*"))
  4.        )
  5.      )
  6.    (prompt (strcat "\nTotal " (itoa (sslength SS)) " blocks."))
  7. )
  8. (princ)
  9. )
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 07:07:38 | 显示全部楼层
请注意,lisp仅统计当前空间中的块。对于整个DWG删除的计数
这(cons 410(getvar“CTAB”))
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 07:13:58 | 显示全部楼层
这是你日常生活的一个模式。
  1. ;;********************
  2. ;;*                  *
  3. ;;* C:BlocksList.LSP *
  4. ;;*                  *
  5. ;;********************
  6. (defun C:BlocksList (                   ; Command emulation; ( local variables
  7.                     /            Option; User option for output of block quantities (or exit)
  8.                     C_layer            ; Current layer's name con'd with its assoc key (
  9.                     Block_list         ; List of block's table information
  10.                     Block_cons         ; List of block's name con'd with 2 (its assoc key)
  11.                     Block_set          ; Selection set of all blocks with given name (& on curr layer)
  12.                     Block_name         ; Current block's name
  13.                     Block_srch         ; Search criteria for finding/selecting blocks
  14.                     Count$             ; Quantity of selected blocks as a string value
  15.                     Pattern            ; Wild Card match layer name
  16.                    )                   ; Close defun's local variables list
  17. (cond                                 ; Begin routine--get user input first
  18.    ((initget "All Current Pattern eXit"))      ; Initialize options for user input
  19.    ((= "eXit"
  20.        (setq
  21.          Option (getkword
  22.                   (strcat "List ["
  23.                           "All occurrences/Current layer only/Pattern/eXit"
  24.                           "] <Current layer only>: "
  25.                   )
  26.                 )
  27.        )
  28.     )
  29.    )                                   ; Default is do blocks on current layer
  30.    (T
  31.     (if (= Option "Pattern") ; Wild Card match
  32.       (while (= (vl-string-trim " \t\n"
  33.                   (setq Pattern (getstring t "\nEnter Layer name pattern. "))) "")
  34.         (prompt "\nYou must enter a layer name.")
  35.       )
  36.     )
  37.     (textscr)
  38.     (prompt
  39.       "\nPlease wait...Counting block insertions...Found..."
  40.     )
  41.     (cond
  42.       ((= Option "All"))
  43.       ((= Option "Pattern")(setq C_layer (cons 8 Pattern)))
  44.       ((setq C_layer (cons 8 (getvar "CLAYER"))))
  45.     )
  46.     (while                             ; Inform user processing is starting
  47.       (setq Block_list (tblnext "BLOCK" (not Block_list)))
  48.        (setq Block_cons (assoc 2 Block_list)
  49.              Block_name (cdr Block_cons)
  50.              Block_srch (cond          ; Step through entire block name database
  51.                           ((= (ascii Block_name) 42) nil)
  52.                                        ; Ignore anonymous blocks: "*..."
  53.                           ((= Option "All") (list Block_cons))
  54.                           (T (list Block_cons C_layer))
  55.                         )
  56.        )                               ; Limit to current layer if All not opted
  57.        (cond                           ; Now output (ignores unused blocknames)
  58.          ((and Block_srch (setq Block_set (ssget "X" Block_srch)))
  59.           (setq Count$ (itoa (sslength Block_set)))
  60.           (prompt
  61.             (strcat "\n"               ; Build prompt string--pretty-print qty
  62.                     (substr "      " 1 (- 6 (strlen Count$)))
  63.                     Count$
  64.                     " "
  65.                     Block_name         ; Output qty & block name to screen
  66.             )
  67.           )
  68.          )                             ; Close cond's only opt & prompt-strcat
  69.        )
  70.     )                                  ; Close processing while & its cond
  71.     (or Count$ (prompt "\n**< None Found >**"))
  72.    )
  73. )                                     ; Close main cond & its T option
  74. (princ)                               ; Quiet exit
  75. )                                       ; The END (close defun C:BlocksList)
  76. (C:BlocksList)                          ; Auto-call @ actual, not dummy, load
回复

使用道具 举报

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 07:17:51 | 显示全部楼层
谢谢,很有效。
 
不过我有一个小问题。。。有一个街区叫“UnderFloorHeating”。。。现在,如果我用lisp并选择“All ocurances”,它会计算17。
 
但是如果我做一个quickselect,有21个。。。他们都在同一层,但Lisp程序似乎无法计算他们。
 
有什么帮助吗?
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 07:20:18 | 显示全部楼层
你能发布一个示例DWG,以便我们测试错误吗?
回复

使用道具 举报

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 07:26:33 | 显示全部楼层
好啊开始了
UFH测试。图纸
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 07:30:29 | 显示全部楼层
将DWG保存回ACAD2000,这是我得到的。
没有名为“UnderFloorHeating”的区块
  1. Command: blockslist
  2. List [All occurrences/Current layer only/Pattern/eXit] <Current layer only>: a
  3. Please wait...Counting block insertions...Found...
  4.     6 Double Fluorescent
  5.   358 Downlighter
  6.    20 1 Lever Switch
  7.    60 DimmerSwitch
  8.    26 2 Way Switching
  9.     9 Ceiling Mount Light
  10.     7 Shaver Socket
  11.     9 UpDown Wall Mounted Light
  12.     3 Distribution Board
  13.     6 Internal Wall Mounted Light
  14.     2 Pendant Light
  15.    11 Garden Light
  16.     3 Pool Light
  17.    70 Double Switched Socket
  18.    24 Single Switched Socket
  19.     3 Intermediate Switch
  20.     3 Enclosure
  21.     6 External Wall Mounted Light
  22.     3 Stove Isolator
  23.     7 Weather Proof Plug

 
使用另一个例程:
  1. Command: blkcount
  2. (("*U10" . 17)
  3. ("*U17" . 4)
  4. ("*U21" . 11)
  5. ("*U9" . 7)
  6. ("1 Lever Switch" . 20)
  7. ("2 Way Switching" . 26)
  8. ("Ceiling Mount Light" . 9)
  9. ("DimmerSwitch" . 60)
  10. ("Distribution Board" . 3)
  11. ("Double Fluorescent" . 6)
  12. ("Double Switched Socket" . 70)
  13. ("Downlighter" . 358)
  14. ("Enclosure" . 3)
  15. ("External Wall Mounted Light" . 6)
  16. ("Garden Light" . 11)
  17. ("Intermediate Switch" . 3)
  18. ("Internal Wall Mounted Light" . 6)
  19. ("Pendant Light" . 2)
  20. ("Pool Light" . 3)
  21. ("Shaver Socket" . 7)
  22. ("Single Switched Socket" . 24)
  23. ("Stove Isolator" . 3)
  24. ("UpDown Wall Mounted Light" . 9)
  25. ("Weather Proof Plug" . 7))
回复

使用道具 举报

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 07:34:34 | 显示全部楼层
这是我得到的
 
  1. Command:
  2. Current block modes: Unused = IGNORE,  Anonymous = IGNORE, Layers = ALL
  3. Send report to [Printer/Screen/File/Unused/Anonymous/Layers/eXit] <c:\documents
  4. and settings\design.desktop\desktop\ufh-test.blk>: S
  5. Please wait...Counting block inserts...
  6. Writing results to: Text Window
  7.        6    Double Fluorescent
  8.      358    Downlighter
  9.       20    1 Lever Switch
  10.       60    DimmerSwitch
  11.       26    2 Way Switching
  12.        9    Ceiling Mount Light
  13.        7    Shaver Socket
  14.        7    Heated Towel Rail
  15.       17    UnderFloorHeating
  16.        9    UpDown Wall Mounted Light
  17.        3    Distribution Board
  18.        6    Internal Wall Mounted Light
  19.        2    Pendant Light
  20.       11    Garden Light
  21.        3    Pool Light
  22.       70    Double Switched Socket
  23.       24    Single Switched Socket
  24.        3    Intermediate Switch
  25.       11    Aircon Point
  26.        3    Enclosure
  27.        6    External Wall Mounted Light
  28.        3    Stove Isolator
  29.        7    Weather Proof Plug
回复

使用道具 举报

4

主题

2143

帖子

2197

银币

限制会员

铜币
-24
发表于 2022-7-6 07:40:11 | 显示全部楼层
真奇怪。。。我用BCOUNT也得到17。Qselect给出21,图中有21。出于某种原因,块计数器LISP无法识别其中4个块。
 
  1. Command: [size=3][b]bcount
  2. [/b][/size]
  3. Initializing...
  4. Press Enter to select all or...
  5. Select objects:
  6. Block............................Count
  7. --------------------------------------
  8. Double Fluorescent...............6
  9. Distribution Board...............3
  10. Pendant Light....................2
  11. Internal Wall Mounted Light......6
  12. UpDown Wall Mounted Light........9
  13. Ceiling Mount Light..............9
  14. 2 Way Switching..................26
  15. Garden Light.....................11
  16. Pool Light.......................3
  17. Downlighter......................358
  18. Shaver Socket....................7
  19. Heated Towel Rail................7
  20. DimmerSwitch.....................60
  21. Intermediate Switch..............3
  22. Double Switched Socket...........70
  23. Aircon Point.....................11
  24. Enclosure........................3
  25. 1 Lever Switch...................20
  26. External Wall Mounted Light......6
  27. Stove Isolator...................3
  28. Single Switched Socket...........24
  29. Weather Proof Plug...............7
  30. [b]UnderFloorHeating................17[/b]
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 10:24 , Processed in 0.358370 second(s), 72 queries .

© 2020-2025 乐筑天下

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