# Thread: Lowest y value - coordinate for a polyline

1. ## Lowest y value - coordinate for a polyline

Registered forum members do not see this ad.

Hello,
How to determine te smaller (and bigger) value,Y or X, for a polyline? I mean the Y coordinate on a polyline where Y has the minimum value for the whole polyline?

2. look at the min and max functions
also i think there was a post about this awhile back try to search for it

3. This would make a point at the lowest coordinate point of the selected Polyline that has the smallest Y value in it , besides that it would show the Coordinates of the Point which the point lays on .

Code:
```(vl-load-com)
(defun c:test (/ ss Coords l i p p1 pt)
; Tharwat 15. 06. 2011
(if (eq (getvar 'pdmode) 0)
(setvar 'pdmode 3)
)
(if
(setq ss (ssget "_+.:L" '((0 . "*POLYLINE"))))
(progn
(setq Coords (vlax-get (vlax-ename->vla-object (ssname ss 0))
'Coordinates
)
)
(setq l (/ (length Coords) 2))
(setq i 0
p (cons 10 (list (car Coords) (cadr Coords)))
)
(repeat l
(setq
p1 (cons 10
(list (nth i Coords) (nth (setq i (1+ i)) Coords))
)
)
(setq p p1)
)
(setq i (1+ i))
)
(print p)

(entmakex (list (cons 0 "POINT") p))
)
(princ)
)
(princ)
)```
Tharwat

4. ???

*cough* GetBoundingBox *cough*

Code:
```(defun c:GBB () (c:GetBoundingBox))
(defun c:GetBoundingBox (/ ss v mn mx)
(princ "\rGET BOUNDING BOX \n")
(if (and (setq ss (ssget ":S:E" ))
(vlax-method-applicable-p
(setq v (vlax-ename->vla-object (ssname ss 0)))
'getboundingbox))
(progn
(vla-getboundingbox v 'mn 'mx)
(princ (mapcar 'vlax-safearray->list (list mn mx))))
(cond (ss (prompt "\n** GetBoundingBox method not available ** "))
((prompt "\n** Nothing selected ** "))))
(princ))```
Untested - Written quickly on my MacBook from memory.

5. Hi Renderman .

The (min max) are functions and you have used them as variables . Is that possible ?

Code:
`(/ ss v min max)`
Regards.

Tharwat

6. Originally Posted by Tharwat
Hi Renderman .

The (min max) are functions and you have used them as variables . Is that possible ?

Code:
`(/ ss v min max)`
I noticed that too when I came to work to test (code works BTW).

Sadly, it was a typo on my part typing code in the forum text box. Code corrected.

7. No worries mate .

Best regards.

8. Here's some old code I wrote to find the Max/Min points of a curve:

Code:
```(defun LM:CurveMinMax
( obj fuzz / _GetBoundingBoxWithOffset _GroupByNum _FlattenPoint a acdoc acspc lst obj tmp )

(defun _GetBoundingBoxWithOffset ( obj o / ll ur )
(
(lambda ( a )
(mapcar
(function
(lambda ( b )
(mapcar
(function
(lambda ( c ) ((eval c) a))
)
b
)
)
)
'(
(
(lambda ( x ) (- (caar  x) o))
(lambda ( x ) (- (cadar x) o))
)
(
(lambda ( x ) (+ (caadr x) o))
(lambda ( x ) (- (cadar x) o))
)
(
(lambda ( x ) (+ (caadr  x) o))
(lambda ( x ) (+ (cadadr x) o))
)
(
(lambda ( x ) (- (caar   x) o))
(lambda ( x ) (+ (cadadr x) o))
)
)
)
)
(mapcar 'vlax-safearray->list
(progn (vla-getboundingbox obj 'll 'ur) (list ll ur))
)
)
)

(defun _GroupByNum ( l n / r)
(if l
(cons
(reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r))
(_GroupByNum l n)
)
)
)

(defun _FlattenPoint ( p )
(list (car p) (cadr p) 0.0)
)

(setq acdoc (vla-get-activedocument (vlax-get-acad-object))
acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace))
)
(cond
( (not (vlax-method-applicable-p obj 'GetBoundingBox))
)
( t
(setq tmp
(mapcar
(function
(lambda ( x )
(apply 'vla-addline (cons acspc (mapcar 'vlax-3D-point x)))
)
)
(_GroupByNum (mapcar '_FlattenPoint (_GetBoundingBoxWithOffset obj (- fuzz))) 2)
)
)
(setq lst
(mapcar
(function
(lambda ( x )
(car (_GroupByNum (vlax-invoke obj 'Intersectwith x acExtendOtherEntity) 3))
)
)
tmp
)
)
(mapcar 'vla-delete tmp)
lst
)
)
)

;; Test Function

(defun c:test( / e m )
(if
(and
(setq e (car (entsel)))
(setq m (LM:CurveMinMax (vlax-ename->vla-object e) 1e-8))
(apply 'and m)
)
(foreach x m
(entmakex (list (cons 0 "POINT") (cons 10 x)))
)
)
(princ)
)```

9. Originally Posted by Tharwat
Hi Renderman .

The (min max) are functions and you have used them as variables . Is that possible ?

Code:
`(/ ss v min max)`
Regards.

Tharwat
It's "possible", since you can redefine anything in Lisp - and since they're localized variables they won't affect enything outside the defun - so the min & max functions wont be removed in other places. Though this is not recommended and would cause a warning message in VLIDE (something like protected symbol redefined).

10. Registered forum members do not see this ad.

Originally Posted by irneb
(something like protected symbol redefined).
Thank you .

I have faced that message before which made me panic for a long time and after searching in that time I have realized the main issue of it , and I doubt I may forget these memories with it and the perfect lesson that I had .

Regards.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts