1. ## Draw Rectangle Dimension

Registered forum members do not see this ad.

Hello! I was wondering how I would go about writing a function that would calculate the length of a diagonal of a rectangle using SQRT function? I've been trying but so far nothing!
Thanks!

2. Can you post the code you wrote so far?
Presuming that you know the length, respectively width of the rectangle, you should use Pythagoras formula:
Code:
`(setq sizeDiagonal (sqrt (+ (expt sizeLength 2.0) (expt sizeWidth 2.0))))`

3. Thanks! I had a few simple lines, but I erased those as yours was basically what I needed. Would it be possible to write a function that would find the length & width itself? This one is out of curiosity.

Thanks! I had a few simple lines, but I erased those as yours was basically what I needed. Would it be possible to write a function that would find the length & width itself? This one is out of curiosity.
Try this:
Code:
```(defun LM:MAssoc ( key lst / item )
(if (setq item (assoc key lst))
(cons (cdr item) (LM:MAssoc key (cdr (member item lst))))
)
)
(defun c:getdist (/ s pt1 pt2 pt3 pt4 x y ent lst)
(setq s (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
(if (= s nil)
(progn
(setq ent  (entget(ssname s 0)))
(setq lst (LM:MAssoc 10 ent))
(princ)
(setq pt1 (nth 0 lst))
(setq pt2 (nth 1 lst))
(setq pt3 (nth 2 lst))
(setq pt4 (nth 3 lst))
(setq x(distance pt1 pt2))
(setq y(distance pt1 pt4))
(princ (strcat "\nHeight: " (rtos y) "\nWidth: " (rtos x)))
(princ)
)
)
)```
Yes, thanks to Lee Mac haha

Edit: But there is some problem with this code, if you rotate your rectangle by 90º the height will become width and vice versa.
Nothing that a if can't solve hehe

5. Registered forum members do not see this ad.

Here is another method:
Code:
```(defun c:test ( / lst sel )
(if (setq sel (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
(progn
(setq lst
(mapcar 'cdr
(vl-remove-if-not '(lambda ( x ) (= 10 (car x)))
(entget (ssname sel 0))
)
)
)
(apply 'mapcar
(cons '-
(mapcar
'(lambda ( x ) (apply 'mapcar (cons x lst)))
'(max min)
)
)
)
)
)
)```