Jump to content

Select everything within or crossing a polyline


Recommended Posts

Posted

I know this topic has been covered a thousand times but I am unable to find an answer that suits my needs. I want to be able to select all circles and polylines that are within and crossing another polyline. The closest I have found is this LISP from alanjt:

 

(defun c:SWP (/ _pac add ss i e temp it o a b pts tempC i3 ec)
 ;; Select Within/Crossing Curve

 (vl-load-com)

 (defun _pac (e / l v d lst)
   (setq d (- (setq v (/ (setq l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))) 100.))))
   (while (< (setq d (+ d v)) l)
     (setq lst (cons (vlax-curve-getPointAtDist e d) lst))
   )
 )

 (initget 0 "Crossing Within")
 (setq *SWP:Opt*
        (cond ((getkword (strcat "\nSpecify selection method witin curve [Crossing/Within] <"
                                 (cond (*SWP:Opt*)
                                       ((setq *SWP:Opt* "Crossing"))
                                 )
                                 ">: "
                         )
               )
              )
              (*SWP:Opt*)
        )
 )

 (princ "\nSelect closed curves to select object(s) within: ")
 (if (setq add (ssadd)
           ss  (ssget '((-4 . "<OR")
                        (0 . "CIRCLE,ELLIPSE")
                        (-4 . "<AND")
                        (0 . "*POLYLINE")
                        (-4 . "&=")
                        (70 . 1)
                        (-4 . "AND>")
                        (-4 . "OR>")
                       )
               )
     )
   (progn (repeat (setq i (sslength ss))
            (if (setq temp (ssget "_WP" (_pac (setq e (ssname ss (setq i (1- i)))))))
              (repeat (setq i2 (sslength temp)) (ssadd (ssname temp (setq i2 (1- i2))) add))
            )

            (if (eq *SWP:Opt* "Crossing")
              (progn (vla-getboundingbox (setq o (vlax-ename->vla-object e)) 'a 'b)
                     (setq pts (mapcar 'vlax-safearray->list (list a b)))
                     (if (setq tempC (ssget "_C"
                                            (list (caar pts) (cadar pts) 0.)
                                            (list (caadr pts) (cadadr pts) 0.)
                                     )
                         )
                       (repeat (setq i3 (sslength tempC))
                         (if (vlax-invoke
                               o
                               'Intersectwith
                               (vlax-ename->vla-object (setq ec (ssname tempC (setq i3 (1- i3)))))
                               acExtendNone
                             )
                           (ssadd ec add)
                         )
                       )
                     )
              )
            )
          )
          (sssetfirst nil add)
          (ssget "_I")
   )
 )
 (princ)
)

If I select Crossing and then select my polyline it selects all the circles that are within and crossing but it only selects polylines that are within. Please could anyone help?

 

Thanks in advance!

 

Posted

This worked perfectly on my system (2012) when I tested it. Can you post a sample drawing (AutoCAD 2010 or earlier) of a situation where it is not working. This may be something simple

 

Posted

Hi dlanorh

Sample dataset attached. I work in Map3d 2020 but I have saved it as 2010 for you.

Sample.dwg

Posted

OK, I think this is down to the crossing polylines having an elevation. Will see if it possible to sort it out.

Posted

Ahh, yes I bet it is due to that. I would really appreciate it if you could.

Many thanks

Posted

I've butchered it to work with lwpolylines with elevations only. It now seems to work as required. The problem was the polylines with elevation were not being picked up by the 'intersectwith.

 

(defun c:SWP (/ _pac add ss i e temp it o a b pts tempC i3 ec tobj t_obj)
 ;; Select Within/Crossing Curve

 (vl-load-com)

 (defun _pac (e / l v d lst)
   (setq d (- (setq v (/ (setq l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))) 100.))))
   (while (< (setq d (+ d v)) l)
     (setq lst (cons (vlax-curve-getPointAtDist e d) lst))
   )
 )

 (initget 0 "Crossing Within")
 (setq *SWP:Opt*
        (cond ((getkword (strcat "\nSpecify selection method witin curve [Crossing/Within] <"
                                 (cond (*SWP:Opt*)
                                       ((setq *SWP:Opt* "Crossing"))
                                 )
                                 ">: "
                         )
               )
              )
              (*SWP:Opt*)
        )
 )

 (princ "\nSelect closed curves to select object(s) within: ")
 (if (setq add (ssadd)
           ss  (ssget '((-4 . "<OR")
                        (0 . "CIRCLE,ELLIPSE")
                        (-4 . "<AND")
                        (0 . "*POLYLINE")
                        (-4 . "<OR")
                        (-4 . "&=")
                        (70 . 1)
                        (-4 . "&=")
                        (70 . 0)
                        (-4 . "OR>")
                        (-4 . "AND>")
                        (-4 . "OR>")
                       )
               )
     )
   (progn (repeat (setq i (sslength ss))
            (if (setq temp (ssget "_WP" (_pac (setq e (ssname ss (setq i (1- i)))))))
              (repeat (setq i2 (sslength temp)) (ssadd (ssname temp (setq i2 (1- i2))) add))
            )

            (if (eq *SWP:Opt* "Crossing")
              (progn (vla-getboundingbox (setq o (vlax-ename->vla-object e)) 'a 'b)
                     (setq pts (mapcar 'vlax-safearray->list (list a b)))
                     (if (setq tempC (ssget "_C"
                                            (list (caar pts) (cadar pts) 0.)
                                            (list (caadr pts) (cadadr pts) 0.)
                                     )
                         )
                       (repeat (setq i3 (sslength tempC))
                         (setq ec (ssname tempC (setq i3 (1- i3))) tobj nil)
                         (cond ( (= (cdr (assoc 0 (entget ec))) "LWPOLYLINE")
                                 (vlax-put (setq tobj (vla-copy (vlax-ename->vla-object ec))) 'elevation 0.0)
                                 (setq t_obj tobj)
                               )
                               (t (setq t_obj (vlax-ename->vla-object ec)))
                         )
                         (if (vlax-invoke o 'Intersectwith t_obj acExtendNone) (ssadd ec add));end_if
                         (if tobj (vla-delete tobj))
                       )
                     )
              )
            )
          )
          (sssetfirst nil add)
          (ssget "_I")
   )
 )
 (princ)
)

 

Posted

Sir, you are a genius! Works perfectly!! Many thanks

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