乐筑天下

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

[编程交流] 计数块/按att v选择

[复制链接]

73

主题

261

帖子

195

银币

后起之秀

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

铜币
375
发表于 2022-7-5 15:32:32 | 显示全部楼层 |阅读模式
大家好,
我用李·麦克的套路做了一个Lisp程序的动作。(按att值选择)
目的是统计模块的数量(相同的块名)。它涉及“EID、ETV和IO”
它部分起作用。如果我有图纸中所有类型的模块,那么就可以了。但是,一旦我删除了一个类型,lisp仍然指示“OPT11”。我做错了什么?
我不知道在该部分中使用什么(如果没有:“,”0“或nil。
我使用了3次Lee的lisp按属性值进行选择。
这里出问题了吗?这个(3x Lee lisp)是否可以被1个例程替换,并且结果存储在变量(setq)“EIDS”、“ETV”“IO”中?。
 
 
  1. ;        Module counting     "MOD-COUNT" to run
  2. ;------------- Count EIDS -------------
  3. ;; Select Blocks by Attribute Value  -  Lee Mac
  4. ;; Selects all attributed blocks in the current layout which contain a specified attribute value.
  5. (defun c:EIDS ( / att atx ent idx sel1 str1 )
  6.    (if (/= "" (setq str1 "EIDS"))
  7.        (if (and
  8.                (setq sel1
  9.                    (ssget "_X"
  10.                        (list '(0 . "INSERT") '(66 . 1)
  11.                            (if (= 1 (getvar 'cvport))
  12.                                (cons 410 (getvar 'ctab))
  13.                               '(410 . "Model")
  14.                            )
  15.                        )
  16.                    )
  17.                )
  18.                (progn
  19.                    (repeat (setq idx (sslength sel1))
  20.                        (setq ent (ssname sel1 (setq idx (1- idx)))
  21.                              att (entnext ent)
  22.                              atx (entget  att)
  23.                        )
  24.                        (while
  25.                            (and (= "ATTRIB" (cdr (assoc 0 atx)))
  26.                                 (not (wcmatch (strcase (cdr (assoc 1 atx))) str1))
  27.                            )
  28.                            (setq att (entnext att)
  29.                                  atx (entget  att)
  30.                            )
  31.                        )
  32.                        (if (= "SEQEND" (cdr (assoc 0 atx)))
  33.                            (ssdel ent sel1)
  34.                        )
  35.                    )
  36.                    (< 0 (sslength sel1))
  37.                )
  38.            )
  39.            (sssetfirst nil sel1)
  40.            (princ (strcat "\nNo blocks found with attribute value matching "" str1 ""."))
  41.        )
  42.    )
  43.    (princ)
  44. (progn (setq n (sslength sel1))
  45. (setq EIDS (itoa n))
  46. )
  47. )
  48. ;------------- Count ETV -------------
  49. ;; Select Blocks by Attribute Value  -  Lee Mac
  50. ;; Selects all attributed blocks in the current layout which contain a specified attribute value.
  51. (defun c:ETV ( / att atx ent idx sel2 str2 )
  52.    (if (/= "" (setq str2 "ETV"))
  53.        (if (and
  54.                (setq sel2
  55.                    (ssget "_X"
  56.                        (list '(0 . "INSERT") '(66 . 1)
  57.                            (if (= 1 (getvar 'cvport))
  58.                                (cons 410 (getvar 'ctab))
  59.                               '(410 . "Model")
  60.                            )
  61.                        )
  62.                    )
  63.                )
  64.                (progn
  65.                    (repeat (setq idx (sslength sel2))
  66.                        (setq ent (ssname sel2 (setq idx (1- idx)))
  67.                              att (entnext ent)
  68.                              atx (entget  att)
  69.                        )
  70.                        (while
  71.                            (and (= "ATTRIB" (cdr (assoc 0 atx)))
  72.                                 (not (wcmatch (strcase (cdr (assoc 1 atx))) str2))
  73.                            )
  74.                            (setq att (entnext att)
  75.                                  atx (entget  att)
  76.                            )
  77.                        )
  78.                        (if (= "SEQEND" (cdr (assoc 0 atx)))
  79.                            (ssdel ent sel2)
  80.                        )
  81.                    )
  82.                    (< 0 (sslength sel2))
  83.                )
  84.            )
  85.            (sssetfirst nil sel2)
  86.            (princ (strcat "\nNo blocks found with attribute value matching "" str2 ""."))
  87.        )
  88.    )
  89.    (princ)
  90. (progn (setq n (sslength sel2))
  91. (setq ETV (itoa n))
  92. )
  93. )
  94. ;------------- Count IO -------------
  95. ;; Select Blocks by Attribute Value  -  Lee Mac
  96. ;; Selects all attributed blocks in the current layout which contain a specified attribute value.
  97. (defun c:IO ( / att atx ent idx sel3 str3 )
  98.    (if (/= "" (setq str3 "I/O"))
  99.        (if (and
  100.                (setq sel3
  101.                    (ssget "_X"
  102.                        (list '(0 . "INSERT") '(66 . 1)
  103.                            (if (= 1 (getvar 'cvport))
  104.                                (cons 410 (getvar 'ctab))
  105.                               '(410 . "Model")
  106.                            )
  107.                        )
  108.                    )
  109.                )
  110.                (progn
  111.                    (repeat (setq idx (sslength sel3))
  112.                        (setq ent (ssname sel3 (setq idx (1- idx)))
  113.                              att (entnext ent)
  114.                              atx (entget  att)
  115.                        )
  116.                        (while
  117.                            (and (= "ATTRIB" (cdr (assoc 0 atx)))
  118.                                 (not (wcmatch (strcase (cdr (assoc 1 atx))) str3))
  119.                            )
  120.                            (setq att (entnext att)
  121.                                  atx (entget  att)
  122.                            )
  123.                        )
  124.                        (if (= "SEQEND" (cdr (assoc 0 atx)))
  125.                            (ssdel ent sel3)
  126.                        )
  127.                    )
  128.                    (< 0 (sslength sel3))
  129.                )
  130.            )
  131.            (sssetfirst nil sel3)
  132.            (princ (strcat "\nNo blocks found with attribute value matching "" str3 ""."))
  133.        )
  134.    )
  135.    (princ)
  136. (progn (setq n (sslength sel3))
  137. (setq IO (itoa n))
  138. )
  139. )
  140. ; ------------- Set Amount -------------
  141. (defun c:amount ()
  142. (if (and (= EIDS nil)        (= ETV "1")        (= IO nil))        (setq Module "OPT1"))
  143. (if (and (= EIDS "1")        (= ETV nil)        (= IO nil))        (setq Module "OPT2"))
  144. (if (and (= EIDS "1")        (= ETV nil)        (= IO "1"))        (setq Module "OPT3"))
  145. (if (and (= EIDS "1")        (= ETV nil)        (= IO "2"))        (setq Module "OPT4"))
  146. (if (and (= EIDS "1")        (= ETV nil)        (= IO "3"))        (setq Module "OPT5"))
  147. (if (and (= EIDS "1")        (= ETV nil)        (= IO "4"))        (setq Module "OPT6"))
  148. (if (and (= EIDS "1")        (= ETV nil)        (= IO "5"))        (setq Module "OPT7"))
  149. (if (and (= EIDS "1")        (= ETV "1")        (= IO nil))        (setq Module "OPT8"))
  150. (if (and (= EIDS "1")        (= ETV "1")        (= IO "1"))        (setq Module "OPT9"))
  151. (if (and (= EIDS "1")        (= ETV "1")        (= IO "2"))        (setq Module "OPT10"))
  152. (if (and (= EIDS "1")         (= ETV "1")        (= IO "3"))        (setq Module "OPT11"))
  153. ;(setenv 'USER1' ")
  154. ;(setenv'USER1' Module)
  155. ;(setq USl (getenv'USER1'))
  156. (alert module); to test
  157. )
  158. i------------- Main / Run -------------
  159. (defun c:test ()
  160. ;(setq EIDS nil)
  161. ;(setq ETV nil)
  162. ;(setq IO nil)
  163. ;(setq amount nil)
  164. (c:EIDS)
  165. (c:ETV)
  166. (c:IO)
  167. (c:amount)
  168. )

 
提前谢谢你
 
PmxCAD
平面布置图。图纸
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 15:46:07 | 显示全部楼层
只是一点猜测,如果你不检查不存在,添加一个额外的。
  1. (if (= module nil)((setq module "Not found"))
回复

使用道具 举报

73

主题

261

帖子

195

银币

后起之秀

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

铜币
375
发表于 2022-7-5 16:00:45 | 显示全部楼层
嗨,比格尔,
谢谢你的回复,但问题已经解决了。所以它必须是“0”。
 
  1. ;    Module counting     "MOD-COUNT" to run
  2. ;------------- Count EIDS -------------
  3. ;; Select Blocks by Attribute Value  -  Lee Mac
  4. ;; Selects all attributed blocks in the current layout which contain a specified attribute value.
  5. (defun c:EIDS ( / att atx ent idx sel1 str1 )
  6.    (if (/= "" (setq str1 "EIDS"))
  7.        (if (and
  8.                (setq sel1
  9.                    (ssget "_X"
  10.                        (list '(0 . "INSERT") '(66 . 1)
  11.                            (if (= 1 (getvar 'cvport))
  12.                                (cons 410 (getvar 'ctab))
  13.                               '(410 . "Model")
  14.                            )
  15.                        )
  16.                    )
  17.                )
  18.                (progn
  19.                    (repeat (setq idx (sslength sel1))
  20.                        (setq ent (ssname sel1 (setq idx (1- idx)))
  21.                              att (entnext ent)
  22.                              atx (entget  att)
  23.                        )
  24.                        (while
  25.                            (and (= "ATTRIB" (cdr (assoc 0 atx)))
  26.                                 (not (wcmatch (strcase (cdr (assoc 1 atx))) str1))
  27.                            )
  28.                            (setq att (entnext att)
  29.                                  atx (entget  att)
  30.                            )
  31.                        )
  32.                        (if (= "SEQEND" (cdr (assoc 0 atx)))
  33.                            (ssdel ent sel1)
  34.                        )
  35.                    )
  36.                    (< 0 (sslength sel1))
  37.                )
  38.            )
  39.            (sssetfirst nil sel1)
  40.            (princ (strcat "\nNo blocks found with attribute value matching "" str1 ""."))
  41.        )
  42.    )
  43.    (princ)
  44. (progn (setq n1 (sslength sel1))
  45. (setq EIDS (itoa n1))
  46. )
  47. ;(alert eids)
  48. )
  49. ;------------- Count ETV -------------
  50. ;; Select Blocks by Attribute Value  -  Lee Mac
  51. ;; Selects all attributed blocks in the current layout which contain a specified attribute value.
  52. (defun c:ETV ( / att atx ent idx sel2 str2 )
  53.    (if (/= "" (setq str2 "ETV"))
  54.        (if (and
  55.                (setq sel2
  56.                    (ssget "_X"
  57.                        (list '(0 . "INSERT") '(66 . 1)
  58.                            (if (= 1 (getvar 'cvport))
  59.                                (cons 410 (getvar 'ctab))
  60.                               '(410 . "Model")
  61.                            )
  62.                        )
  63.                    )
  64.                )
  65.                (progn
  66.                    (repeat (setq idx (sslength sel2))
  67.                        (setq ent (ssname sel2 (setq idx (1- idx)))
  68.                              att (entnext ent)
  69.                              atx (entget  att)
  70.                        )
  71.                        (while
  72.                            (and (= "ATTRIB" (cdr (assoc 0 atx)))
  73.                                 (not (wcmatch (strcase (cdr (assoc 1 atx))) str2))
  74.                            )
  75.                            (setq att (entnext att)
  76.                                  atx (entget  att)
  77.                            )
  78.                        )
  79.                        (if (= "SEQEND" (cdr (assoc 0 atx)))
  80.                            (ssdel ent sel2)
  81.                        )
  82.                    )
  83.                    (< 0 (sslength sel2))
  84.                )
  85.            )
  86.            (sssetfirst nil sel2)
  87.            (princ (strcat "\nNo blocks found with attribute value matching "" str2 ""."))
  88.        )
  89.    )
  90.    (princ)
  91. (progn (setq n2 (sslength sel2))
  92. (setq ETV (itoa n2))
  93. )
  94. ;(alert etv)
  95. )
  96. ;------------- Count IO -------------
  97. ;; Select Blocks by Attribute Value  -  Lee Mac
  98. ;; Selects all attributed blocks in the current layout which contain a specified attribute value.
  99. (defun c:IO ( / att atx ent idx sel3 str3 )
  100.    (if (/= "" (setq str3 "I/O"))
  101.        (if (and
  102.                (setq sel3
  103.                    (ssget "_X"
  104.                        (list '(0 . "INSERT") '(66 . 1)
  105.                            (if (= 1 (getvar 'cvport))
  106.                                (cons 410 (getvar 'ctab))
  107.                               '(410 . "Model")
  108.                            )
  109.                        )
  110.                    )
  111.                )
  112.                (progn
  113.                    (repeat (setq idx (sslength sel3))
  114.                        (setq ent (ssname sel3 (setq idx (1- idx)))
  115.                              att (entnext ent)
  116.                              atx (entget  att)
  117.                        )
  118.                        (while
  119.                            (and (= "ATTRIB" (cdr (assoc 0 atx)))
  120.                                 (not (wcmatch (strcase (cdr (assoc 1 atx))) str3))
  121.                            )
  122.                            (setq att (entnext att)
  123.                                  atx (entget  att)
  124.                            )
  125.                        )
  126.                        (if (= "SEQEND" (cdr (assoc 0 atx)))
  127.                            (ssdel ent sel3)
  128.                        )
  129.                    )
  130.                    (< 0 (sslength sel3))
  131.                )
  132.            )
  133.            (sssetfirst nil sel3)
  134. ;            (princ (strcat "\nNo blocks found with attribute value matching "" str3 ""."))
  135.        )
  136.    )
  137.    (princ)
  138. (progn (setq n3 (sslength sel3))
  139. (setq IO (itoa n3))
  140. )
  141. ;(alert io)
  142. )
  143. ; ------------- Set Amount -------------
  144. (defun c:amount ()
  145. (if (and (= EIDS "0")    (= ETV "1")    (= IO "0"))    (setq Module "OPT1"))
  146. (if (and (= EIDS "1")    (= ETV "0")    (= IO "0"))    (setq Module "OPT2"))
  147. (if (and (= EIDS "1")    (= ETV "0")    (= IO "1"))    (setq Module "OPT3"))
  148. (if (and (= EIDS "1")    (= ETV "0")    (= IO "2"))    (setq Module "OPT4"))
  149. (if (and (= EIDS "1")    (= ETV "0")    (= IO "3"))    (setq Module "OPT5"))
  150. (if (and (= EIDS "1")    (= ETV "0")    (= IO "4"))    (setq Module "OPT6"))
  151. (if (and (= EIDS "1")    (= ETV "0")    (= IO "5"))    (setq Module "OPT7"))
  152. (if (and (= EIDS "1")    (= ETV "1")    (= IO "0"))    (setq Module "OPT8"))
  153. (if (and (= EIDS "1")    (= ETV "1")    (= IO "1"))    (setq Module "OPT9"))
  154. (if (and (= EIDS "1")    (= ETV "1")    (= IO "2"))    (setq Module "OPT10"))
  155. (if (and (= EIDS "1")     (= ETV "1")    (= IO "3"))    (setq Module "OPT11"))
  156. ;(setenv 'USER1' ")
  157. ;(setenv'USER1' Module)
  158. ;(setq USl (getenv'USER1'))
  159. (alert module)
  160. )
  161. i------------- Main / Run -------------
  162. (defun c:MOD-COUNT ()
  163. (c:EIDS)
  164. (c:ETV)
  165. (c:IO)
  166. (c:amount)
  167. )

 
PmxCAD
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:03:03 | 显示全部楼层
以下是另一种方法(未经测试):
  1. ;; Count Blocks by Attribute Value  -  Lee Mac
  2. (defun CountBlocksByAttribValue ( lst / att atx ent idx itm key rtn sel )
  3.    (if (setq lst (mapcar 'strcase lst)
  4.              sel (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))
  5.        )
  6.        (repeat (setq idx (sslength sel))
  7.            (setq ent (ssname  sel (setq idx (1- idx)))
  8.                  att (entnext ent)
  9.                  atx (entget  att)
  10.            )
  11.            (while (= "ATTRIB" (cdr (assoc 0 atx)))
  12.                (cond
  13.                    (   (not (member (setq key (strcase (cdr (assoc 1 atx)))) lst)))
  14.                    (   (setq itm (assoc key rtn))
  15.                        (setq rtn (subst (cons key (1+ (cdr itm))) itm rtn))
  16.                    )
  17.                    (   (setq rtn (cons (cons key 1) rtn)))
  18.                )
  19.                (setq att (entnext att)
  20.                      atx (entget  att)
  21.                )
  22.            )
  23.        )
  24.    )
  25.    rtn
  26. )
  27. (defun c:test ( / key lst )
  28.    (setq key '("EIDS" "ETV" "I/O")
  29.          lst  (CountBlocksByAttribValue key)
  30.    )
  31.    (cdr
  32.        (assoc (mapcar '(lambda ( k ) (cond ((cdr (assoc k lst))) (0))) key)
  33.           '(
  34.                ((0 1 0) . "OPT1")
  35.                ((1 0 0) . "OPT2")
  36.                ((1 0 1) . "OPT3")
  37.                ((1 0 2) . "OPT4")
  38.                ((1 0 3) . "OPT5")
  39.                ((1 0 4) . "OPT6")
  40.                ((1 0 5) . "OPT7")
  41.                ((1 1 0) . "OPT8")
  42.                ((1 1 1) . "OPT9")
  43.                ((1 1 2) . "OPT10")
  44.                ((1 1 3) . "OPT11")
  45.            )
  46.        )
  47.    )
  48. )
回复

使用道具 举报

73

主题

261

帖子

195

银币

后起之秀

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

铜币
375
发表于 2022-7-5 16:18:48 | 显示全部楼层
和往常一样,李又是一个很好的明确的常规动作。
结果现在在命令行上,是否也可以存储在变量(setq)中?
 
PmxCAD
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:26:02 | 显示全部楼层
 
当然-(setq xxx(cdr(assoc。。。
 
(我相信你本可以解决这个问题)
回复

使用道具 举报

73

主题

261

帖子

195

银币

后起之秀

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

铜币
375
发表于 2022-7-5 16:39:02 | 显示全部楼层
是的。。解决了的。
谢谢李。
 
  1. ;; Count Blocks by Attribute Value  -  Lee Mac
  2. (defun CountBlocksByAttribValue ( lst / att atx ent idx itm key rtn sel )
  3.    (if (setq lst (mapcar 'strcase lst)
  4.              sel (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 .
  5. "Model"))))
  6.        )
  7.        (repeat (setq idx (sslength sel))
  8.            (setq ent (ssname  sel (setq idx (1- idx)))
  9.                  att (entnext ent)
  10.                  atx (entget  att)
  11.            )
  12.            (while (= "ATTRIB" (cdr (assoc 0 atx)))
  13.                (cond
  14.                    (   (not (member (setq key (strcase (cdr (assoc 1 atx)))) lst)))
  15.                    (   (setq itm (assoc key rtn))
  16.                        (setq rtn (subst (cons key (1+ (cdr itm))) itm rtn))
  17.                    )
  18.                    (   (setq rtn (cons (cons key 1) rtn)))
  19.                )
  20.                (setq att (entnext att)
  21.                      atx (entget  att)
  22.                )
  23.            )
  24.        )
  25.    )
  26.    rtn
  27. )
  28. (defun c:test ( / key lst )
  29.    (setq key '("EIDS" "ETV" "I/O")
  30.          lst  (CountBlocksByAttribValue key)
  31.    )
  32.    (setq result (cdr
  33.        (assoc (mapcar '(lambda ( k ) (cond ((cdr (assoc k lst))) (0))) key)
  34.           '(
  35.                ((0 1 0) . "OPT1")
  36.                ((1 0 0) . "OPT2")
  37.                ((1 0 1) . "OPT3")
  38.                ((1 0 2) . "OPT4")
  39.                ((1 0 3) . "OPT5")
  40.                ((1 0 4) . "OPT6")
  41.                ((1 0 5) . "OPT7")
  42.                ((1 1 0) . "OPT8")
  43.                ((1 1 1) . "OPT9")
  44.                ((1 1 2) . "OPT10")
  45.                ((1 1 3) . "OPT11")
  46.            )
  47.        )
  48.    )
  49. )
  50. )
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-14 21:04 , Processed in 3.102408 second(s), 66 queries .

© 2020-2025 乐筑天下

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