Jump to content

Select inside polygon


M76
 Share

Recommended Posts

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?

Link to comment
Share on other sites

  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

  • wizman

    4

  • Lee Mac

    7

  • M76

    4

  • GD.Ritter

    8

Top Posters In This Topic

Posted Images

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?

Link to comment
Share on other sites

What percentage? 100%

 

Autocad doesn't select objects that touch the boundary of the polygon. I need to select these objects too.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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))
               
             

     
           

Link to comment
Share on other sites

  • 3 months later...

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?

Link to comment
Share on other sites

Perhaps you'll have to finish the job manually o:)

 

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 :P

 

I'll check out the other forum soon, thanks for your help though.

Link to comment
Share on other sites

  • 12 years later...

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share


×
×
  • Create New...