prodromosm 发表于 2022-7-5 22:35:45

你能帮我解决这个口齿不清吗

您好,我正在学习lisp,所以我决定写一个代码来计算打印后的纸张长度和打印成本
我知道用excel或计算器很容易计算,但对我来说这是一个练习。
 
对于我的所有图形,要设置块和文本大小的比例,我使用此lisp
( DEFUN C:SETSC ()
   (SETQ CURSC (getvar "useri1" ))
   (princ "the printing scale is 1:")(princ cursc)
   (setq newsc (getint "\ngive a new scale1:"))
   (setvar "useri1" newsc)
   (setq a1 (getvar "useri1"))
   (princ "\n the new printing scale is1:")(princ newsc)(princ)
)
 
这是我写的代码,但有几个问题
 
我想选择两行,捕捉行的长度,然后计算打印长度、打印面积和打印成本
 
(defun c:SD (/ scl lnx lny ex ey area cost)
(setq scl (getvar "useri1"))
(setq ex (entsel "\n select first line :"))
(setq lnx (/ scl (getdist ex)))
(setq ey (entsel "\n select second line :"))
(setq lny (/ scl (getdist ey)))
(setq area ( * lnx lny))
;the cost for the printing is1.42€ / sq.m(this price is for the example)
(setq cost ( * 1.42 area))
(princ (strcat"The length of the print paper and the cost is"
                   "\n length x = "
                  (rtos lnx 2 2)
                  " m"
                  "\n length y = "
                  (rtos lny 2 2)
                  " m"
                  "\n Area = "
                  (rtos area 2 2)
                  " sq.m"
                  "\n cost = "
                  (rtos cost 2 2)
                  " €"
            )
   )

(princ)
)                                        ; end defun

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

7o7 发表于 2022-7-5 22:45:06

无法通过(car(entsel))来获取对象的距离。
相反,你写:

(setq ex (getdist ))
(setq lnx (/ scl ex))
(setq ey (getdist ))
(setq lny (/ scl ey))

prodromosm 发表于 2022-7-5 22:53:40

您好7o7谢谢您的建议。
 
我把代码改成这个但是
a) 我不能选择直线,只能选择点
b) 计算错误????
 
(defun c:SD (/ scl lnx lny ex ey area cost)
(setq scl (getvar "useri1"))
(setq ex (getdist "\n select first line :"))
(setq lnx (/ scl ex))
(setq ey (getdist "\n select second line :"))
(setq lny (/ scl ey))
(setq area ( * lnx lny))
;the cost for the printing is1.42€ / sq.m(this price is for the example)
(setq cost ( * 1.42 area))
(princ (strcat"The length of the print paper and the cost is"
                   "\n length x = "
                  (rtos lnx 2 2)
                  " m"
                  "\n length y = "
                  (rtos lny 2 2)
                  " m"
                  "\n Area = "
                  (rtos area 2 2)
                  " sq.m"
                  "\n cost = "
                  (rtos cost 2 2)
                  " €"
            )
   )

(princ)
)       
 
你能帮忙吗谢谢

prodromosm 发表于 2022-7-5 23:00:26

我把这两行改了
 

(setq lnx (/ scl ex))
(setq lny (/ scl ey))

 
结果更好,但不正确
线路选择存在问题
 
(defun c:SD (/ scl lnx lny ex ey area cost)
(setq scl (getvar "useri1"))
(setq ex (getdist "\n select first line :"))
(setq lnx (/ ex scl))
(setq ey (getdist "\n select second line :"))
(setq lny (/ ey scl))
(setq area ( * lnx lny))
;the cost for the printing is1.42€ / sq.m(this price is for the example)
(setq cost ( * 1.42 area))
(princ (strcat"The length of the print paper and the cost is"
                   "\n length x = "
                  (rtos lnx 2 2)
                  " m"
                  "\n length y = "
                  (rtos lny 2 2)
                  " m"
                  "\n Area = "
                  (rtos area 2 2)
                  " sq.m"
                  "\n cost = "
                  (rtos cost 2 2)
                  " €"
            )
   )

(princ)
)       
 
谢谢

prodromosm 发表于 2022-7-5 23:05:19

我解决了计算问题
我不知道如何选择线路和获得距离。
 
(defun c:SD (/ scl lnx lny ex ey area cost)
(setq scl (getvar "useri1"))
(setq ex (getdist "\n select first line :"))
(setq ey (getdist "\n select second line :"))
(setq lnx (/ ex scl))
(setq lny (/ ey scl))
(setq area ( * lnx lny))
;the cost for the printing is1.42€ / sq.m(this price is for the example)
(setq cost ( * 1.42 area))
(princ (strcat"The length of the print paper and the cost is"
                   "\n length x = "
                  (rtos lnx 2 2)
                  " m"
                  "\n length y = "
                  (rtos lny 2 2)
                  " m"
                  "\n Area = "
                  (rtos area 2 2)
                  " sq.m"
                  "\n cost = "
                  (rtos cost 2 2)
                  " €"
            )
   )

(princ)
)       
 
有什么想法吗?
 
谢谢

hanhphuc 发表于 2022-7-5 23:12:33

尝试

(defun c:SD (/ scl lnx lny ex ey area cost)

(setq scl (getvar "userr1")); ; <---- can not be zerop

(initget 7)
(setq scl (getreal "\nInput scale")) ;<--- or try manual input

;;;(setq ex (getdist "\n select first line :"))
;;;(setq ey (getdist "\n select second line :"))

(setq ex (entsel "\n select first line :"))
(setq ey (entsel "\n select second line :"))

(setq area (apply '*
          (mapcar 'set
                  '(lnx lny)
                  (mapcar ''((x) (/ (vlax-get (vlax-ename->vla-object (car x)) "Length") scl)) (list ex ey))
                  ) ;_ end of mapcar
          ) ;_ end of apply
   ) ;_ end of setq

;;;(setq lnx (/ ex scl))
;;;(setq lny (/ ey scl))
;;;(setq area ( * lnx lny))


;the cost for the printing is1.42€ / sq.m(this price is for the example)
(setq cost ( * 1.42 area))
(princ (strcat"\nThe length of the print paper and the cost is"
                   "\n length x = "
                  (rtos lnx 2 2)
                  " m"
                  "\n length y = "
                  (rtos lny 2 2)
                  " m"
                  "\n Area = "
                  (rtos area 2 2)
                  " sq.m"
                  "\n cost = "
                  (rtos cost 2 2)
                  " €"
            )
   )

(princ)
)

prodromosm 发表于 2022-7-5 23:17:45

谢谢大家的帮助

BIGAL 发表于 2022-7-5 23:24:59

嗨,比格尔,是的,我同意你的方法可以得到适当的二维面积长度。
vla获取长度很容易,但由于长度是3D的,因此如果选定的线具有不同的高程,则可能会得到错误的结果。

prodromosm 发表于 2022-7-5 23:29:45

hanhphuc 发表于 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.
页: [1]
查看完整版本: 你能帮我解决这个Lisp程序吗