乐筑天下

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

[编程交流] 放置偏移为的结果

[复制链接]

4

主题

16

帖子

12

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 20:14:59 | 显示全部楼层 |阅读模式
当前,我在标记管道管路时根据结果进行剪切和粘贴。我编译了一个简单的程序从零碎和多个网站的参考资料。
我现在需要帮助将lisp中的文本结果放置在选定行中点上方的偏移位置。
感谢您的帮助
 
  1. ;; label_run.lsp
  2. ;; lisp commands used referenced at: cadtutor.com, jefferypsanders.com, afralisp.net, ronleigh.com, lee-mac.com
  3. ;; Credits - Noted Assistance: hanhphuc, ymg      
  4. ;; Objective:
  5. ;; User To Pick By Line Or Two Points From Screen To Retrieve Distance(d) With Length Rounded Off And Compute Slope Percentage Of Selection
  6. ;; To Be Used For:
  7. ;;                 1) As An Inquiry - For Display Only
  8. ;;                 2) With Option To Paste Results Above Selected Line As Label
  9. ;; Wish List Add Ons
  10. ;;                   1) Possible Pipe Size And Material Add To String
  11. ;;                 2) Use Leader If Text Exceeds line
  12. ;;
  13. ;;**************************************************************************************;;
  14. (defun C:label_run ( / *error* a1 a2 el e2 x1 y1 z1 x2 y2 z2 d tx pt txsize rot kw); Defined Functions Used -
  15. (setq oldlayer (getvar "clayer"))
  16. (setq oldsnap (getvar "osmode"))
  17. ;; User Option: Select Two Points Or Line - To Retrieve Distance Between And (z) Elevation At Each Selected Point
  18. (initget 0 "Line")
  19. (setq a1 (getpoint "\nPoint or [Line] "))
  20. (if (= a1 nil); If nil then select line
  21. (setq a1 "Line")
  22. )
  23. ;; If line option selected then:
  24. (if (= a1 "Line")
  25. ; true
  26. (progn
  27. (setq el (ut-get-object "LINE" "\nSelect Line:"))
  28. (setq a1 (cdr (assoc 10 el)))
  29. (setq a2 (cdr (assoc 11 el)))
  30. )
  31. ;; If point - pick point
  32. (progn
  33. (setq a2 (getpoint a1 "\nSelect second point: "))
  34. )
  35. )
  36. (if (= a2 nil) (exit)); line option selected
  37. ;get z value of points
  38. (setq x1 (car a1)
  39. y1 (cadr a1)
  40. z1 (caddr a1)
  41. x2 (car a2)
  42. y2 (cadr a2)
  43. z2 (caddr a2)
  44. )
  45. ;; Determine slope percentage -
  46. (if (> (abs (- z1 z2)) 0.1)
  47. (setq s1 "%"
  48. a1 (subst 0.0 z1 a1)
  49. a2 (subst 0.0 z2 a2)
  50. d  (distance a1 a2); Get Distance / Length Of Line
  51. slp (/ (- z2 z1) d); Formula For Slope: Z Value Point(1) Minus Z Value Point(2) (can Be Opposite 2-1) Divided By Length Of Line
  52. )
  53. (setq s1 "%"; Determine Percent
  54. d (distance a1 a2)
  55. slp (/ (- y2 y1) d)
  56. )
  57. )
  58. (setq slp (* slp 1.000))
  59. ;; Make Angle Readable      ;credit to ymg      
  60. (defun MakeReadable (a)
  61.    (setq a (rem (+ a pi pi) (+ pi pi)))
  62.    (rem (if (< (* pi 0.5) a (* pi 1.5))
  63.    (+ a pi)
  64.    a
  65.    ) ;_ end of if
  66. (+ pi pi)
  67. ) ;_ end of rem
  68.    ) ;_ end of defun
  69. ;; Results Displayed On Screen
  70. (terpri)
  71. (princ (setq tx ( strcat (rtos d 2 0)" LF @ "  (rtos slp 2 2) s1 " Slope")))
  72. ;; Option To Paste Results In Drawing offset Midpoint Above Line From Display
  73. (initget "Yes No")
  74. (setq kw (getkword "\nPlace Above Line? [Yes/No] :"))
  75. (if (= kw "Yes")
  76. (progn (setq txsize (getvar 'textsize) pt (polar (apply 'mapcar (cons ''((a b) (* 0.5 (+ a b))) (list a1 a2)))
  77.                  (+ rot (/ pi 2.))
  78.                  (* txsize 3.0)
  79.                  ) ;_ end of polar
  80.        ) ;_  end of setq
  81. (entmake (list        '(0 . "TEXT")
  82.                 '(72 . 1) ; justify
  83.                 (cons 1 tx)
  84.                 (cons 10 pt)
  85.                 (cons 11 pt) ; justify
  86.                 (cons 40 txsize)
  87.                 (cons 50 (MakeReadable (apply 'angle lst)))
  88.                 ) ; list
  89.           ) ;entmake
  90. ) ;_ end of progn
  91. ) ;_ end of if
  92. ;;;; NOTED ERROR AT THIS POINT
  93. ;;;; ; error: bad argument type: numberp: nil
  94. ;; ERROR RESEARCH: A function requiring an integer argument has been passed an argument of incorrect data type with the value noted in the error message.
  95. (princ)
  96. )
  97. (princ)
  98. ;; To Reset Original Varibles - End
  99. (setq olderr *error*)
  100. (setvar "osmode" 11)
  101. (princ)
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 20:30:13 | 显示全部楼层
 
嗨runner214试试这个旧线程
这有帮助吗?
 
建议:
  1. ;; label_run.lsp
  2. ;; lisp commands used referenced at: cadtutor.com, jefferypsanders.com, afralisp.net, ronleigh.com, lee-mac.com
  3. ;; Credits - Noted Assistance: hanhphuc, ymg      
  4. ;; Objective:
  5. ;; User To Pick By Line Or Two Points From Screen To Retrieve Distance(d) With Length Rounded Off And Compute Slope Percentage Of Selection
  6. ;; To Be Used For:
  7. ;;                 1) As An Inquiry - For Display Only
  8. ;;                 2) With Option To Paste Results Above Selected Line As Label
  9. ;; Wish List Add Ons
  10. ;;                   1) Possible Pipe Size And Material Add To String
  11. ;;                 2) Use Leader If Text Exceeds line
  12. ;;
  13. ;;**************************************************************************************;;
  14. ;; Make Angle Readable      ;credit to ymg      
  15. (defun MakeReadable (a)
  16.    (setq a (rem (+ a pi pi) (+ pi pi)))
  17.    (rem (if (< (* pi 0.5) a (* pi 1.5))
  18.    (+ a pi)
  19.    a
  20.    ) ;_ end of if
  21. (+ pi pi)
  22. ) ;_ end of rem
  23.    ) ;_ end of defun   
  24. (defun C:label_run ( / *error* a1 a2 el e2 x1 y1 z1 x2 y2 z2 d tx pt txsize rot kw [color="red"]lst[/color] ); Defined Functions Used -
  25. (setq oldlayer (getvar "clayer"))
  26. (setq oldsnap (getvar "osmode"))
  27. ;; User Option: Select Two Points Or Line - To Retrieve Distance Between And (z) Elevation At Each Selected Point
  28. (initget 0 "Line")
  29. (setq a1 (getpoint "\nPoint or [Line] "))
  30. (if (= a1 nil); If nil then select line
  31. (setq a1 "Line")
  32. )
  33. ;; If line option selected then:
  34. (if (= a1 "Line")
  35. ; true
  36. (progn
  37. (setq el (ut-get-object "LINE" "\nSelect Line:"))
  38. (setq a1 (cdr (assoc 10 el)))
  39. (setq a2 (cdr (assoc 11 el)))
  40. )
  41. ;; If point - pick point
  42. (progn
  43. (setq a2 (getpoint a1 "\nSelect second point: "))
  44. )
  45. )
  46. (if (= a2 nil) (exit)); line option selected
  47. ;get z value of points
  48. (setq x1 (car a1)
  49. y1 (cadr a1)
  50. z1 (caddr a1)
  51. x2 (car a2)
  52. y2 (cadr a2)
  53. z2 (caddr a2)
  54. )
  55. ;; Determine slope percentage -
  56. (if (> (abs (- z1 z2)) 0.1)
  57. (setq s1 "%"
  58. a1 (subst 0.0 z1 a1)
  59. a2 (subst 0.0 z2 a2)
  60. d  (distance a1 a2); Get Distance / Length Of Line
  61. slp (/ (- z2 z1) d); Formula For Slope: Z Value Point(1) Minus Z Value Point(2) (can Be Opposite 2-1) Divided By Length Of Line
  62. )
  63. (setq s1 "%"; Determine Percent
  64. d (distance a1 a2)
  65. slp (/ (- y2 y1) d)
  66. )
  67. )
  68. (setq slp (* slp 1.000))
  69. ;; Results Displayed On Screen
  70. (terpri)
  71. (princ (setq tx ( strcat (rtos d 2 0)" LF @ "  (rtos slp 2 2) s1 " Slope")))
  72. ;; Option To Paste Results In Drawing offset Midpoint Above Line From Display
  73. (initget "Yes No")
  74. (setq kw (getkword "\nPlace Above Line? [Yes/No] :"))
  75. (if (= kw "Yes")
  76. (progn (setq txsize (getvar 'textsize)
  77.        [color="red"]lst (list a1 a2)
  78.        rot (MakeReadable (apply 'angle lst))[/color]
  79.        pt  (polar (apply 'mapcar (cons ''((a b) (* 0.5 (+ a b)))[color="red"] lst[/color]))
  80.                  (+ rot (/ pi 2.))
  81.                  (* txsize 3.0)
  82.                  ) ;_ end of polar
  83.        ) ;_  end of setq
  84. (entmake (list        '(0 . "TEXT")
  85.                 '(72 . 1) ; justify
  86.                 (cons 1 tx)
  87.                 (cons 10 pt)
  88.                 (cons 11 pt) ; justify
  89.                 (cons 40 txsize)
  90.                 (cons 50 [color="red"]rot[/color])
  91.                 ) ; list
  92.           ) ;entmake
  93. ) ;_ end of progn
  94. ) ;_ end of if
  95. (princ)
  96. )
  97. (princ)
  98. ;; To Reset Original Varibles - End
  99. (setq olderr *error*)
  100. (setvar "osmode" 11)
  101. (princ)

HTH公司
回复

使用道具 举报

4

主题

16

帖子

12

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 20:40:16 | 显示全部楼层
谢谢hanhphuc,明天早上会查出来的
 
我对lisp结果的结果感到满意。-ie:27 LF@。02%斜率-。我只是不确定如何获取结果并将其放置在偏离所选线中点的位置。
我试图使用lisp作为查询(显示)的工具,如果我想标记文本结果,还可以使用Y或N选项将其放置在行上。。
回复

使用道具 举报

4

主题

16

帖子

12

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 20:54:50 | 显示全部楼层
hanhphuc公司
 
插入您建议的更改。YES响应出错,并收到错误。NO选项关闭时没有任何错误。
 
然后,我根据Lee Mac的教程运行了Visual Lips editor程序,结果如下:
 
日志监视
...............
*最后一个值*=
(+ROT(/PI 2.0))=
(SETQ DEC 2)=2
12 = 12
...............
 
更新代码:
  1. ;; label_run.lsp
  2. ;; lisp commands used referenced at: cadtutor.com, jefferypsanders.com, afralisp.net, ronleigh.com, lee-mac.com
  3. ;; Credits - Noted Assistance: hanhphuc, ymg
  4. ;; Debugging
  5. ;; Current - 020815
  6. ;; Objective:
  7. ;; User To Pick By Line Or Two Points From Screen To Retrieve Distance(d) With Length Rounded Off And Compute Slope Percentage Of Selection
  8. ;; To Be Used For:
  9. ;;                 1) As An Inquiry - For Display Only
  10. ;;                 2) With Option To Paste Results Above Selected Line As Label
  11. ;; Wish List Add Ons
  12. ;;                   1) Possible Pipe Size And Material Add To String
  13. ;;                 2) Use Leader If Text Exceeds line
  14. ;;
  15. ;;**************************************************************************************;;
  16. (defun C:label_run ( / *error* a1 a2 el e2 x1 y1 z1 x2 y2 z2 d tx pt txsize rot kw); Defined Functions Used -
  17. (setq oldlayer (getvar "clayer"))
  18. (setq oldsnap (getvar "osmode"))
  19. ;; User Option: Select Two Points Or Line - To Retrieve Distance Between And (z) Elevation At Each Selected Point
  20. (initget 0 "Line")
  21. (setq a1 (getpoint "\nPoint or [Line] "))
  22. (if (= a1 nil); If nil then select line
  23. (setq a1 "Line")
  24. )
  25. ;; If line option selected then:
  26. (if (= a1 "Line")
  27. ; true
  28. (progn
  29. (setq el (ut-get-object "LINE" "\nSelect Line:"))
  30. (setq a1 (cdr (assoc 10 el)))
  31. (setq a2 (cdr (assoc 11 el)))
  32. )
  33. ;; If point - pick point
  34. (progn
  35. (setq a2 (getpoint a1 "\nSelect second point: "))
  36. )
  37. )
  38. (if (= a2 nil) (exit)); line option selected
  39. ;get z value of points
  40. (setq x1 (car a1)
  41. y1 (cadr a1)
  42. z1 (caddr a1)
  43. x2 (car a2)
  44. y2 (cadr a2)
  45. z2 (caddr a2)
  46. )
  47. ;; Determine slope percentage -
  48. (if (> (abs (- z1 z2)) 0.1)
  49. (setq s1 "%"
  50. a1 (subst 0.0 z1 a1)
  51. a2 (subst 0.0 z2 a2)
  52. d  (distance a1 a2); Get Distance / Length Of Line
  53. slp (/ (- z2 z1) d); Formula For Slope: Z Value Point(1) Minus Z Value Point(2) (can Be Opposite 2-1) Divided By Length Of Line
  54. )
  55. (setq s1 "%"; Determine Percent
  56. d (distance a1 a2)
  57. slp (/ (- y2 y1) d)
  58. )
  59. )
  60. (setq slp (* slp 1.000))
  61. ;; Make Angle Readable      ;credit to ymg
  62. (defun MakeReadable (a)
  63.    (setq a (rem (+ a pi pi) (+ pi pi)))
  64.    (rem (if (< (* pi 0.5) a (* pi 1.5))
  65.    (+ a pi)
  66.    a
  67.    ) ;_ end of if
  68. (+ pi pi)
  69. ) ;_ end of rem
  70.    ) ;_ end of defun
  71. ;; Results Displayed On Screen
  72. (terpri)
  73. (princ (setq tx ( strcat (rtos d 2 0)" LF @ "  (rtos slp 2 2) s1 " Slope")))
  74. ;; Option To Paste Results In Drawing offset Midpoint Above Line From Display
  75. (initget "Yes No")
  76. (setq kw (getkword "\nPlace Above Line? [Yes/No] :"))
  77. (if (= kw "Yes")
  78. (progn (setq txsize (getvar 'textsize) pt (polar (apply 'mapcar (cons ''((a b) (* 0.5 (+ a b))) (list a1 a2)))
  79.                  (+ rot (/ pi 2.))
  80.                  (* txsize 3.0)
  81.                  ) ;_ end of polar
  82.        ) ;_  end of setq
  83. (entmake (list        '(0 . "TEXT")
  84.                 '(72 . 1) ; justify
  85.                 (cons 1 tx)
  86.                 (cons 10 pt)
  87.                 (cons 11 pt) ; justify
  88.                 (cons 40 txsize)
  89.                 (cons 50 (MakeReadable (apply 'angle lst)))
  90.                 ) ; list
  91.           ) ;entmake
  92. ) ;_ end of progn
  93. ) ;_ end of if
  94. ;;;; NOTED ERROR AT THIS POINT
  95. ;;;; ; error: bad argument type: numberp: nil
  96. ;; ERROR RESEARCH: A function requiring an integer argument has been passed an argument of incorrect data type with the value noted in the error message.
  97. (princ)
  98. )
  99. (princ)
  100. ;; To Reset Original Varibles - End
  101. (setq olderr *error*)
  102. (setvar "osmode" 11)
  103. (princ)

 
有什么想法吗?
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 21:03:22 | 显示全部楼层
我的道歉,
这是由于rot值不是setq,
  1. lst (list a1 a2)
  2. [color="red"]rot[/color] (MakeReadable (apply 'angle lst))

代码更新后#2
回复

使用道具 举报

4

主题

16

帖子

12

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 21:12:26 | 显示全部楼层
hanhphuc公司
 
成功了!
 
谢谢你的帮助。我读了一整天都没有成功。
 
谢谢你的时间。
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 21:16:28 | 显示全部楼层
 
欢迎你runner214。坚持下去这是你的负担
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 09:26 , Processed in 0.462128 second(s), 66 queries .

© 2020-2025 乐筑天下

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