temo 发表于 2022-7-6 15:59:34

这很好,但对于非直矩形的形状,难道不能编写lisp来从最大x值中减去最小x值,通过用y代替x来获得长度和宽度吗?

temo 发表于 2022-7-6 16:02:06

顺便说一句,你在哪里学会写这些?

Lee Mac 发表于 2022-7-6 16:07:30

哈哈,你回复的时候写的

(defun c:lenwid    (/ ent pt nlist xlist ylist xmax xmin ymax ymin xlen ylen len)

   (defun makelay (x)
   (if (not (tblsearch "Layer" x))
       (progn
       (setvar "cmdecho" 0)
       (command "-layer" "m" x "")
       (setvar "cmdecho" 1)
       ) ;_end progn
   ) ;_end if
   ) ;_end defun
   (makelay "TEXT")

   (defun Make_Text (txt_pt txt_val)
   (entmake
       (list '(0 . "TEXT")
         '(8 . "TEXT")
         (cons 10 txt_pt)
         (cons 40 (max 2.5 (getvar "TEXTSIZE")))
         (cons 1 txt_val)
         '(50 . 0.0)
         '(7 . "STANDARD")
         '(71 . 0)
         '(72 . 1)
         '(73 . 2)
         (cons 11 txt_pt)
       ) ; end list
   ) ; end entmake
   ) ;_end defun

   (if    (and
       (setq ent (car (entsel "\nSelect Object > ")))
       (= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
       (setq pt (getpoint "\nSelect Point for Text > "))
   ) ;_end and
   (progn
       (foreach x (entget ent)
       (if (eq 10 (car x))
         (setq nlist (cons (cdr x) nlist))
       ) ;_end if
       ) ;_end foreach
       (setq nlist (reverse nlist))
       (foreach n nlist
       (setq xlist (cons (car n) xlist)
             ylist (cons (cadr n) ylist)
       ) ;_end setq
       ) ;_end foreach
       (setq xmax (apply 'max xlist)
         xmin (apply 'min xlist)
         ymax (apply 'max ylist)
         ymin (apply 'min ylist)
         xlen (- xmax xmin)
         ylen (- ymax ymin)
       ) ;_end setq
       (if    (> xlen ylen)
       (setq len (strcat "Length of Room = "
               (rtos xlen 2 2)
               ",Width of Room = "
               (rtos ylen 2 2)
             ) ;_end strcat
       ) ;_end setq
       (setq len (strcat "Length of Room = "
               (rtos ylen 2 2)
               ",Width of Room = "
               (rtos xlen 2 2)
             ) ;_end strcat
       ) ;_end setq
       ) ;_end if
       (Make_Text pt len)
   ) ;_end progn
   (princ "\n<!> No Object Selected or Object is not Polyline! <!>")
   ) ;_end if
   (princ)
) ;_end defun

temo 发表于 2022-7-6 16:10:02

含糖的谢谢结果很好

temo 发表于 2022-7-6 16:12:11

等等,单位是英寸。我怎么把它换成脚?

Lee Mac 发表于 2022-7-6 16:16:04

 
上大学前的一个空档年,在一家公司工作时,有人给我看了一个Lisp程序以及它能做什么,我很感兴趣,所以我查看了Lisp程序并试图找出它(很多尝试和错误!)。。。然后我偶然发现了这个论坛,从这里的人那里学到了我现在知道的一切。

Lee Mac 发表于 2022-7-6 16:18:20

 
这样地?
 

(defun c:lenwid    (/ ent pt nlist xlist ylist xmax xmin ymax ymin xlen ylen len)

   (defun makelay (x)
   (if (not (tblsearch "Layer" x))
       (progn
       (setvar "cmdecho" 0)
       (command "-layer" "m" x "")
       (setvar "cmdecho" 1)
       ) ;_end progn
   ) ;_end if
   ) ;_end defun
   (makelay "TEXT")

   (defun Make_Text (txt_pt txt_val)
   (entmake
       (list '(0 . "TEXT")
         '(8 . "TEXT")
         (cons 10 txt_pt)
         (cons 40 (max 2.5 (getvar "TEXTSIZE")))
         (cons 1 txt_val)
         '(50 . 0.0)
         '(7 . "STANDARD")
         '(71 . 0)
         '(72 . 1)
         '(73 . 2)
         (cons 11 txt_pt)
       ) ; end list
   ) ; end entmake
   ) ;_end defun

   (if    (and
       (setq ent (car (entsel "\nSelect Object > ")))
       (= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
       (setq pt (getpoint "\nSelect Point for Text > "))
   ) ;_end and
   (progn
       (foreach x (entget ent)
       (if (eq 10 (car x))
         (setq nlist (cons (cdr x) nlist))
       ) ;_end if
       ) ;_end foreach
       (setq nlist (reverse nlist))
       (foreach n nlist
       (setq xlist (cons (car n) xlist)
             ylist (cons (cadr n) ylist)
       ) ;_end setq
       ) ;_end foreach
       (setq xmax (apply 'max xlist)
         xmin (apply 'min xlist)
         ymax (apply 'max ylist)
         ymin (apply 'min ylist)
         xlen (- xmax xmin)
         ylen (- ymax ymin)
       ) ;_end setq
       (if    (> xlen ylen)
       (setq len (strcat "Length of Room = "
               (rtos (/ xlen 12.0) 2 2)
               ",Width of Room = "
               (rtos (/ ylen 12.0) 2 2)
             ) ;_end strcat
       ) ;_end setq
       (setq len (strcat "Length of Room = "
               (rtos (/ ylen 12.0) 2 2)
               ",Width of Room = "
               (rtos (/ xlen 12.0) 2 2)
             ) ;_end strcat
       ) ;_end setq
       ) ;_end if
       (Make_Text pt len)
   ) ;_end progn
   (princ "\n<!> No Object Selected or Object is not Polyline! <!>")
   ) ;_end if
   (princ)
) ;_end defun

Lee Mac 发表于 2022-7-6 16:23:02

可能也需要(英尺):
 

(defun c:lenwid    (/ ent pt nlist xlist ylist xmax xmin ymax ymin xlen ylen len)

   (defun makelay (x)
   (if (not (tblsearch "Layer" x))
       (progn
       (setvar "cmdecho" 0)
       (command "-layer" "m" x "")
       (setvar "cmdecho" 1)
       ) ;_end progn
   ) ;_end if
   ) ;_end defun
   (makelay "TEXT")

   (defun Make_Text (txt_pt txt_val)
   (entmake
       (list '(0 . "TEXT")
         '(8 . "TEXT")
         (cons 10 txt_pt)
         (cons 40 (max 2.5 (getvar "TEXTSIZE")))
         (cons 1 txt_val)
         '(50 . 0.0)
         '(7 . "STANDARD")
         '(71 . 0)
         '(72 . 1)
         '(73 . 2)
         (cons 11 txt_pt)
       ) ; end list
   ) ; end entmake
   ) ;_end defun

   (if    (and
       (setq ent (car (entsel "\nSelect Object > ")))
       (= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
       (setq pt (getpoint "\nSelect Point for Text > "))
   ) ;_end and
   (progn
       (foreach x (entget ent)
       (if (eq 10 (car x))
         (setq nlist (cons (cdr x) nlist))
       ) ;_end if
       ) ;_end foreach
       (setq nlist (reverse nlist))
       (foreach n nlist
       (setq xlist (cons (car n) xlist)
             ylist (cons (cadr n) ylist)
       ) ;_end setq
       ) ;_end foreach
       (setq xmax (apply 'max xlist)
         xmin (apply 'min xlist)
         ymax (apply 'max ylist)
         ymin (apply 'min ylist)
         xlen (- xmax xmin)
         ylen (- ymax ymin)
       ) ;_end setq
       (if    (> xlen ylen)
       (setq len (strcat "Length of Room = "
               (rtos (/ xlen 12.0) 2 2)
               "ft,Width of Room = "
               (rtos (/ ylen 12.0) 2 2)
               "ft"
             ) ;_end strcat
       ) ;_end setq
       (setq len (strcat "Length of Room = "
               (rtos (/ ylen 12.0) 2 2)
               "ft,Width of Room = "
               (rtos (/ xlen 12.0) 2 2)
               "ft"
             ) ;_end strcat
       ) ;_end setq
       ) ;_end if
       (Make_Text pt len)
   ) ;_end progn
   (princ "\n<!> No Object Selected or Object is not Polyline! <!>")
   ) ;_end if
   (princ)
) ;_end defun

页: 1 [2]
查看完整版本: LISP计算长度和w