乐筑天下

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

[编程交流] 非常健壮的lisp

[复制链接]

1

主题

9

帖子

8

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 12:05:19 | 显示全部楼层
更新版本-愚蠢的我忘记设置cmdecho
 
  1. (defun c:tagger     (/ *error* vLst oVars ans pTxt    sTxt cnt iPt drTag bubTag drTagLst
  2.             bubTagLst lAns 1pt 2pt lAng chrLst sChr)
  3. (vl-load-com)
  4. (defun *error*  (msg)
  5.    (if    oVars
  6.      (mapcar 'setvar vLst oVars))
  7.    (if    (eq "" msg)
  8.      (princ "\n<< Function Complete >>")
  9.      (princ (strcat "Error: " (strcase msg))))
  10.    (princ))
  11. (setq    vLst  (list "OSMODE" "CLAYER" "ATTREQ" "BLIPMODE")
  12.    oVars (mapcar 'getvar vLst))
  13. (mapcar 'makelay '("A-DOOR-IDEN" "S-GRID-IDEN" "S-GRID") '("5" "4" "2"))
  14. (if (and (tblsearch "BLOCK" "Tagdoor1") (tblsearch "BLOCK" "Grdbub01"))
  15.    (progn
  16.      (if (not TG:oans)
  17.    (setq TG:oans "Door"))
  18.      (if (not TG:olans)
  19.    (setq TG:olans "Yes"))
  20.      (initget "Door Bubble")
  21.      (setq ans (getkword (strcat "\nSpecify Tag Type [Door/Bubble] <" TG:oans ">: ")))
  22.      (if (not ans)
  23.    (setq ans TG:oans)
  24.    (setq TG:oans ans))
  25.      (if (and (setq pTxt (getstring t "\nSpecify Prefix Text <Enter for no Prefix>:  "))
  26.           (not (initget 5))
  27.           (setq sNum (getint "\nSpecify Starting Number: ")
  28.             sTxt (getstring t "\nSpecify Suffix Text <Enter for no Suffix>:  ")))
  29.    (progn
  30.      (setq cnt 0)
  31.      (mapcar 'setvar vLst (list 0 "0" 0 0))
  32.      (cond    ((= ans "Bubble")
  33.         (initget "Yes No")
  34.         (setq lAns (getkword (strcat "\nGrid-Line? [Yes/No] <" TG:olans ">: ")))
  35.         (if (not lAns)
  36.           (setq lAns TG:olans)
  37.           (setq TG:olans lAns))
  38.         (cond ((= lAns "No")
  39.            (while (setq iPt (getpoint "\nSelect Point for Symbol > "))
  40.              (setvar "clayer" "S-GRID-IDEN")
  41.              (command "-insert" "Grdbub01" iPt "" "" "")
  42.              (setq bubTag (entnext (entlast)))
  43.              (while (/= "SEQEND" (cdadr (setq bubTagLst (entget bubTag))))
  44.                (if    (= "GRIDNUM" (cdr (assoc 2 bubTagLst)))
  45.                  (entmod (subst (cons 1 (strcat pTxt (rtos (+ sNum cnt) 2 0) sTxt))
  46.                         (assoc 1 bubTagLst)
  47.                         bubTagLst)))
  48.                (setq bubTag (entnext bubTag)))
  49.              (command "_regenall")
  50.              (setq cnt (1+ cnt))))
  51.               ((= lAns "Yes")
  52.            (while (and (setq 1pt (getpoint "\nSpecify Grid-Line First Point > "))
  53.                    (setq 2pt (getpoint 1pt "\nSpecify Second Grid-Line Point > ")))
  54.              (setvar "clayer" "S-GRID")
  55.              (command "_line" 1pt 2pt "")
  56.              (setq    grLin (entlast)
  57.                lAng  (angle 1pt 2pt)
  58.                iPt   (polar 2pt lAng 0.5))
  59.              (setvar "clayer" "S-GRID-IDEN")
  60.              (command "-insert" "Grdbub01" iPt "" "" "")
  61.              (setq bubTag (entnext (entlast)))
  62.              (while (/= "SEQEND" (cdadr (setq bubTagLst (entget bubTag))))
  63.                (if    (= "GRIDNUM" (cdr (assoc 2 bubTagLst)))
  64.                  (entmod (subst (cons 1 (strcat pTxt (rtos (+ sNum cnt) 2 0) sTxt))
  65.                         (assoc 1 bubTagLst)
  66.                         bubTagLst)))
  67.                (setq bubTag (entnext bubTag)))
  68.              (command "_regenall")
  69.              (setq cnt (1+ cnt))))))
  70.        ((= ans "Door")
  71.         (setq chrLst (vl-string->list sTxt))
  72.         (if chrLst
  73.           (setq sChr (last chrLst))
  74.           (setq sChr 65))
  75.         (while    (and (setq iPt (getpoint "\nSelect Point for Symbol > "))
  76.                 (< (+ sChr cnt) 91))
  77.           (setvar "clayer" "A-DOOR-IDEN")
  78.           (command "-insert" "Tagdoor1" iPt "" "" "")
  79.           (setq drTag (entnext (entlast)))
  80.           (while (/= "SEQEND" (cdadr (setq drTagLst (entget drTag))))
  81.             (if (= "DR1NUM" (cdr (assoc 2 drTagLst)))
  82.               (entmod (subst (cons 1 (strcat pTxt (rtos sNum 2 0) (chr (+ sChr cnt))))
  83.                      (assoc 1 drTagLst)
  84.                      drTagLst)))
  85.             (setq drTag (entnext drTag)))
  86.           (command "_regenall")
  87.           (setq cnt (1+ cnt))))))))
  88.    (princ "\n<!> One or More Blocks not Found <!>"))
  89. (*error* "")
  90. (princ))
  91. (defun makelay    (x y)
  92. (if (not (tblsearch "LAYER" x))
  93.    (command "-layer" "M" x "C" y x "")))
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:09:14 | 显示全部楼层
如果它确实是您希望块引用的文件路径,请确保使用双反斜杠将突出显示的部分填充到每个块的正确文件路径(一直到文件级)。
 

 
C: \\Users\\LeeMac\\Documents\\Block1。图纸
 
  1. (defun c:tagger     (/ *error* vLst oVars ans pTxt    sTxt cnt iPt drTag bubTag drTagLst bubTagLst lAns 1pt 2pt lAng chrLst
  2.          sChr)
  3. (vl-load-com)
  4. (defun *error*  (msg)
  5.    (if    oVars
  6.      (mapcar 'setvar vLst oVars))
  7.    (if    (eq "" msg)
  8.      (princ "\n<< Function Complete >>")
  9.      (princ (strcat "Error: " (strcase msg))))
  10.    (princ))
  11. (setq    vLst  (list "OSMODE" "CLAYER" "ATTREQ" "BLIPMODE" "CMDECHO")
  12.    oVars (mapcar 'getvar vLst))
  13. (mapcar 'setvar vLst (list 0 "0" 0 0 0))
  14. (mapcar 'makelay '("A-DOOR-IDEN" "S-GRID-IDEN" "S-GRID") '("5" "4" "2"))
  15. (if (and (tblsearch "BLOCK" "Tagdoor1") (tblsearch "BLOCK" "Grdbub01"))
  16.    (progn
  17.      (if (not TG:oans)
  18.    (setq TG:oans "Door"))
  19.      (if (not TG:olans)
  20.    (setq TG:olans "Yes"))
  21.      (initget "Door Bubble")
  22.      (setq ans (getkword (strcat "\nSpecify Tag Type [Door/Bubble] <" TG:oans ">: ")))
  23.      (if (not ans)
  24.    (setq ans TG:oans)
  25.    (setq TG:oans ans))
  26.      (if (and (setq pTxt (getstring t "\nSpecify Prefix Text <Enter for no Prefix>:  "))
  27.           (not (initget 5))
  28.           (setq sNum (getint "\nSpecify Starting Number: ")
  29.             sTxt (getstring t "\nSpecify Suffix Text <Enter for no Suffix>:  ")))
  30.    (progn
  31.      (setq cnt 0)
  32.      (cond    ((= ans "Bubble")
  33.         (initget "Yes No")
  34.         (setq lAns (getkword (strcat "\nGrid-Line? [Yes/No] <" TG:olans ">: ")))
  35.         (if (not lAns)
  36.           (setq lAns TG:olans)
  37.           (setq TG:olans lAns))
  38.         (cond ((= lAns "No")
  39.            (while (setq iPt (getpoint "\nSelect Point for Symbol > "))
  40.              (setvar "clayer" "S-GRID-IDEN")
  41.              (command "-insert" "Grdbub01" iPt "" "" "")
  42.              (setq bubTag (entnext (entlast)))
  43.              (while (/= "SEQEND" (cdadr (setq bubTagLst (entget bubTag))))
  44.                (if    (= "GRIDNUM" (cdr (assoc 2 bubTagLst)))
  45.                  (entmod (subst (cons 1 (strcat pTxt (rtos (+ sNum cnt) 2 0) sTxt))
  46.                         (assoc 1 bubTagLst)
  47.                         bubTagLst)))
  48.                (setq bubTag (entnext bubTag)))
  49.              (command "_regenall")
  50.              (setq cnt (1+ cnt))))
  51.               ((= lAns "Yes")
  52.            (while (and (setq 1pt (getpoint "\nSpecify Grid-Line First Point > "))
  53.                    (setq 2pt (getpoint 1pt "\nSpecify Second Grid-Line Point > ")))
  54.              (setvar "clayer" "S-GRID")
  55.              (command "_line" 1pt 2pt "")
  56.              (setq    grLin (entlast)
  57.                lAng  (angle 1pt 2pt)
  58.                iPt   (polar 2pt lAng 0.5))
  59.              (setvar "clayer" "S-GRID-IDEN")
  60.              (command "-insert" "Grdbub01" iPt "" "" "")
  61.              (setq bubTag (entnext (entlast)))
  62.              (while (/= "SEQEND" (cdadr (setq bubTagLst (entget bubTag))))
  63.                (if    (= "GRIDNUM" (cdr (assoc 2 bubTagLst)))
  64.                  (entmod (subst (cons 1 (strcat pTxt (rtos (+ sNum cnt) 2 0) sTxt))
  65.                         (assoc 1 bubTagLst)
  66.                         bubTagLst)))
  67.                (setq bubTag (entnext bubTag)))
  68.              (command "_regenall")
  69.              (setq cnt (1+ cnt))))))
  70.        ((= ans "Door")
  71.         (setq chrLst (vl-string->list sTxt))
  72.         (if chrLst
  73.           (setq sChr (last chrLst))
  74.           (setq sChr 65))
  75.         (while    (and (setq iPt (getpoint "\nSelect Point for Symbol > "))
  76.                 (< (+ sChr cnt) 91))
  77.           (setvar "clayer" "A-DOOR-IDEN")
  78.           (command "-insert" "Tagdoor1" iPt "" "" "")
  79.           (setq drTag (entnext (entlast)))
  80.           (while (/= "SEQEND" (cdadr (setq drTagLst (entget drTag))))
  81.             (if (= "DR1NUM" (cdr (assoc 2 drTagLst)))
  82.               (entmod (subst (cons 1 (strcat pTxt (rtos sNum 2 0) (chr (+ sChr cnt))))
  83.                      (assoc 1 drTagLst)
  84.                      drTagLst)))
  85.             (setq drTag (entnext drTag)))
  86.           (command "_regenall")
  87.           (setq cnt (1+ cnt))))))))
  88.    (princ "\n<!> One or More Blocks not Found <!>"))
  89. (*error* "")
  90. (princ))
  91. (defun makelay    (x y)
  92. (if (not (tblsearch "LAYER" x))
  93.    (command "-layer" "M" x "C" y x "")))
回复

使用道具 举报

1

主题

9

帖子

8

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 12:11:30 | 显示全部楼层
把“起始数字”设为字母/数字有多难?
 
所以在网格泡泡中,我可以有一个AA,BB,CC之类的东西
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:15:35 | 显示全部楼层
那么你想选择使用递增字母和数字吗?
 
你还需要使用前缀和后缀吗?
回复

使用道具 举报

1

主题

9

帖子

8

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 12:17:45 | 显示全部楼层
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:20:58 | 显示全部楼层
I can point it to the block filepath, or leave the filepath blank for you to fill in
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:24:57 | 显示全部楼层
An updated version - silly me forgot to set the cmdecho
 
  1. (defun c:tagger     (/ *error* vLst oVars ans pTxt    sTxt cnt iPt drTag bubTag drTagLst bubTagLst lAns 1pt 2pt lAng chrLst         sChr) (vl-load-com) (defun *error*  (msg)   (if    oVars     (mapcar 'setvar vLst oVars))   (if    (eq "" msg)     (princ "\n>")     (princ (strcat "Error: " (strcase msg))))   (princ)) (setq    vLst  (list "OSMODE" "CLAYER" "ATTREQ" "BLIPMODE" "CMDECHO")   oVars (mapcar 'getvar vLst)) (mapcar 'setvar vLst (list 0 "0" 0 0 0)) (mapcar 'makelay '("A-DOOR-IDEN" "S-GRID-IDEN" "S-GRID") '("5" "4" "2")) (if (and (tblsearch "BLOCK" "Tagdoor1") (tblsearch "BLOCK" "Grdbub01"))   (progn     (if (not TG:oans)   (setq TG:oans "Door"))     (if (not TG:olans)   (setq TG:olans "Yes"))     (initget "Door Bubble")     (setq ans (getkword (strcat "\nSpecify Tag Type [Door/Bubble] : ")))     (if (not ans)   (setq ans TG:oans)   (setq TG:oans ans))     (if (and (setq pTxt (getstring t "\nSpecify Prefix Text :  "))          (not (initget 5))          (setq sNum (getint "\nSpecify Starting Number: ")            sTxt (getstring t "\nSpecify Suffix Text :  ")))   (progn     (setq cnt 0)     (cond    ((= ans "Bubble")        (initget "Yes No")        (setq lAns (getkword (strcat "\nGrid-Line? [Yes/No] : ")))        (if (not lAns)          (setq lAns TG:olans)          (setq TG:olans lAns))        (cond ((= lAns "No")           (while (setq iPt (getpoint "\nSelect Point for Symbol > "))             (setvar "clayer" "S-GRID-IDEN")             (command "-insert" "Grdbub01" iPt "" "" "")             (setq bubTag (entnext (entlast)))             (while (/= "SEQEND" (cdadr (setq bubTagLst (entget bubTag))))               (if    (= "GRIDNUM" (cdr (assoc 2 bubTagLst)))                 (entmod (subst (cons 1 (strcat pTxt (rtos (+ sNum cnt) 2 0) sTxt))                        (assoc 1 bubTagLst)                        bubTagLst)))               (setq bubTag (entnext bubTag)))             (command "_regenall")             (setq cnt (1+ cnt))))              ((= lAns "Yes")           (while (and (setq 1pt (getpoint "\nSpecify Grid-Line First Point > "))                   (setq 2pt (getpoint 1pt "\nSpecify Second Grid-Line Point > ")))             (setvar "clayer" "S-GRID")             (command "_line" 1pt 2pt "")             (setq    grLin (entlast)               lAng  (angle 1pt 2pt)               iPt   (polar 2pt lAng 0.5))             (setvar "clayer" "S-GRID-IDEN")             (command "-insert" "Grdbub01" iPt "" "" "")             (setq bubTag (entnext (entlast)))             (while (/= "SEQEND" (cdadr (setq bubTagLst (entget bubTag))))               (if    (= "GRIDNUM" (cdr (assoc 2 bubTagLst)))                 (entmod (subst (cons 1 (strcat pTxt (rtos (+ sNum cnt) 2 0) sTxt))                        (assoc 1 bubTagLst)                        bubTagLst)))               (setq bubTag (entnext bubTag)))             (command "_regenall")             (setq cnt (1+ cnt))))))       ((= ans "Door")        (setq chrLst (vl-string->list sTxt))        (if chrLst          (setq sChr (last chrLst))          (setq sChr 65))        (while    (and (setq iPt (getpoint "\nSelect Point for Symbol > "))                (< (+ sChr cnt) 91))          (setvar "clayer" "A-DOOR-IDEN")          (command "-insert" "Tagdoor1" iPt "" "" "")          (setq drTag (entnext (entlast)))          (while (/= "SEQEND" (cdadr (setq drTagLst (entget drTag))))            (if (= "DR1NUM" (cdr (assoc 2 drTagLst)))              (entmod (subst (cons 1 (strcat pTxt (rtos sNum 2 0) (chr (+ sChr cnt))))                     (assoc 1 drTagLst)                     drTagLst)))            (setq drTag (entnext drTag)))          (command "_regenall")          (setq cnt (1+ cnt))))))))   (princ "\n One or More Blocks not Found ")) (*error* "") (princ))(defun makelay    (x y) (if (not (tblsearch "LAYER" x))   (command "-layer" "M" x "C" y x "")))
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:26:20 | 显示全部楼层
If it is indeed a filepath you would like the blocks referenced to, make sure you fill in the highlighted Parts to the correct Filepaths for each block (right down to the file level), using double backslashes.
 
i.e.
 
C:\\Users\\LeeMac\\Documents\\Block1.dwg
 
  1. (defun c:tagger     (/ *error* vLst oVars DoorBlock BubbleBlock ans pTxt sTxt cnt iPt            drTag bubTag drTagLst bubTagLst lAns 1pt 2pt lAng chrLst sChr) (vl-load-com) (defun *error*  (msg)   (if    oVars     (mapcar 'setvar vLst oVars))   (if    (eq "" msg)     (princ "\n>")     (princ (strcat "Error: " (strcase msg))))   (princ)) (setq    vLst  (list "OSMODE" "CLAYER" "ATTREQ" "BLIPMODE" "CMDECHO")   oVars (mapcar 'getvar vLst)) (mapcar 'setvar vLst (list 0 "0" 0 0 0)) (mapcar 'makelay '("A-DOOR-IDEN" "S-GRID-IDEN" "S-GRID") '("5" "4" "2")) (setq    DoorBlock   "[b][color=Red]C:\\...[/color][/b]"          BubbleBlock "[color=Red][b]C:\\...[/b][/color]") (if (and DoorBlock BubbleBlock)   (progn     (if (not TG:oans)   (setq TG:oans "Door"))     (if (not TG:olans)   (setq TG:olans "Yes"))     (initget "Door Bubble")     (setq ans (getkword (strcat "\nSpecify Tag Type [Door/Bubble] : ")))     (if (not ans)   (setq ans TG:oans)   (setq TG:oans ans))     (if (and (setq pTxt (getstring t "\nSpecify Prefix Text :  "))          (not (initget 5))          (setq sNum (getint "\nSpecify Starting Number: ")            sTxt (getstring t "\nSpecify Suffix Text :  ")))   (progn     (setq cnt 0)     (cond    ((= ans "Bubble")        (initget "Yes No")        (setq lAns (getkword (strcat "\nGrid-Line? [Yes/No] : ")))        (if (not lAns)          (setq lAns TG:olans)          (setq TG:olans lAns))        (cond ((= lAns "No")           (while (setq iPt (getpoint "\nSelect Point for Symbol > "))             (setvar "clayer" "S-GRID-IDEN")             (command "-insert" BubbleBlock iPt "" "" "")             (setq bubTag (entnext (entlast)))             (while (/= "SEQEND" (cdadr (setq bubTagLst (entget bubTag))))               (if    (= "GRIDNUM" (cdr (assoc 2 bubTagLst)))                 (entmod (subst (cons 1 (strcat pTxt (rtos (+ sNum cnt) 2 0) sTxt))                        (assoc 1 bubTagLst)                        bubTagLst)))               (setq bubTag (entnext bubTag)))             (command "_regenall")             (setq cnt (1+ cnt))))              ((= lAns "Yes")           (while (and (setq 1pt (getpoint "\nSpecify Grid-Line First Point > "))                   (setq 2pt (getpoint 1pt "\nSpecify Second Grid-Line Point > ")))             (setvar "clayer" "S-GRID")             (command "_line" 1pt 2pt "")             (setq    grLin (entlast)               lAng  (angle 1pt 2pt)               iPt   (polar 2pt lAng 0.5))             (setvar "clayer" "S-GRID-IDEN")             (command "-insert" BubbleBlock iPt "" "" "")             (setq bubTag (entnext (entlast)))             (while (/= "SEQEND" (cdadr (setq bubTagLst (entget bubTag))))               (if    (= "GRIDNUM" (cdr (assoc 2 bubTagLst)))                 (entmod (subst (cons 1 (strcat pTxt (rtos (+ sNum cnt) 2 0) sTxt))                        (assoc 1 bubTagLst)                        bubTagLst)))               (setq bubTag (entnext bubTag)))             (command "_regenall")             (setq cnt (1+ cnt))))))       ((= ans "Door")        (setq chrLst (vl-string->list sTxt))        (if chrLst          (setq sChr (last chrLst))          (setq sChr 65))        (while    (and (setq iPt (getpoint "\nSelect Point for Symbol > "))                (< (+ sChr cnt) 91))          (setvar "clayer" "A-DOOR-IDEN")          (command "-insert" DoorBlock iPt "" "" "")          (setq drTag (entnext (entlast)))          (while (/= "SEQEND" (cdadr (setq drTagLst (entget drTag))))            (if (= "DR1NUM" (cdr (assoc 2 drTagLst)))              (entmod (subst (cons 1 (strcat pTxt (rtos sNum 2 0) (chr (+ sChr cnt))))                     (assoc 1 drTagLst)                     drTagLst)))            (setq drTag (entnext drTag)))          (command "_regenall")          (setq cnt (1+ cnt))))))))   (princ "\n One or More Blocks not Found ")) (*error* "") (princ))(defun makelay    (x y) (if (not (tblsearch "LAYER" x))   (command "-layer" "M" x "C" y x "")))
回复

使用道具 举报

1

主题

9

帖子

8

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 12:28:55 | 显示全部楼层
How hard is it to take the "starting number" and let it be alpha/numeric?
 
So that inside the grid bubbles I can have an AA, BB, CC kinda thing
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:31:50 | 显示全部楼层
So you would like the option of using incremental letters as well as numbers?
 
Would you still require the use of Prefixes and Suffixes?
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 02:11 , Processed in 0.425267 second(s), 70 queries .

© 2020-2025 乐筑天下

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