Jump to content

Delete objects that intersect a polyline


MastroLube

Recommended Posts

Hello guys, I've already asked that.. but I?m not able to find the post (maybe it has been deleted?)

Anyway Mr. Mac Lee answerd me that there are 2 methods.

1) slow, it interrogates every object and find if it intersect the plyne

2) fast, something using the Zoom

 

I've compiled the first one, but its very slow if i have a lot of ojects.

 

Can someone remind me about the second method? Thanks guys

 

The old code

(DEFUN cancella_cerchi (/)
 (SETQ 
    	i 0
       deleted (LIST)
       lista_polilinee (LIST)
 )
 (sel_polylines "Bordi")

 
 (REPEAT (LENGTH lista_polilinee)
   (setq n 0
         p_linea (NTH i lista_polilinee))
   (REPEAT (LENGTH lista_cerchi)
     (SETQ cerchio_obj (VLAX-ENAME->VLA-OBJECT (NTH n lista_cerchi)))
     (IF
       (/= (VLAX-INVOKE p_linea 'intersectwith cerchio_obj ACEXTENDNONE) nil)
        (PROGN (ENTDEL (NTH n lista_cerchi))
               (SETQ deleted (APPEND deleted (LIST (NTH n lista_cerchi))))
        )
     )
     (SETQ n (1+ n))
   )
   (SETQ del 0)
   (REPEAT (LENGTH deleted)
     (SETQ lista_cerchi (VL-REMOVE (NTH del deleted) lista_cerchi))
     (SETQ del (1+ del))
   )
   (SETQ i (1+ i))
   (entdel (VLAX-VLA-OBJECT->ENAME p_linea))
 )
 ;(prompt (length lista_cerchi))
)

 

EDIT:

 

Two methods spring to mind:

 

1) Slow but more robust:

Iterate over the set of all circles created.

Delete circles for which (vlax-invoke 'intersectwith acextendnone) is non-nil for any one polyline.

 

2) Quicker but less reliable:

Zoom to extents of polyline.

Obtain a Fence selection of circles using the polyline vertices for each polyline (ssget "_F" '((0 . "CIRCLE"))) [reference here].

Erase all entities in the selection.

Edited by MastroLube
FIND IT! But need some help anyway
Link to comment
Share on other sites

Can someone remind me about the second method? Thanks guys

 

Just an example .

 

(setq s (car (entsel "\nSelect Polyline :")))
(vla-getboundingbox (vlax-ename->vla-object s) 'j 'k)
(vla-ZoomWindow (vlax-get-acad-object) j k)

Link to comment
Share on other sites

Thanks, I've a little question about that.

Look at this short video: http://autode.sk/1My5bQW

When I created the hatch I save the polyline of the boundary, and I delete the object using the first metod.. The boundary isn't a perfect square..

The code you posted seems to work properly if the boundary is a rectangle.. Correct? Maybe I'm wrong, please let me know :)

Thanks, Dennis

Link to comment
Share on other sites

See the methods suggested in this thread: http://www.theswamp.org/index.php?topic=50190.0

 

Thanks Lee, it was hard to find it :) too many forums eheh

 

I'll try to post there the solution!

Thanks :)

 

EDIT: Solution

 

well, this is the solution!

 

(defun cdrs (key lst / pair rtn)
(while (setq pair (assoc key lst))
(setq rtn (cons (cdr pair) rtn)
lst (cdr (member pair lst))
)
)
(reverse rtn)
)

(setq vertici_pl (cdrs 10 (entget (car (entsel "\nSelect a polyline")))))
(defun c:cancella_cerchi_interni ( / e i n s x )
   (if (setq s (ssget "_CP" vertici_pl  '((0 . "CIRCLE"))))
       (progn
           (setq i 0
                 n (sslength s)
           )
           (repeat n
               (setq e (ssname s i)
                     ;x (cdr (assoc 0 (entget e)))
                     i (1+ i)
               )
               (entdel e)
           )
       )
   )
   (princ)
)

(defun c:cancella_cerchi_lungo_linea ( / e i n s x )
   (if (setq s (ssget "_F" (append vertici_pl (list (car vertici_pl)))  '((0 . "CIRCLE"))))
       (progn
           (setq i 0
                 n (sslength s)
           )
           (repeat n
               (setq e (ssname s i)
                     ;x (cdr (assoc 0 (entget e)))
                     i (1+ i)
               )
               (entdel e)
           )
       )
   )
   (princ)
)

1) delete only objects crossing a selection fence

2) delete everything inside and crossing the selection fence

 

:heart:

Edited by MastroLube
Solution!
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...