乐筑天下

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

[编程交流] 块字段Lisp例程

[复制链接]

2

主题

2

帖子

0

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 16:14:25 | 显示全部楼层 |阅读模式
嘿伙计们,
 
我想知道是否有人可以帮我解决Lisp程序的问题。我对编写LISP基本上是新手。我使用许多字段命令将细节剪切引用到相应的细节标题栏。这样,如果我重新编号实际的细节或移动图纸,则快速重新生成,并相应地更新平面细节切割。剪辑和标题都是动态块。我确实有一些类似的开始代码,由LeeMac编写,但只复制field command属性,并将其应用于另一个属性,文本或任何内容。它无法复制实际的“text”属性并将其转换为field命令。随附的图片显示了我在说什么。我想为细节的引用6创建一个字段“文本链接”LISP例程。这样我就不必手动将它们全部链接起来。如果你们能帮我的话,这会节省我很多时间。下面的脚本。
 
 
  1. ;;--------------------------=={ Copy Field }==--------------------------;;
  2. ;;                                                                      ;;
  3. ;;  This program enables the user to copy a field expression from a     ;;
  4. ;;  selected source object to multiple destination objects in a         ;;
  5. ;;  drawing.                                                            ;;
  6. ;;                                                                      ;;
  7. ;;  Upon issuing the command syntax 'copyfield' at the AutoCAD          ;;
  8. ;;  command-line, the user is prompted to select an annotation object   ;;
  9. ;;  (Text, MText, Attribute, Multileader, Dimension) containing a       ;;
  10. ;;  field expression to be copied.                                      ;;
  11. ;;                                                                      ;;
  12. ;;  Following a valid response, the user may then copy the field to     ;;
  13. ;;  multiple selected destination objects in the drawing.               ;;
  14. ;;----------------------------------------------------------------------;;
  15. ;;  Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com              ;;
  16. ;;----------------------------------------------------------------------;;
  17. ;;  Version 1.0    -    2013-07-14                                      ;;
  18. ;;                                                                      ;;
  19. ;;  - First release.                                                    ;;
  20. ;;----------------------------------------------------------------------;;
  21. ;;  Version 1.1    -    2017-06-13                                      ;;
  22. ;;                                                                      ;;
  23. ;;  - Updated LM:fieldcode function to account for field expressions    ;;
  24. ;;    greater than 250 characters in length.                            ;;
  25. ;;----------------------------------------------------------------------;;
  26. (defun c:copyfield ( / *error* select src )
  27.    (defun *error* ( msg )
  28.        (LM:endundo (LM:acdoc))
  29.        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  30.            (princ (strcat "\nError: " msg))
  31.        )
  32.        (princ)
  33.    )
  34.    (defun select ( msg fun / ent rtn )
  35.        (while
  36.            (progn (setvar 'errno 0) (setq ent (nentsel msg))
  37.                (cond
  38.                    (   (= 7 (getvar 'errno))
  39.                        (princ "\nMissed, try again.")
  40.                    )
  41.                    (   (= 'list (type ent))
  42.                        (cond
  43.                            (   (progn
  44.                                    (if (= 4 (length ent))
  45.                                        (setq ent (last (last ent)))
  46.                                        (setq ent (car ent))
  47.                                    )
  48.                                    (not (wcmatch (cdr (assoc 0 (entget ent))) "TEXT,MTEXT,ATTRIB,MULTILEADER,*DIMENSION"))
  49.                                )
  50.                                (princ "\nInvalid object selected.")
  51.                            )
  52.                            (   (not (setq rtn ((eval fun) ent))))
  53.                        )
  54.                    )
  55.                )
  56.            )
  57.        )
  58.        rtn
  59.    )
  60.    (if
  61.        (setq src
  62.            (select "\nSelect source field: "
  63.                (function
  64.                    (lambda ( ent )
  65.                        (cond ((LM:fieldcode ent)) ((not (princ "\nSelected object does not contain a field."))))
  66.                    )
  67.                )
  68.            )
  69.        )
  70.        (progn
  71.            (LM:startundo (LM:acdoc))
  72.            (select "\nSelect destination object <Exit>: "
  73.                (function
  74.                    (lambda ( ent / obj )
  75.                        (cond
  76.                            (   (null (vlax-write-enabled-p (setq obj (vlax-ename->vla-object ent))))
  77.                                (princ "\nSelected object is on a locked layer.")
  78.                            )
  79.                            (   (vlax-property-available-p obj 'textoverride t)
  80.                                (vla-put-textoverride obj src)
  81.                                (command "_.updatefield" ent "")
  82.                            )
  83.                            (   (vlax-property-available-p obj 'textstring t)
  84.                                (vla-put-textstring obj src)
  85.                                (command "_.updatefield" ent "")
  86.                            )
  87.                        )
  88.                        nil
  89.                    )
  90.                )
  91.            )
  92.            (LM:endundo (LM:acdoc))
  93.        )
  94.    )
  95.    (princ)
  96. )
  97. ;; Field Code  -  Lee Mac
  98. ;; Returns the field expression associated with an entity
  99. (defun LM:fieldcode ( ent / replacefield replaceobject fieldstring enx )
  100.    (defun replacefield ( str enx / ent fld pos )
  101.        (if (setq pos (vl-string-search "\\_FldIdx" (setq str (replaceobject str enx))))
  102.            (progn
  103.                (setq ent (assoc 360 enx)
  104.                      fld (entget (cdr ent))
  105.                )
  106.                (strcat
  107.                    (substr str 1 pos)
  108.                    (replacefield (fieldstring fld) fld)
  109.                    (replacefield (substr str (1+ (vl-string-search ">%" str pos))) (cdr (member ent enx)))
  110.                )
  111.            )
  112.            str
  113.        )
  114.    )
  115.    (defun replaceobject ( str enx / ent pos )
  116.        (if (setq pos (vl-string-search "ObjIdx" str))
  117.            (strcat
  118.                (substr str 1 (+ pos 5)) " "
  119.                (LM:ObjectID (vlax-ename->vla-object (cdr (setq ent (assoc 331 enx)))))
  120.                (replaceobject (substr str (1+ (vl-string-search ">%" str pos))) (cdr (member ent enx)))
  121.            )
  122.            str
  123.        )
  124.    )
  125.    (defun fieldstring ( enx / itm )
  126.        (if (setq itm (assoc 3 enx))
  127.            (strcat (cdr itm) (fieldstring (cdr (member itm enx))))
  128.            (cond ((cdr (assoc 2 enx))) (""))
  129.        )
  130.    )
  131.    
  132.    (if (and (wcmatch  (cdr (assoc 0 (setq enx (entget ent)))) "TEXT,MTEXT,ATTRIB,MULTILEADER,*DIMENSION")
  133.             (setq enx (cdr (assoc 360 enx)))
  134.             (setq enx (dictsearch enx "ACAD_FIELD"))
  135.             (setq enx (dictsearch (cdr (assoc -1 enx)) "TEXT"))
  136.        )
  137.        (replacefield (fieldstring enx) enx)
  138.    )
  139. )
  140. ;; ObjectID  -  Lee Mac
  141. ;; Returns a string containing the ObjectID of a supplied VLA-Object
  142. ;; Compatible with 32-bit & 64-bit systems
  143. (defun LM:ObjectID ( obj )
  144.    (eval
  145.        (list 'defun 'LM:ObjectID '( obj )
  146.            (if
  147.                (and
  148.                    (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
  149.                    (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
  150.                )
  151.                (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
  152.               '(itoa (vla-get-objectid obj))
  153.            )
  154.        )
  155.    )
  156.    (LM:ObjectID obj)
  157. )
  158. ;; Start Undo  -  Lee Mac
  159. ;; Opens an Undo Group.
  160. (defun LM:startundo ( doc )
  161.    (LM:endundo doc)
  162.    (vla-startundomark doc)
  163. )
  164. ;; End Undo  -  Lee Mac
  165. ;; Closes an Undo Group.
  166. (defun LM:endundo ( doc )
  167.    (while (= 8 (logand 8 (getvar 'undoctl)))
  168.        (vla-endundomark doc)
  169.    )
  170. )
  171. ;; Active Document  -  Lee Mac
  172. ;; Returns the VLA Active Document Object
  173. (defun LM:acdoc nil
  174.    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
  175.    (LM:acdoc)
  176. )
  177. ;;----------------------------------------------------------------------;;
  178. (vl-load-com)
  179. (princ
  180.    (strcat
  181.        "\n:: CopyField.lsp | Version 1.1 | \\U+00A9 Lee Mac "
  182.        (menucmd "m=$(edtime,0,yyyy)")
  183.        " www.lee-mac.com ::"
  184.        "\n:: Type "copyfield" to Invoke ::"
  185.    )
  186. )
  187. (princ)
  188. ;;----------------------------------------------------------------------;;
  189. ;;                             End of File                              ;;
  190. ;;----------------------------------------------------------------------;;

171427eg5tm5gmmph89h9w.jpg
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 17:01 , Processed in 0.465215 second(s), 57 queries .

© 2020-2025 乐筑天下

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