M76 Posted January 4, 2010 Share Posted January 4, 2010 Hi I'm trying to select objects inside polygons. The problem is, that if I use WP then it won't select the objects that touch the exterior of the polygon, but if I use CP it also selects the objects that touch it from the outside. Is there any solution for this or do I have to loop through all the objects to check if they 're really inside the polygon? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 4, 2010 Share Posted January 4, 2010 I suppose the question that you have got to ask yourself is what is the definition of an object being on the inside/outside of the polygon. What percentage of the object must be inside the polygon for it to be declared as inside? You see what I'm getting at? Quote Link to comment Share on other sites More sharing options...
M76 Posted January 4, 2010 Author Share Posted January 4, 2010 What percentage? 100% Autocad doesn't select objects that touch the boundary of the polygon. I need to select these objects too. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 4, 2010 Share Posted January 4, 2010 What percentage? 100% Autocad doesn't select objects that touch the boundary of the polygon. I need to select these objects too. I see, so those objects that do not overlap at all, but just touch the boundary at a single point. Quote Link to comment Share on other sites More sharing options...
wizman Posted January 4, 2010 Share Posted January 4, 2010 Please try: ;; WINDOW POLYGON SELECTION ;; FUZZ = 1e-3 ;; (defun c:WPS (/ pl pts *error* lastent ccolor cplwid flag) ;; ;; (defun *error* (msg) (if (and flag (/= lastent (entlast))) (entdel (entlast)) ) (setvar 'cecolor ccolor) (setvar 'plinewid cplwid) (setvar 'cmdecho 1) ) ;; ;; (vl-load-com) ;; (setq lastent (entlast) ccolor (getvar 'cecolor) cplwid (getvar 'plinewid)) (setvar 'cmdecho 0) (setvar 'cecolor "210") (setvar 'plinewid (/ (getvar 'ViewSize) 300.0)) (prompt ">>>...Create Window Polygon...>>>: ") (command ".pline") (while (= (logand (getvar "cmdactive") 1) 1) (command pause) (setq flag T) ) (setq flag nil) (setq pl (vlax-ename->vla-object (entlast))) (vla-put-Closed pl :vlax-true) ;; ;;by gile (defun clockwise-p (p1 p2 p3) (< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14) ) ;; ;; (defun groupby2 (lst / grp) (while (< 1 (length lst)) (Setq grp (cons (list (car lst) (cadr lst) ) grp ) ) (setq lst (cddr lst)) ) (vl-remove 'nil (reverse (cons lst grp))) ) ;; ;; (setq pts (groupby2 (vlax-get pl 'Coordinates))) (vla-offset pl (if (clockwise-p (car pts) (cadr pts) (caddr pts)) -1e-3 1e-3 ) ) (vla-delete pl) (setq pl (vlax-ename->vla-object (entlast))) (setq pts (groupby2 (vlax-get pl 'Coordinates))) (vla-delete pl) (sssetfirst nil (ssget "wp" pts)) (*error* nil) (princ) ) ;; ;;WIZ_05JAN10 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 4, 2010 Share Posted January 4, 2010 Nice method Wiz - I like it! I love this from Gile ;;by gile (defun clockwise-p (p1 p2 p3) (< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14) Not sure how he thinks up these things Quote Link to comment Share on other sites More sharing options...
wizman Posted January 5, 2010 Share Posted January 5, 2010 Nice method Wiz - I like it! Thanks Lee. Not sure how he thinks up these things Incredibly genius he is. Quote Link to comment Share on other sites More sharing options...
M76 Posted January 5, 2010 Author Share Posted January 5, 2010 Thanks I guess I can work with that, if I can understand the way it works. Quote Link to comment Share on other sites More sharing options...
wizman Posted January 5, 2010 Share Posted January 5, 2010 M76, I just updated above code. Quote Link to comment Share on other sites More sharing options...
M76 Posted January 5, 2010 Author Share Posted January 5, 2010 M76, I just updated above code. I've already implemented it thanks. No need for the changes, I don't use it manually. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2010 Share Posted January 5, 2010 Learning from the genius of Evgeniy, an alternative Selection Method: (defun Get_Closed_Poly (/ pt Lst gr) ;; Method by ElpanovEvgeniy, Modified by Lee Mac (vl-load-com) (if (setq pt (getpoint "\nSelect First Point: ")) (progn (setq Lst (list pt)) (princ "\nSelect Point : ") (while (setq pt (progn (while (eq 5 (car (setq gr (grread 't 5 0)))) (redraw) (mapcar (function (lambda (from to) (grdraw from to 3 1))) (cons (cadr gr) Lst) (append Lst (cdr gr)))) (if (listp (cadr gr)) (cadr gr)))) (setq Lst (cons pt Lst))) (redraw) (reverse Lst)))) (defun c:test (/ lst poly) (if (setq lst (Get_Closed_Poly)) (vla-put-Closed (setq poly (vla-AddLightWeightPolyline (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-Acad-Object))) (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble (cons 0 (1- (* 2 (length lst))))) (apply (function append) (mapcar (function (lambda (x) (list (car x) (cadr x)))) lst)))))) :vlax-true)) (princ)) Quote Link to comment Share on other sites More sharing options...
wizman Posted January 6, 2010 Share Posted January 6, 2010 Good One Lee, thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 6, 2010 Share Posted January 6, 2010 Thanks Wiz Quote Link to comment Share on other sites More sharing options...
ewan_m Posted May 4, 2010 Share Posted May 4, 2010 Hi Guys, I have a requirement that I think this structure is best suited to. I just can't seem to make it work. What I need to be able to select an existing polygon (with potentially thousands of points) and remove all lines and polylines that are contained within it and trim all lines and polylines on the inner side of the boundary only from a specified layer. Does anyone have any suggestions? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 4, 2010 Share Posted May 4, 2010 Does Extrim help? Perhaps lock those layers that you don't want trimmed? Quote Link to comment Share on other sites More sharing options...
ewan_m Posted May 4, 2010 Share Posted May 4, 2010 extrim wasn't getting rid of lines wholly inside the polygon Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 4, 2010 Share Posted May 4, 2010 Perhaps you'll have to finish the job manually Or see here. Quote Link to comment Share on other sites More sharing options...
ewan_m Posted May 4, 2010 Share Posted May 4, 2010 Perhaps you'll have to finish the job manually Or see here. Hahah, Yes that is a possibility, but for 50,000 water areas across the country and thousands of objects in each I was hoping for something a bit more automated I'll check out the other forum soon, thanks for your help though. Quote Link to comment Share on other sites More sharing options...
GD.Ritter Posted June 6, 2022 Share Posted June 6, 2022 Does anyone know how to modify this to let you select an existing closed polyline in the drawing to use instead of prompting the user to draw it? Would save me a mountain of time on a project I'm working on. I'm sorry I don't know LISP at all and trying to decipher how this works is daunting. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 6, 2022 Share Posted June 6, 2022 You need to explain more what it is you want this post is about getting objects inside a pline. Is that what you want ? Post a dwg or image about what you want. 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.