明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1269|回复: 2

[基础] 計算數值時,被CAD無條件捨去,程式出錯(求助)

[复制链接]
发表于 2010-12-7 13:53:57 | 显示全部楼层 |阅读模式
这是一个在画砖墙的程式
里面在计算砖块高度的时候,如果有出现小数点,都会被CAD取成整数


Uploaded with ImageShack.us


(defun C:233()
  (setvar "cmdecho" 0);關閉指令回應
  ;;前置動作;;
  (setq p1(getpoint"\n選擇左下角點"))
  (setq hh(getdist"\n輸入高度<65>"))(if(null hh)(setq hh 65))
  (setq ww(getdist"\n輸入寬度<120>"))(if(null ww)(setq ww 120))
  (setq nnh(getint"\n垂直等分量<5>"))(if(null nnh)(setq nnh 5))
  (setq nnw(getint"\n水平等分量<8>"))(if(null nnw)(setq nnw 8))
  
  (setq gapw(/ ww nnw))
  (setq gaph(/ hh nnh))
  
  (print (strcat (rtos hh) " / " (rtos nnh) "=" (rtos gaph)))
  
  (setq p2(polar p1 0 ww))
  (setq p3(polar p2 (* 0.5 pi) hh))
  (setq p4(polar p3 pi ww))
  (setq pa p1)
  (setq pz1(polar p1 (* pi 0.5) gaph))
  (setq pz(polar pz1 pi (* gapw 0.5)))
  (command"line" p1 p4 "")
  (command"line" p2 p3 "")
  (command"line" p1 p2 "")
  (setq en1 (entlast))
  (setq ss1 (ssadd))
  (setq ss2 (ssadd))
  
  (repeat (- nnw 1)
    (setq pa (polar pa 0 gapw))
    (setq pb (polar pa (* 0.5 pi) gaph))
    (command"line" pa pb "")
    (setq ss1(ssadd (entlast) ss1))
  )
  
  (if (> nnh 1)
    (repeat nnw
      (setq pz(polar pz 0 gapw))
      (setq py(polar pz (* pi 0.5) gaph))
      (command "line" pz py "")
      (setq ss2(ssadd (entlast) ss2))
    )
  )
  (command "array" en1 "" "R" (+ nnh 1) 1 gaph 1)
  (if(= (rem nnh 2) 0) (setq an (/ nnh 2)) (setq an(/ (+ nnh 1) 2)))
  (command "array" ss1 "" "R" an 1 (* gaph 2))
  (if(= (rem nnh 2) 0) (setq an (/ nnh 2)) (setq an(/ (- nnh 1) 2)))
  (command "array" ss2 "" "R" an 1 (* gaph 2))
   
(prin1)
)
发表于 2010-12-7 14:14:10 | 显示全部楼层
  (setq gapw (/ ww nnw 1.0))
  (setq gaph (/ hh nnh 1.0))
 楼主| 发表于 2010-12-7 14:23:51 | 显示全部楼层
感谢,原来可以用这种方法来调整小数点的数量
我的问题解决了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-10-2 16:16 , Processed in 0.158059 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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