明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1288|回复: 6

[已解答] 怎么把整数值改成保留一位小数?

[复制链接]
发表于 2015-7-17 15:27 | 显示全部楼层 |阅读模式
怎么把下列代码取整数值改成保留一位小数?

(defun make-same-pline-txt (obj1 obj2)
  (defun chg_pline_link_txt (v1 / p1 p2 p3 w h txt)
    (setq txt (vlax-ldata-get v1 "Link"))
    (if        (not (vlax-erased-p txt))
      (progn
        (setq p1 (vlax-curve-getpointatparam v1 0.)
              p2 (vlax-curve-getpointatparam v1 1.)
              p3 (vlax-curve-getpointatparam v1 2.)
              w         (fix (distance p1 p2))
              h        (fix (distance p2 p3))
        )
        (vl-catch-all-apply
          'vla-put-textstring
          (list        txt
                (strcat (itoa w) "     " (itoa h))
          )
        )
      )
    )
  )
  (defun chg_txt_link_pline (v1 / sp p1 p2 p3 str pos w h pts)
    (setq pl (vlax-ldata-get v1 "Link"))
    (if        (not (vlax-erased-p pl))
      (progn
        (setq sp  (vlax-curve-getstartpoint pl)
              p1  (vlax-curve-getpointatparam pl 1.)
              p2  (vlax-curve-getpointatparam pl 2.)
              p3  (vlax-curve-getpointatparam pl 3.)
              str (vla-get-textstring v1)
              pos (vl-string-position (ascii "     ") str)
              w          (distof (substr str 1 pos))
              h          (distof (substr str (+ pos 2)))
        )
        (vla-put-coordinates
          pl
          (vlax-make-variant
            (vlax-safearray-fill
              (vlax-make-safearray vlax-vbDouble '(0 . 7))
              (apply 'append
                     (list (!last sp)
                           (setq p11 (polar (!last sp) (angle sp p1) w))
                           (setq p22 (polar p11 (angle p1 p2) h))
                           (polar p22 (angle p2 p3) w)
                     )
              )
            )
          )
        )
        (vla-put-closed pl actrue)
      )
    )
  )
  (if (and
        obj2
        (vlax-write-enabled-p obj2)
        (vlax-read-enabled-p obj1)
      )
    (if        (= (vla-get-objectname obj1) "AcDbText")
      (chg_txt_link_pline obj1)
      (chg_pline_link_txt obj1)
    )
  )
)
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2015-7-17 15:40 | 显示全部楼层
(setq w (read (HH:rtosr1 (distance p1 p2) 1));保留一位
http://bbs.mjtd.com/thread-107567-1-1.html
发表于 2015-7-17 16:02 | 显示全部楼层
转字符串再转回来。
(atof(rtos 3.0499999999 2 1))
(atof(rtos 3.0511111111 2 1))

  1. (atof(rtos(distance p1 p2) 2 1))
  2. (atof(rtos(distance p2 p3) 2 1))
 楼主| 发表于 2015-7-17 16:24 | 显示全部楼层
edata 发表于 2015-7-17 16:02
转字符串再转回来。
(atof(rtos 3.0499999999 2 1))
(atof(rtos 3.0511111111 2 1))



原程序代码的效果,用【自贡黄明儒】和 你的方法都不行。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2015-7-17 17:09 | 显示全部楼层
无码无真相,你是不是前面还用了fix。。。。。
 楼主| 发表于 2015-7-17 17:15 | 显示全部楼层
edata 发表于 2015-7-17 17:09
无码无真相,你是不是前面还用了fix。。。。。
  1. (defun !last (lst)
  2. (reverse (cdr (reverse lst))))
  3. (defun make-same-pline-txt (obj1 obj2)
  4. (defun chg_pline_link_txt (v1 / p1 p2 p3 w h txt)
  5. (setq txt (vlax-ldata-get v1 "Link"))
  6. (if (not (vlax-erased-p txt))
  7. (progn
  8. (setq p1 (vlax-curve-getpointatparam v1 0.)
  9.       p2 (vlax-curve-getpointatparam v1 1.)
  10.       p3 (vlax-curve-getpointatparam v1 2.)
  11.       w  (fix (distance p1 p2))
  12.       h  (fix (distance p2 p3)))
  13. (vl-catch-all-apply
  14. 'vla-put-textstring
  15. (list txt
  16. (strcat (itoa h) "     " (itoa w)))))))
  17. (defun chg_txt_link_pline (v1 / sp p1 p2 p3 str pos w h pts)
  18. (setq pl (vlax-ldata-get v1 "Link"))
  19. (if (not (vlax-erased-p pl))
  20. (progn
  21. (setq sp (vlax-curve-getstartpoint pl)
  22.       p1 (vlax-curve-getpointatparam pl 1.)
  23.       p2 (vlax-curve-getpointatparam pl 2.)
  24.       p3 (vlax-curve-getpointatparam pl 3.)
  25.      str (vla-get-textstring v1)
  26.      pos (vl-string-position (ascii "     ") str)
  27.       w  (distof (substr str 1 pos))
  28.       h  (distof (substr str (+ pos 2))))
  29. (vla-put-coordinates
  30. pl
  31. (vlax-make-variant
  32. (vlax-safearray-fill
  33. (vlax-make-safearray vlax-vbDouble '(0 . 7))
  34. (apply 'append
  35. (list (!last sp)
  36. (setq p11 (polar (!last sp) (angle sp p1) w))
  37. (setq p22 (polar p11 (angle p1 p2) h))
  38. (polar p22 (angle p2 p3) w))))))
  39. (vla-put-closed pl actrue))))
  40. (if (and
  41. obj2
  42. (vlax-write-enabled-p obj2)
  43. (vlax-read-enabled-p obj1))
  44. (if (= (vla-get-objectname obj1) "AcDbText")
  45. (chg_txt_link_pline obj1)
  46. (chg_pline_link_txt obj1))))
  47. (defun make-same-pline-txt-reaction (notifier reactor arg-list)
  48. (make-same-pline-txt notifier (VLR-Data reactor)))
  49. (defun c:jxgl (/ e1 e2 obj1 obj2)
  50. (if (and (setq e1 (car (entsel "\n選択ポリライン:")))
  51. (setq e2 (car (entsel "\n選択関連文字:"))))
  52. (progn
  53. (vlax-ldata-put
  54. e1
  55. "Link"
  56. (setq obj2 (vlax-ename->vla-object e2)))
  57. (vlax-ldata-put
  58. e2
  59. "Link"
  60. (setq obj1 (vlax-ename->vla-object e1)))
  61. (setq myReactor
  62. (vlr-object-reactor
  63. (list obj2)
  64. obj1
  65. '((:vlr-modified . make-same-pline-txt-reaction))))
  66. (setq TxtReactor
  67. (vlr-object-reactor
  68. (list obj1)
  69. obj2
  70. '((:vlr-modified . make-same-pline-txt-reaction))))))
  71. (princ))
发表于 2015-7-17 17:43 | 显示全部楼层
  1. (defun !last (lst)
  2. (reverse (cdr (reverse lst))))
  3. (defun make-same-pline-txt (obj1 obj2)
  4. (defun chg_pline_link_txt (v1 / p1 p2 p3 w h txt)
  5. (setq txt (vlax-ldata-get v1 "Link"))
  6. (if (not (vlax-erased-p txt))
  7. (progn
  8. (setq p1 (vlax-curve-getpointatparam v1 0.)
  9.       p2 (vlax-curve-getpointatparam v1 1.)
  10.       p3 (vlax-curve-getpointatparam v1 2.)
  11.       w  (distance p1 p2)
  12.       h  (distance p2 p3))
  13. (vl-catch-all-apply
  14. 'vla-put-textstring
  15. (list txt
  16. (strcat (rtos h 2 1) "     " (rtos w 2 1)))))))
  17. (defun chg_txt_link_pline (v1 / sp p1 p2 p3 str pos w h pts)
  18. (setq pl (vlax-ldata-get v1 "Link"))
  19. (if (not (vlax-erased-p pl))
  20. (progn
  21. (setq sp (vlax-curve-getstartpoint pl)
  22.       p1 (vlax-curve-getpointatparam pl 1.)
  23.       p2 (vlax-curve-getpointatparam pl 2.)
  24.       p3 (vlax-curve-getpointatparam pl 3.)
  25.      str (vla-get-textstring v1)
  26.      pos (vl-string-position (ascii "     ") str)
  27.       w  (distof (substr str 1 pos))
  28.       h  (distof (substr str (+ pos 2))))
  29. (vla-put-coordinates
  30. pl
  31. (vlax-make-variant
  32. (vlax-safearray-fill
  33. (vlax-make-safearray vlax-vbDouble '(0 . 7))
  34. (apply 'append
  35. (list (!last sp)
  36. (setq p11 (polar (!last sp) (angle sp p1) w))
  37. (setq p22 (polar p11 (angle p1 p2) h))
  38. (polar p22 (angle p2 p3) w))))))
  39. (vla-put-closed pl actrue))))
  40. (if (and
  41. obj2
  42. (vlax-write-enabled-p obj2)
  43. (vlax-read-enabled-p obj1))
  44. (if (= (vla-get-objectname obj1) "AcDbText")
  45. (chg_txt_link_pline obj1)
  46. (chg_pline_link_txt obj1))))
  47. (defun make-same-pline-txt-reaction (notifier reactor arg-list)
  48. (make-same-pline-txt notifier (VLR-Data reactor)))
  49. (defun c:jxgl (/ e1 e2 obj1 obj2)
  50. (if (and (setq e1 (car (entsel "\n選択ポリライン:")))
  51. (setq e2 (car (entsel "\n選択関連文字:"))))
  52. (progn
  53. (vlax-ldata-put
  54. e1
  55. "Link"
  56. (setq obj2 (vlax-ename->vla-object e2)))
  57. (vlax-ldata-put
  58. e2
  59. "Link"
  60. (setq obj1 (vlax-ename->vla-object e1)))
  61. (setq myReactor
  62. (vlr-object-reactor
  63. (list obj2)
  64. obj1
  65. '((:vlr-modified . make-same-pline-txt-reaction))))
  66. (setq TxtReactor
  67. (vlr-object-reactor
  68. (list obj1)
  69. obj2
  70. '((:vlr-modified . make-same-pline-txt-reaction))))))
  71. (princ))
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-25 10:00 , Processed in 0.197007 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表