乐筑天下

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

[编程交流] 你能帮我解决这个Lisp程序吗

[复制链接]

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-5 22:35:45 | 显示全部楼层 |阅读模式
您好,我正在学习lisp,所以我决定写一个代码来计算打印后的纸张长度和打印成本
我知道用excel或计算器很容易计算,但对我来说这是一个练习。
 
对于我的所有图形,要设置块和文本大小的比例,我使用此lisp
  1. ( DEFUN C:SETSC ()
  2.    (SETQ CURSC (getvar "useri1" ))
  3.    (princ "the printing scale is 1:")(princ cursc)
  4.    (setq newsc (getint "\ngive a new scale  1:"))
  5.    (setvar "useri1" newsc)
  6.      (setq a1 (getvar "useri1"))
  7.    (princ "\n the new printing scale is  1:")(princ newsc)(princ)
  8. )

 
这是我写的代码,但有几个问题
 
我想选择两行,捕捉行的长度,然后计算打印长度、打印面积和打印成本
 
  1. (defun c:SD (/ scl lnx lny ex ey area cost)
  2. (setq scl (getvar "useri1"))
  3. (setq ex (entsel "\n select first line :"))
  4. (setq lnx (/ scl (getdist ex)))
  5. (setq ey (entsel "\n select second line :"))
  6. (setq lny (/ scl (getdist ey)))
  7. (setq area ( * lnx lny))
  8. ;the cost for the printing is  1.42€ / sq.m  (this price is for the example)
  9. (setq cost ( * 1.42 area))
  10. (princ (strcat  "The length of the print paper and the cost is"
  11.                    "\n length x = "
  12.                     (rtos lnx 2 2)
  13.                     " m"
  14.                     "\n length y = "
  15.                     (rtos lny 2 2)
  16.                     " m"
  17.                     "\n Area = "
  18.                     (rtos area 2 2)
  19.                     " sq.m"
  20.                     "\n cost = "
  21.                     (rtos cost 2 2)
  22.                     " €"
  23.             )
  24.      )
  25. (princ)
  26. )                                        ; end defun

 
该代码中的问题是
 
a) 仅选择一行
b) 不打印结果
 
看看测试。dwg,你会理解的
 
当我选择长度为118.80的行时,请打印此错误
 
 
比你。。
测验图纸
回复

使用道具 举报

7o7

0

主题

93

帖子

93

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 22:45:06 | 显示全部楼层
无法通过(car(entsel))来获取对象的距离。
相反,你写:
  1. (setq ex (getdist ))
  2. (setq lnx (/ scl ex))
  3. (setq ey (getdist ))
  4. (setq lny (/ scl ey))
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-5 22:53:40 | 显示全部楼层
您好7o7谢谢您的建议。
 
我把代码改成这个但是
a) 我不能选择直线,只能选择点
b) 计算错误????
 
  1. (defun c:SD (/ scl lnx lny ex ey area cost)
  2. (setq scl (getvar "useri1"))
  3. (setq ex (getdist "\n select first line :"))
  4. (setq lnx (/ scl ex))
  5. (setq ey (getdist "\n select second line :"))
  6. (setq lny (/ scl ey))
  7. (setq area ( * lnx lny))
  8. ;the cost for the printing is  1.42€ / sq.m  (this price is for the example)
  9. (setq cost ( * 1.42 area))
  10. (princ (strcat  "The length of the print paper and the cost is"
  11.                    "\n length x = "
  12.                     (rtos lnx 2 2)
  13.                     " m"
  14.                     "\n length y = "
  15.                     (rtos lny 2 2)
  16.                     " m"
  17.                     "\n Area = "
  18.                     (rtos area 2 2)
  19.                     " sq.m"
  20.                     "\n cost = "
  21.                     (rtos cost 2 2)
  22.                     " €"
  23.             )
  24.      )
  25. (princ)
  26. )       

 
你能帮忙吗谢谢
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-5 23:00:26 | 显示全部楼层
我把这两行改了
 
  1. (setq lnx (/ scl ex))
  2. (setq lny (/ scl ey))

 
结果更好,但不正确
线路选择存在问题
 
  1. (defun c:SD (/ scl lnx lny ex ey area cost)
  2. (setq scl (getvar "useri1"))
  3. (setq ex (getdist "\n select first line :"))
  4. (setq lnx (/ ex scl))
  5. (setq ey (getdist "\n select second line :"))
  6. (setq lny (/ ey scl))
  7. (setq area ( * lnx lny))
  8. ;the cost for the printing is  1.42€ / sq.m  (this price is for the example)
  9. (setq cost ( * 1.42 area))
  10. (princ (strcat  "The length of the print paper and the cost is"
  11.                    "\n length x = "
  12.                     (rtos lnx 2 2)
  13.                     " m"
  14.                     "\n length y = "
  15.                     (rtos lny 2 2)
  16.                     " m"
  17.                     "\n Area = "
  18.                     (rtos area 2 2)
  19.                     " sq.m"
  20.                     "\n cost = "
  21.                     (rtos cost 2 2)
  22.                     " €"
  23.             )
  24.      )
  25. (princ)
  26. )       

 
谢谢
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-5 23:05:19 | 显示全部楼层
我解决了计算问题
我不知道如何选择线路和获得距离。
 
  1. (defun c:SD (/ scl lnx lny ex ey area cost)
  2. (setq scl (getvar "useri1"))
  3. (setq ex (getdist "\n select first line :"))
  4. (setq ey (getdist "\n select second line :"))
  5. (setq lnx (/ ex scl))
  6. (setq lny (/ ey scl))
  7. (setq area ( * lnx lny))
  8. ;the cost for the printing is  1.42€ / sq.m  (this price is for the example)
  9. (setq cost ( * 1.42 area))
  10. (princ (strcat  "The length of the print paper and the cost is"
  11.                    "\n length x = "
  12.                     (rtos lnx 2 2)
  13.                     " m"
  14.                     "\n length y = "
  15.                     (rtos lny 2 2)
  16.                     " m"
  17.                     "\n Area = "
  18.                     (rtos area 2 2)
  19.                     " sq.m"
  20.                     "\n cost = "
  21.                     (rtos cost 2 2)
  22.                     " €"
  23.             )
  24.      )
  25. (princ)
  26. )       

 
有什么想法吗?
 
谢谢
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 23:12:33 | 显示全部楼层
尝试
  1. (defun c:SD (/ scl lnx lny ex ey area cost)
  2. (setq scl (getvar "userr1")); ; [color="red"]<---- can not be zerop [/color]
  3. (initget 7)
  4. (setq scl (getreal "\nInput scale")) ;<--- or try manual input
  5. [color="gray"];;;  (setq ex (getdist "\n select first line :"))
  6. ;;;  (setq ey (getdist "\n select second line :"))[/color]
  7. (setq ex (entsel "\n select first line :"))
  8. (setq ey (entsel "\n select second line :"))
  9. [color="blue"](setq area (apply '*
  10.           (mapcar 'set
  11.                   '(lnx lny)
  12.                   (mapcar ''((x) (/ (vlax-get (vlax-ename->vla-object (car x)) "Length") scl)) (list ex ey))
  13.                   ) ;_ end of mapcar
  14.           ) ;_ end of apply
  15.      ) ;_ end of setq[/color]
  16. [color="gray"];;;  (setq lnx (/ ex scl))
  17. ;;;  (setq lny (/ ey scl))
  18. ;;;  (setq area ( * lnx lny))[/color]
  19. ;the cost for the printing is  1.42€ / sq.m  (this price is for the example)
  20. (setq cost ( * 1.42 area))
  21. (princ (strcat  "\nThe length of the print paper and the cost is"
  22.                    "\n length x = "
  23.                     (rtos lnx 2 2)
  24.                     " m"
  25.                     "\n length y = "
  26.                     (rtos lny 2 2)
  27.                     " m"
  28.                     "\n Area = "
  29.                     (rtos area 2 2)
  30.                     " sq.m"
  31.                     "\n cost = "
  32.                     (rtos cost 2 2)
  33.                     " €"
  34.             )
  35.      )
  36. (princ)
  37. )
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-5 23:17:45 | 显示全部楼层
谢谢大家的帮助
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 23:24:59 | 显示全部楼层
嗨,比格尔,是的,我同意你的方法可以得到适当的二维面积长度。
vla获取长度很容易,但由于长度是3D的,因此如果选定的线具有不同的高程,则可能会得到错误的结果。
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-5 23:29:45 | 显示全部楼层
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 23:36:14 | 显示全部楼层
hi BIGAL, yes i agree your method can get proper 2D length for area.
The vla-get-length is easy so but, due to length is 3D, so it may get incorrect result if selected lines have different elevations.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 06:09 , Processed in 0.458808 second(s), 72 queries .

© 2020-2025 乐筑天下

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