Author Topic: Select the entities that intersect a polyline  (Read 2794 times)

0 Members and 1 Guest are viewing this topic.

Lube

  • Guest
Select the entities that intersect a polyline
« on: September 30, 2015, 08:43:01 AM »
Hello guys, I've tried do to it by myself but i failed.

I need to understand how to select all the object that intersect a polyline (or more than one) to delete them.
I've a lisp that draws circles inside a polyline.
-> create an hatch
-> explode the hatch
-> put circles in every vertex

The problem is that sometime vertex are bordeline and the circles go a little outside.

There is an exemple of what I get, and what I want to get:
https://www.dropbox.com/s/506xh7ftx5uj8nl/deleteobj.png?dl=0

Thanks, Dennis

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Select the entities that intersect a polyline
« Reply #1 on: September 30, 2015, 09:11:30 AM »
Two methods spring to mind:

1) Slow but more robust:
  • Iterate over the set of all circles created.
  • Delete circles for which (vlax-invoke <polyline-object> 'intersectwith <circle-object> 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" <UCS-polyline-vertices> '((0 . "CIRCLE"))) [reference here].
  • Erase all entities in the selection.

Lube

  • Guest
Re: Select the entities that intersect a polyline
« Reply #2 on: October 02, 2015, 05:30:57 AM »
Thank you Mister!

Code: [Select]
(defun cancella_cerchi (/)
 (setq n 0)
 (setq p_linea (VLAX-ENAME->VLA-OBJECT (car (entsel))))
(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)
  (entdel (nth n lista_cerchi))
  )
  (setq n (1+ n))
  )
  )
But I have a problem. I need to extract the boundary of the hatch and not to select it manually.
I create my hatch with:
(command "_-bhatch" "_L" "bordo" "_a" "_r" "_y" "_i" "_y" "" "_p" "_u" "0" passo "_y" p "" ) and it can be have more that one polyline.
I really don't know how to do that, any advice?
Thanks!

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Select the entities that intersect a polyline
« Reply #3 on: October 02, 2015, 05:55:51 AM »
The slow way would be to test for an intersection with every surrounding object, erasing as soon as an intersection is found.

However, if the hatch is polygonal (which it looks to be from your example image), the hatch boundary can be quite easily obtained from the hatch DXF data.

Lube

  • Guest
Re: Select the entities that intersect a polyline
« Reply #4 on: October 02, 2015, 07:12:39 AM »
I go with the slow way because I find it more easy, but maybe i'm wrong..

A real exemple of the hatch could be that:
https://www.dropbox.com/s/s28j2ybmunhmib7/Screenshot%202015-10-02%2013.06.46.png?dl=0

Will the dxf code extraction works?

I've to say that the hatch create a polyline because of that: (setvar 'hpbound 1)
i wanted to select it.

Another little ask, there is a way to select element inside an hatch?
(vlax-invoke p_linea 'inside cerchio_obj acextendnone) nil) ?

Thanks

Lube

  • Guest
Re: Select the entities that intersect a polyline
« Reply #5 on: October 02, 2015, 10:24:34 AM »
I did it in this way:

Code: [Select]
...
(_CreateLayer "Bordi" 1 "" 0 0)
    (setq OLD_LAYER (getvar 'clayer))
    (_SetCLayer "Bordi")
    (command "_-bhatch" "_L" "bordo" "_a" "_r" "_y" "_i" "_y" "" "_p" "_u" "0" passo "_y" p "" )
    (_SetCLayer OLD_LAYER)
...
and

Code: [Select]
(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))
  )
 
)

(defun sel_polylines ( layer / ss n )
   (setq ss (ssget "x" (list (cons 0 "LWPOLYLINE") (cons 8 layer)))
         n 0) ;seleziona tutte le polilinee in "bordi"
   (repeat (sslength ss)
     (SETQ lista_polilinee (append lista_polilinee (LIST (VLAX-ENAME->VLA-OBJECT (ssname ss n)))))
     (setq n (1+ n))
     )
)