Jump to content

Select inside polygon


M76

Recommended Posts

8 hours ago, GD.Ritter said:

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.y

 

This builds off Lee Mac lisp.

1. Allows you to keep building the selection.

2. gives you a warning if things cross over the polyline and how many.

 

 

;;----------------------------------------------------------------------------;;
;; Select Objects Inside Entity
(defun C:SI (/ ent i j l SS SS1 SS2 SS3 plist)
  (vl-load-com)
  (if (ssget "_I")          ; if there are preselected objects [= Implied selection]
    (sssetfirst nil (setq SS (ssget "_I")))
  )
  (if (setq ent (car (entsel "\nSelect Polyline To Select Objects Inside ")))
    (progn
      (SELECTINSIDE ent 100)
      (if (> (- (sslength SS2) 1) (sslength SS1))
        (progn
          (setq n (- (- (sslength SS2) 1) (sslength SS1)))
          (alert (strcat "\n" (itoa n) " Entitys Crossing Selection Area"))
          (if SS
            (vl-cmdf "_.Select" SS SS2 "")
            (vl-cmdf "_.Select" SS2 "")
          )

        )
        (if SS
          (vl-cmdf "_.Select" SS SS1 ent "")
          (vl-cmdf "_.Select" SS1 ent "")
        )
      )
      (setq SS3 (ssget "_P"))
      (sssetfirst nil SS3)
    )
  )
  (princ)
)
;;----------------------------------------------------------------------------;;
;; ssget "WP" doesn't work well with arc this fixes it
;; https://www.cadtutor.net/forum/topic/42900-select-within-a-polyline-containing-arcs-and-splines/#comment-350171
(defun SELECTINSIDE (ent acc / i j l)
  (setq i (/ (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)) acc)
        j (- i)
  )
  (repeat (fix acc)
    (setq l (cons (trans (vlax-curve-getpointatdist ent (setq j (+ j i))) 0 1) l))
  )
  (setq SS1 (ssget "_WP" l))
  (setq SS2 (ssget "_CP" l))
)

 

Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

  • GD.Ritter

    8

  • Lee Mac

    7

  • wizman

    4

  • M76

    4

Top Posters In This Topic

Posted Images

On 6/6/2022 at 7:26 PM, BIGAL said:

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.

So imagine a drawing with a ton of topo lines for example. If I have a closed polyline representing a property, i would want it to select everything within or crossing that polyline regardless of z elevation. The Lisp above lets you freehand draw a polyline to select within it, I want to just click the existing polyline i have.

 

Link to comment
Share on other sites

On 6/6/2022 at 9:18 PM, mhupp said:

 

This builds off Lee Mac lisp.

1. Allows you to keep building the selection.

2. gives you a warning if things cross over the polyline and how many.

 

 

;;----------------------------------------------------------------------------;;
;; Select Objects Inside Entity
(defun C:SI (/ ent i j l SS SS1 SS2 SS3 plist)
  (vl-load-com)
  (if (ssget "_I")          ; if there are preselected objects [= Implied selection]
    (sssetfirst nil (setq SS (ssget "_I")))
  )
  (if (setq ent (car (entsel "\nSelect Polyline To Select Objects Inside ")))
    (progn
      (SELECTINSIDE ent 100)
      (if (> (- (sslength SS2) 1) (sslength SS1))
        (progn
          (setq n (- (- (sslength SS2) 1) (sslength SS1)))
          (alert (strcat "\n" (itoa n) " Entitys Crossing Selection Area"))
          (if SS
            (vl-cmdf "_.Select" SS SS2 "")
            (vl-cmdf "_.Select" SS2 "")
          )

        )
        (if SS
          (vl-cmdf "_.Select" SS SS1 ent "")
          (vl-cmdf "_.Select" SS1 ent "")
        )
      )
      (setq SS3 (ssget "_P"))
      (sssetfirst nil SS3)
    )
  )
  (princ)
)
;;----------------------------------------------------------------------------;;
;; ssget "WP" doesn't work well with arc this fixes it
;; https://www.cadtutor.net/forum/topic/42900-select-within-a-polyline-containing-arcs-and-splines/#comment-350171
(defun SELECTINSIDE (ent acc / i j l)
  (setq i (/ (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)) acc)
        j (- i)
  )
  (repeat (fix acc)
    (setq l (cons (trans (vlax-curve-getpointatdist ent (setq j (+ j i))) 0 1) l))
  )
  (setq SS1 (ssget "_WP" l))
  (setq SS2 (ssget "_CP" l))
)

 

 

this comes very close. the only thing it seems to miss is if there are radius fillets in the polyline, it misses items that are within that arc. For example, see the chosen polyline in yellow and items missed pointed out in pink.

Screenshot 2022-06-22 145837.png

Link to comment
Share on other sites

Lee Mac messaged me this example which also misses items within a radius fillet. But getting this far still saves me a lot of time on this big topography project I'm working on.

 

(defun c:test ( / ent sel )
    (while
        (progn
            (setvar 'errno 0)
            (setq ent (car (entsel "\nSelect polyline: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent)
                    nil
                )
                (   (/= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
                    (princ "\nThe selected objects is not a 2D polyline.")
                )
            )
        )
    )
    (if (and ent (setq sel (ssget "_CP" (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent))))))
        (progn
            (ssdel ent sel)
            (sssetfirst nil sel)
        )
    )
    (princ)
)

 

Link to comment
Share on other sites

1 hour ago, GD.Ritter said:

 

this comes very close. the only thing it seems to miss is if there are radius fillets in the polyline, it misses items that are within that arc. For example, see the chosen polyline in yellow and items missed pointed out in pink.

 

My lisp take that issue into account. Your pointing to the gray items? are they part of a block or xref?

I would have to see the file to tell you exactly why they aren't being selected but it works with arcs.

see example The red dash line is what the cords of the polyline.

Link to comment
Share on other sites

22 minutes ago, mhupp said:

 

My lisp take that issue into account. Your pointing to the gray items? are they part of a block or xref?

I would have to see the file to tell you exactly why they aren't being selected but it works with arcs.

see example The red dash line is what the cords of the polyline.

 

They are not a block or xref, it's just not selecting them. Example file available here https://1drv.ms/u/s!AklbmHoHc-lgvf4QZgr0pZh9RPvMIQ?e=ipFQdv

 

Link to comment
Share on other sites

there are three problems.

1. for things to be selected with ssget "wp" and "cp" it needs to be on screen. So you have to zoom to object (yellow polyline) to make sure everything inside will be selected.

2. what (SELECTINSIDE ent 100) essentially does is splits up a polyline into 100 smaller sections. and since the polyline your running it on has 743 vertices already its making it less accurate rather then more. update (SELECTINSIDE ent 2000)

3. ssget has a limit on how many points can be inputted. and how many selected entity's can be listed.

 

That still doesn't fix the problem. when i ran the updated code i got over 35k+ entity's in the selection set. I moved them to another location outside the polyline and ran it again. and got the rest of the items inside.

 

Seems their is only 6 entity's not inside that polyline.

 

tldr

update code to (SELECTINSIDE ent 2000)

make your perimeter polyline smaller,   or move the items selected entity's to another location outside the perimeter and run a second or even third time.

 

 

Link to comment
Share on other sites

GD.Ritter is the task to get a long section or cross sections based on your pline ? If so better answers are already out there. They do not use contours but rather the TIN model that made the contours.

 

Ps Long and cross sections takes about  1-2 minutes to create. 

Link to comment
Share on other sites

4 hours ago, BIGAL said:

GD.Ritter is the task to get a long section or cross sections based on your pline ? If so better answers are already out there. They do not use contours but rather the TIN model that made the contours.

 

Ps Long and cross sections takes about  1-2 minutes to create. 

 

This is LIDAR data downloaded for the entire state that I'm slicing up to separate out by city. I'm using EXTRIM to trim all the crossing contours and then afterwards I need to go around and delete all the topo exterior to the city I'm working on. So I'm just looking for ways to speed the process up. It's pretty slow going right now.

Link to comment
Share on other sites

I worked for a local Authority so had access to the lidar models. We would export out 3dfaces for the area we wanted not entire model its in the Tb size.

 

Can you not get small areas so the extrim will work ?

 

Try Cookiecutter.lspCookieCutter2_v1.0.lsp it can be better than extrim at times.

Link to comment
Share on other sites

19 hours ago, BIGAL said:

I worked for a local Authority so had access to the lidar models. We would export out 3dfaces for the area we wanted not entire model its in the Tb size.

 

Can you not get small areas so the extrim will work ?

 

Try Cookiecutter.lspCookieCutter2_v1.0.lsp it can be better than extrim at times.

The cookiecutter2 v1.0 lsp you recommended doesn't seem to do anything. If I select to delete objects outside the polyline it deletes everything on screen except the polyline. If i say don't delete it doesn't appear to affect any objects at all.

Link to comment
Share on other sites

So this made me re-work the selectinside function. rather then dividing the whole polyline into smaller segments of equal length. This function will looks at the polyline segments and only adds points to the arc's cutting down on the total number of points.

 

need to think about this line a bit more

(setq seg (/ (vla-get-arclength obj) 5))

to be a little more dynamic like more segments to scale up with larger radius/arc length.

 

;;----------------------------------------------------------------------------;;
;; ssget "WP" doesn't work well with arc this fixes it
(defun SELECTINSIDE (ent / poly obj len lst)
  (setq poly (vlax-invoke (vlax-ename->vla-object ent) 'explode))
  (foreach obj poly
    (cond
      ((eq (vla-get-Objectname obj) "AcDbArc")
        (setq lst (cons (vlax-curve-getPointAtDist obj 0) lst))
        (if (< (vla-get-radius obj) 0.124)
          (progn
            (setq seg (/ (vla-get-arclength obj) 5)) 
            (setq len seg)
            (repeat 4
              (setq lst (cons (vlax-curve-getPointAtDist obj len) lst))
              (setq len (+ len seg))
            )
          )
        )
        (vla-delete obj)
      )
      ((eq (vla-get-Objectname obj) "AcDbLine")
        (setq lst (cons (vlax-get obj 'StartPoint) lst))
        (vla-delete obj)
      )
    )
  )
  (setq SS1 (ssget "_WP" lst))
  (setq SS2 (ssget "_CP" lst))
)

 

Edited by mhupp
Link to comment
Share on other sites

On 6/25/2022 at 1:29 AM, BIGAL said:

Was the pline closed it needs to be to work can not be like just delete everything to left.

yes, closed polyline. just like in the example i shared before.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.


×
×
  • Create New...