# max and min coordinate in polyline

## Recommended Posts

hello everyone, i want an autolisp function to get maximum and minimum coordinate in a polyline, such as below image A is min and B is max Coordinates that i want to get them.

A = (x,y)

B = (x,y)

##### Share on other sites

Try this function :

```(defun get:min (l)
(list	(apply 'min (mapcar 'car l))
)
)
```

Example :

```_\$ (get:min '((1 6)(2 5)(3 4)))
(1 4)
```

Use (get:min (list a b)) in your case

##### Share on other sites
```
(defun c:plminmax ( / lw pl pmin pmax )
(while
(or
(not (setq lw (car (entsel "\nPick LWPOLYLINE..."))))
(if lw
(/= (cdr (assoc 0 (entget lw))) "LWPOLYLINE")
)
)
(prompt "\nMissed or picked wrong entity type...")
)
(setq pl (mapcar '(lambda ( p ) (trans (list (car p) (cadr p) (cdr (assoc 38 (entget lw)))) lw 0)) (mapcar 'cdr (vl-remove-if  '(lambda ( x ) (/= (car x) 10)) (entget lw)))))
(setq pmin  (car (setq pl (vl-sort pl '(lambda ( a b ) (if (equal (cadr a) (cadr b)  1e- (< (car a) (car b)) (< (cadr a) (cadr b))))))))
(setq pmax (last pl))
(prompt "\nA - pmin = ")(princ pmin)
(prompt "\nB - pmax = ")(princ pmax)
(princ)
)
```

##### Share on other sites

\$0.02 - 'bounding box' should return min max as well

##### Share on other sites

thank you all,,, my problem has been resolved by your help.

##### Share on other sites
Try this function :

```(defun get:min (l)
(list	(apply 'min (mapcar 'car l))
)
)
```

Example :

```_\$ (get:min '((1 6)(2 5)(3 4)))
(1 4)
```

Use (get:min (list a b)) in your case

\$0.02 - 'bounding box' should return min max as well

Such solutions will not necessarily yield a point on the polyline.

##### Share on other sites
Posted (edited)

EDIT: I just realized its too easy for any shape

Lisp Code

Edited by pBe

##### Share on other sites
Such solutions will not necessarily yield a point on the polyline.

oops, i misunderstood. In case polyline has bulge, i thought OP looking merely min max like bbox

thanks Lee

##### Share on other sites
bbox

Oddly enough, that's exactly what i use: [ code removed from link ]

```(defun c:HiLow (/ obj pts)
(while (setq obj (Car (entsel)))
(progn
(vla-getboundingbox (vlax-ename->vla-object obj) 'll 'ur)
(setq pts	(mapcar	'(lambda (p)
(vlax-curve-getClosestPointToProjection
obj
(vlax-safearray->list p)
'(1.0 0.0 0.0)
)
)
(list ll ur)
)
)
;;	for showing the points		;;
(Foreach p pts
(entmakex (list	(cons 0 "POINT")
(cons 10 p)
)
)
)
)
)
)```

##### Share on other sites
Oddly enough, that's exactly what i use: [ code removed from link ]

```(defun c:HiLow (/ obj pts) .... )
```

BingoBox finally explained doubt thanks