brams Posted May 24, 2012 Posted May 24, 2012 For a selection set (any type of entity), i want to determine the point on entity with lowest value on Y axis - how? This point shoud be situated on a entity from my selection set. Quote
pBe Posted May 24, 2012 Posted May 24, 2012 From the Autocad Help (vl-sort '((1 3) (2 2) (3 1)) (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))) where (cadr e1)(cadr e2) is 2nd element of a list i.e (setq ptlist '((259.81 1836.12 0.0) (201.542 1955.57 0.0) (395.77 1949.59 0.0) [color=blue](226.194 1754.74 0.0)[/color] (187.348 1939.14 0.0))) ([color=blue]car [/color](vl-sort ptlist (function (lambda (e1 e2) (< (cadr e1) (cadr e2)))))) [color=blue](226.194 1754.74 0.0)[/color] Quote
MSasu Posted May 24, 2012 Posted May 24, 2012 Since the lowest point of an entity may be stored or not in his associated list (i.e. the lowest quadrant of a circle item), then what I will do is to create a selection set with items to be checked and then parse the said set and apply Lee Mac’s routine for bounding box. From this will extract the list of Y coordinates to sort. Quote
pBe Posted May 24, 2012 Posted May 24, 2012 oh yeah.. what MSasu said, Then you use vl-sort.... that is. Quote
brams Posted May 24, 2012 Author Posted May 24, 2012 Something found with google and something added....seems to work ... (defun c:GBB () (c:GetBoundingBox)) (defun c:GetBoundingBox (/ ss v mn mx lxs lys lxd lyd) (vl-load-com) (princ "\rGET BOUNDING BOX \n") (setq ss (ssget)) (setq i 0) (repeat (sslength ss) (vlax-method-applicable-p (setq v (vlax-ename->vla-object (ssname ss i))) 'getboundingbox ) ;_ end of vlax-method-applicable-p (vla-getboundingbox v 'mn 'mx) (setq p (mapcar 'vlax-safearray->list (list mn mx))) (setq xs (car (car p))) (setq ys (cadr (car p))) (setq xd (car (cadr p))) (setq yd (cadr (cadr p))) (setq lxs (cons xs lxs)) (setq lys (cons ys lys)) (setq lxd (cons xd lxd)) (setq lyd (cons yd lyd)) (setq mxs (apply 'min lxs)) (setq mys (apply 'min lys)) (setq mxd (apply 'max lxd)) (setq myd (apply 'max lyd)) (setq ps (list mxs mys)) (setq pd (list mxd myd)) (setq i (1+ i)) ) ;_ end of repeat (command "rectangle" ps pd) (princ) ) ;_ end of defun Quote
MSasu Posted May 24, 2012 Posted May 24, 2012 You can increase the speed by doing the sorting once instead of doing it for each item: ... (setq lxd (cons xd lxd)) (setq lyd (cons yd lyd)) (setq i (1+ i)) ) ;_ end of repeat [color=blue] (setq mxs (apply 'min lxs))[/color] [color=blue] (setq mys (apply 'min lys))[/color] [color=blue] (setq mxd (apply 'max lxd))[/color] [color=blue] (setq myd (apply 'max lyd))[/color] [color=blue] (setq ps (list mxs mys))[/color] [color=blue] (setq pd (list mxd myd))[/color] (command "rectangle" ps pd) (princ) ) ;_ end of defun Reply Reply With Quote Quote
pBe Posted May 24, 2012 Posted May 24, 2012 Inside repeat (defun c:demo ( / ss mn mx e _lowY) (if (setq ss (ssget )) (progn (repeat (sslength ss) (cond ((and (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list (vlax-ename->vla-object (setq e (ssname ss 0))) 'mn 'mx)))) (setq mn (vlax-safearray->list mn)) (setq _lowY (if (or (null _lowY) (< (cadr mn )(Cadar _lowY))) (list mn e) _lowY)) ) ) ) (ssdel e ss) )(sssetfirst nil (ssadd (cadr _lowY))) ) ) (princ) ) But thats just me 1 Quote
pBe Posted May 24, 2012 Posted May 24, 2012 Nice, Pbe Thank you brams, The code doesnt really makes any sense, espeially if prompted to select objects, as you can actually see the object with the lowest Y, So tell us, what would be main function of the rouitne? surely there's more to it than that? Quote
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.