乐筑天下

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

[编程交流] 附着点

[复制链接]

2

主题

15

帖子

13

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 16:14:00 | 显示全部楼层 |阅读模式
我一直在摆弄李的中长代码,试图学习一些新东西。我已经能够将多行文字沿着柱脚移动到不同的点,并改变对齐方式。我遇到的问题是将多行文字插入点与柱脚上的附件点偏移。有什么简单的改变吗?感谢您的帮助!
 
  1. ;;----------------------=={ Length at Midpoint }==----------------------;;
  2. ;;                                                                      ;;
  3. ;;  This program prompts the user for a selection of objects to be      ;;
  4. ;;  labelled and proceeds to generate an MText object located at        ;;
  5. ;;  the midpoint of each object displaying a Field Expression           ;;
  6. ;;  referencing the length of the object.                               ;;
  7. ;;                                                                      ;;
  8. ;;  The program is compatible for use with Arcs, Circles, Lines,        ;;
  9. ;;  LWPolylines, 2D & 3D Polylines, and under all UCS & View settings.  ;;
  10. ;;                                                                      ;;
  11. ;;  The program will generate MText objects positioned directly over    ;;
  12. ;;  the midpoint of each object, and aligned with the object whilst     ;;
  13. ;;  preserving text readability. The MText will have a background mask  ;;
  14. ;;  enabled and will use the active Text Style and Text Height settings ;;
  15. ;;  at the time of running the program.                                 ;;
  16. ;;----------------------------------------------------------------------;;
  17. ;;  Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com              ;;
  18. ;;----------------------------------------------------------------------;;
  19. ;;  Version 1.0    -    2013-11-12                                      ;;
  20. ;;                                                                      ;;
  21. ;;  - First release.                                                    ;;
  22. ;;----------------------------------------------------------------------;;
  23. ;;  Version 1.1    -    2016-01-16                                      ;;
  24. ;;                                                                      ;;
  25. ;;  - Modified LM:objectid function to account for 64-bit AutoCAD 2008. ;;
  26. ;;----------------------------------------------------------------------;;
  27. _$
  28. (defun c:Test ( / *error* ent fmt idx ins ocs par sel spc txt typ uxa )
  29.    (setq fmt "%lu6") ;; Field Formatting
  30.    (defun *error* ( msg )
  31.        (LM:endundo (LM:acdoc))
  32.        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  33.            (princ (strcat "\nError: " msg))
  34.        )
  35.        (princ)
  36.    )
  37.    
  38.    (if
  39.        (setq sel
  40.            (ssget
  41.                (list
  42.                   '(0 . "ARC,CIRCLE,LINE,*POLYLINE")
  43.                   '(-4 . "<NOT")
  44.                       '(-4 . "<AND")
  45.                           '(0 . "POLYLINE")
  46.                           '(-4 . "&")
  47.                           '(70 . 80)
  48.                       '(-4 . "AND>")
  49.                   '(-4 . "NOT>")
  50.                    (if (= 1 (getvar 'cvport))
  51.                        (cons 410 (getvar 'ctab))
  52.                       '(410 . "Model")
  53.                    )
  54.                )
  55.            )
  56.        )
  57.        (progn
  58.            (setq spc
  59.                (vlax-get-property (LM:acdoc)
  60.                    (if (= 1 (getvar 'cvport))
  61.                        'paperspace
  62.                        'modelspace
  63.                    )
  64.                )
  65.            )
  66.            (setq ocs (trans '(0.0 0.0 0.1) 0 1 t)
  67.                  uxa (angle '(0.0 0.0) (trans (getvar 'ucsxdir) 0 ocs t))
  68.            )
  69.            (LM:startundo (LM:acdoc))
  70.            (repeat (setq idx (sslength sel))
  71.                (setq ent (ssname sel (setq idx (1- idx)))
  72.                      par (vlax-curve-getparamatdist ent (/ (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)) 2.0))
  73.                      ins (vlax-curve-getpointatparam ent par)
  74.                      typ (cdr (assoc 0 (entget ent)))
  75.                )
  76.                (setq txt
  77.                    (vlax-invoke spc 'addmtext ins 0.0
  78.                        (strcat
  79.                            "%<\\AcObjProp Object(%<\\_ObjId " (LM:objectid (vlax-ename->vla-object ent)) ">%)."
  80.                            (cond
  81.                                (   (= "CIRCLE" typ) "Circumference")
  82.                                (   (= "ARC"    typ) "ArcLength")
  83.                                (   "Length"   )
  84.                            )
  85.                            " \\f "" fmt "">%"
  86.                        )
  87.                    )
  88.                )
  89.                (vla-put-backgroundfill  txt :vlax-false)
  90.                (vla-put-attachmentpoint txt acattachmentpointmiddlecenter)
  91.                (vla-put-insertionpoint  txt (vlax-3D-point ins))
  92.                (vla-put-rotation txt (LM:readable (- (angle '(0.0 0.0 0.0) (trans (vlax-curve-getfirstderiv ent par) 0 ocs t)) uxa)))
  93.            )
  94.            (LM:endundo (LM:acdoc))
  95.        )
  96.    )
  97.    (princ)
  98. )
  99. ;; Readable  -  Lee Mac
  100. ;; Returns an angle corrected for text readability.
  101. (defun LM:readable ( a )
  102.    (   (lambda ( a )
  103.            (if (and (< (* pi 0.5) a) (<= a (* pi 1.5)))
  104.                (LM:readable (+ a pi))
  105.                a
  106.            )
  107.        )
  108.        (rem (+ a pi pi) (+ pi pi))
  109.    )
  110. )
  111. ;; ObjectID  -  Lee Mac
  112. ;; Returns a string containing the ObjectID of a supplied VLA-Object
  113. ;; Compatible with 32-bit & 64-bit systems
  114. (defun LM:objectid ( obj )
  115.    (eval
  116.        (list 'defun 'LM:objectid '( obj )
  117.            (if (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*")
  118.                (if (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
  119.                    (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
  120.                   '(LM:ename->objectid (vlax-vla-object->ename obj))
  121.                )
  122.               '(itoa (vla-get-objectid obj))
  123.            )
  124.        )
  125.    )
  126.    (LM:objectid obj)
  127. )
  128. ;; Entity Name to ObjectID  -  Lee Mac
  129. ;; Returns the 32-bit or 64-bit ObjectID for a supplied entity name
  130. (defun LM:ename->objectid ( ent )
  131.    (LM:hex->decstr
  132.        (setq ent (vl-string-right-trim ">" (vl-prin1-to-string ent))
  133.              ent (substr ent (+ (vl-string-position 58 ent) 3))
  134.        )
  135.    )
  136. )
  137. ;; Hex to Decimal String  -  Lee Mac
  138. ;; Returns the decimal representation of a supplied hexadecimal string
  139. (defun LM:hex->decstr ( hex / foo bar )
  140.    (defun foo ( lst rtn )
  141.        (if lst
  142.            (foo (cdr lst) (bar (- (car lst) (if (< 57 (car lst)) 55 48)) rtn))
  143.            (apply 'strcat (mapcar 'itoa (reverse rtn)))
  144.        )
  145.    )
  146.    (defun bar ( int lst )
  147.        (if lst
  148.            (if (or (< 0 (setq int (+ (* 16 (car lst)) int))) (cdr lst))
  149.                (cons (rem int 10) (bar (/ int 10) (cdr lst)))
  150.            )
  151.            (bar int '(0))
  152.        )
  153.    )
  154.    (foo (vl-string->list (strcase hex)) nil)
  155. )
  156. ;; Start Undo  -  Lee Mac
  157. ;; Opens an Undo Group.
  158. (defun LM:startundo ( doc )
  159.    (LM:endundo doc)
  160.    (vla-startundomark doc)
  161. )
  162. ;; End Undo  -  Lee Mac
  163. ;; Closes an Undo Group.
  164. (defun LM:endundo ( doc )
  165.    (while (= 8 (logand 8 (getvar 'undoctl)))
  166.        (vla-endundomark doc)
  167.    )
  168. )
  169. ;; Active Document  -  Lee Mac
  170. ;; Returns the VLA Active Document Object
  171. (defun LM:acdoc nil
  172.    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
  173.    (LM:acdoc)
  174. )
  175. (vl-load-com)
  176. (princ
  177.    (strcat
  178.        "\n:: MidLen.lsp | Version 1.1 | \\U+00A9 Lee Mac "
  179.        (menucmd "m=$(edtime,0,yyyy)")
  180.        " www.lee-mac.com ::"
  181.        "\n:: Type "midlen" to Invoke ::"
  182.    )
  183. )
  184. (princ)
  185. ;;----------------------------------------------------------------------;;
  186. ;;                             End of File                              ;;
  187. ;;----------------------------------------------------------------------;;
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 16:46:22 | 显示全部楼层
利用vlax曲线getFirstDeriv和极性函数,
还要检查他的“将文本对齐到曲线”程序。
回复

使用道具 举报

2

主题

15

帖子

13

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 17:29:31 | 显示全部楼层
好的,谢谢。我会调查的。谢谢你的帮助
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 16:38 , Processed in 0.432128 second(s), 69 queries .

© 2020-2025 乐筑天下

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