flopo Posted June 15, 2011 Share Posted June 15, 2011 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? Quote Link to comment Share on other sites More sharing options...
JohnM Posted June 15, 2011 Share Posted June 15, 2011 look at the min and max functions also i think there was a post about this awhile back try to search for it Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 15, 2011 Share Posted June 15, 2011 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 . (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)) ) ) (if (< (caddr p1) (caddr p)) (setq p p1) ) (setq i (1+ i)) ) (print p) (entmakex (list (cons 0 "POINT") p)) ) (princ) ) (princ) ) Tharwat Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 15, 2011 Share Posted June 15, 2011 (edited) ??? *cough* GetBoundingBox *cough* (defun c:GBB () (c:GetBoundingBox)) (defun c:GetBoundingBox (/ ss v mn mx) (vl-load-com) (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. Edited June 15, 2011 by BlackBox Code correction Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 15, 2011 Share Posted June 15, 2011 Hi Renderman . The (min max) are functions and you have used them as variables . Is that possible ? (/ ss v [color=blue][b]min max[/b][/color]) Regards. Tharwat Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 15, 2011 Share Posted June 15, 2011 Hi Renderman . The (min max) are functions and you have used them as variables . Is that possible ? (/ ss v [color=blue][b]min max[/b][/color]) 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. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 15, 2011 Share Posted June 15, 2011 No worries mate . Best regards. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 15, 2011 Share Posted June 15, 2011 Here's some old code I wrote to find the Max/Min points of a curve: (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-) (apply 'and m) ) (foreach x m (entmakex (list (cons 0 "POINT") (cons 10 x))) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
irneb Posted June 16, 2011 Share Posted June 16, 2011 Hi Renderman . The (min max) are functions and you have used them as variables . Is that possible ? (/ ss v [color=blue][b]min max[/b][/color]) 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). Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 16, 2011 Share Posted June 16, 2011 (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. Quote Link to comment Share on other sites More sharing options...
flopo Posted December 21, 2011 Author Share Posted December 21, 2011 Hi guys, I have a lisp with points defined like j1, j2......j10. Sometimes i can have only j1...j6, and sometimes j1...j10. I' trying to calculate lowest point on y like this (SETQ PMIN (MIN (CADR J1) (CADR J2 )(CADR J3 )(CADR J4 )(CADR J5 )(CADR J6 )(CADR J7 ) (CADR J8 )(CADR J9 )(CADR J10 ))) when i have only j1...j5 is not working (of course!!). How to do this ? Which condition to add to make this work? ...If j6 exist, then.... how to do this? Thanks! Quote Link to comment Share on other sites More sharing options...
BlackBox Posted December 21, 2011 Share Posted December 21, 2011 Consider using the MAPCAR function. Here's a small example using the coordinates of a rectangle drawn in WCS, then rotated 5 degrees (so clearly one vertex is the lowest): (defun _LowYcoord (pointList) (car (vl-sort (mapcar 'cadr pointList) '<)) ) VLIDE Console (lowest Y value): _LOWYCOORD _$ (_LowYcoord '((-11.1758 20.4623 0.00) (2.19028 21.6316 0.00) (3.11153 11.1017 0.00) (-10.2546 [color=red]9.93234[/color] 0.00))) 9.93234 _$ ** Note that the supplied argument may be a list of any number of coordinates, either 2D (X Y), or 3D (X Y Z). HTH Quote Link to comment Share on other sites More sharing options...
flopo Posted December 21, 2011 Author Share Posted December 21, 2011 (SETQ POINTLIST (LIST 'J1 'J2 'J3 'J4 'J5 'J6 'J7 'J8 'J9 'J10)) (SETQ PCOTAMIN (car (vl-sort (mapcar 'cadr pointList) '<))) LIKE THIS? HOW? Quote Link to comment Share on other sites More sharing options...
alanjt Posted December 21, 2011 Share Posted December 21, 2011 Consider using the MAPCAR function. Here's a small example using the coordinates of a rectangle drawn in WCS, then rotated 5 degrees (so clearly one vertex is the lowest): (defun _LowYcoord (pointList) (car (vl-sort (mapcar 'cadr pointList) '<)) ) VLIDE Console (lowest Y value): _LOWYCOORD _$ (_LowYcoord '((-11.1758 20.4623 0.00) (2.19028 21.6316 0.00) (3.11153 11.1017 0.00) (-10.2546 [color=red]9.93234[/color] 0.00))) 9.93234 _$ ** Note that the supplied argument may be a list of any number of coordinates, either 2D (X Y), or 3D (X Y Z). HTH (defun _lowYcoord (pointlist) (car (vl-sort pointlst (function (lambda (a b) (< (cadr a) (cadr b)))))) ) Quote Link to comment Share on other sites More sharing options...
BlackBox Posted December 21, 2011 Share Posted December 21, 2011 Slight modification: (defun _LowYcoord (pointList) (car (vl-sort (mapcar 'cadr [color=blue](mapcar 'eval[/color] pointList[color=blue])[/color]) '<)) ) Example: (setq J1 '(-11.1758 20.4623 0.00)) (setq J2 '(2.19028 21.6316 0.00)) (setq J3 '(3.11153 11.1017 0.00)) (setq J4 '(-10.2546 9.93234 0.00)) (setq pointList '(J1 J2 J3 J4)) (_LowYcoord pointList) Quote Link to comment Share on other sites More sharing options...
flopo Posted December 21, 2011 Author Share Posted December 21, 2011 I don't understand... I need a point... Which is the lowest point in this case? How to use it in the lisp after? I need to set a point... (setq pmin ....) ?? how? (SETQ PMIN (_LowYcoord pointList)) ??? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted December 21, 2011 Share Posted December 21, 2011 (edited) I don't understand... I need a point... Which is the lowest poit in this case? How to use it in the lisp after? I need to set a point... (setq pmin ....) ?? how?(SETQ PMIN (_LowYcoord pointList)) ??? Sorry, I got hung up on the 'Y' in your previous post: I' trying to calculate lowest point on y like this ! Give this a try: (defun _LowYcoord (pointList) (car (vl-sort (mapcar 'eval pointList) '(lambda (a b) (< (cadr a) (cadr b))))) ) *Tips hat to Alan* Edited December 21, 2011 by BlackBox Quote Link to comment Share on other sites More sharing options...
flopo Posted December 21, 2011 Author Share Posted December 21, 2011 Same question as above...hot to set that point?? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted December 21, 2011 Share Posted December 21, 2011 Same question as above...hot to set that point?? Same response as above... Here's an(other) example from Console using this function: _LOWYCOORD _$ (setq J1 '(-11.1758 20.4623 0.00)) (-11.1758 20.4623 0.0) _$ (setq J2 '(2.19028 21.6316 0.00)) (2.19028 21.6316 0.0) _$ (setq J3 '(3.11153 11.1017 0.00)) (3.11153 11.1017 0.0) _$ (setq J4 '(-10.2546 9.93234 0.00)) (-10.2546 9.93234 0.0) _$ [color=blue](setq pointList '(J1 J2 J3 J4))[/color] (J1 J2 J3 J4) _$[color=red] (setq pMin (_LowYcoord pointList))[/color] (-10.2546 9.93234 0.0) _$ Quote Link to comment Share on other sites More sharing options...
pBe Posted December 21, 2011 Share Posted December 21, 2011 Same response as above... Hello... Hello.. Hello... Hello.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.