temo 发表于 2022-7-6 15:21:40

LISP计算长度和w

有没有办法使用LISP计算形状的长度和宽度?例如,获取在楼层平面上绘制的房间的长度和宽度。
 
谢谢

Lee Mac 发表于 2022-7-6 15:28:12

应该可以,房间是用多段线建造的吗?

temo 发表于 2022-7-6 15:31:08

是的,它是使用多段线构造的

Lee Mac 发表于 2022-7-6 15:35:35

又快又脏:
 

(defun c:lenwid    (/ ent nlist d1 d2)
   (if    (and
       (setq ent (car (entsel "\nSelect Object: ")))
       (= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
   ) ;_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))
       (setq d1 (distance (nth 0 nlist)
                  (nth 1 nlist)
            ) ;_end distance
         d2 (distance (nth 1 nlist)
                  (nth 2 nlist)
            ) ;_end distance
       ) ;_end setq
       (if    (> d1 d2)
       (princ (strcat "\nLength of Room = "
                  (rtos d1 2 2)
                  "\tWidth of Room = "
                  (rtos d2 2 2)
            ) ;_end strcat
       ) ;_end princ
       (princ (strcat "\nLength of Room = "
                  (rtos d2 2 2)
                  "\tWidth of Room = "
                  (rtos d1 2 2)
            ) ;_end strcat
       ) ;_end princ
       ) ;_end if
   ) ;_end progn
   (princ "\n<!> No Object Selected or Object is not Polyline! <!>")
   ) ;_end if
   (princ)
) ;_end defun


temo 发表于 2022-7-6 15:38:39

这将如何在非矩形的房间上工作?

temo 发表于 2022-7-6 15:41:44

此外,它是否可以显示在形状内部的屏幕上,而不是在命令行中?

Lee Mac 发表于 2022-7-6 15:44:02

 
我说它又快又脏
 
只需快速输入即可。
 
我去看看

temo 发表于 2022-7-6 15:46:54

哈哈,对不起。
 
谢谢你的帮助。我非常感谢。

Lee Mac 发表于 2022-7-6 15:53:01

这会将文本放入图形中:
 

(defun c:lenwid    (/ ent pt nlist d1 d2 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))
       (setq d1 (distance (nth 0 nlist)
                  (nth 1 nlist)
            ) ;_end distance
         d2 (distance (nth 1 nlist)
                  (nth 2 nlist)
            ) ;_end distance
       ) ;_end setq
       (if    (> d1 d2)
       (setq len (strcat "Length of Room = "
               (rtos d1 2 2)
               ",Width of Room = "
               (rtos d2 2 2)
             ) ;_end strcat
       ) ;_end setq
       (setq len (strcat "Length of Room = "
               (rtos d2 2 2)
               ",Width of Room = "
               (rtos d1 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 15:55:38

 
没问题,我理解你的意思-我对Lisp程序也不满意。
页: [1] 2
查看完整版本: LISP计算长度和w