Erase objects crossing or within multiple boundaries

Erase objects crossing or within multiple boundaries

Anonymous
Not applicable
3,105 Views
12 Replies
Message 1 of 13

Erase objects crossing or within multiple boundaries

Anonymous
Not applicable

Hi Everyone,

             I have been searching forever to find a solution. The closest routine I came across is CookieCutter2 v1.2.lsp. What I am trying to do is have a user select more than 1 polyline (polygon), to use for the CP, to erase all objects crossing or within them. CookieCutter is used to trim and delete, which i can work with, but unfortunately it is limited to only 1 CP selection set.

 

Please let me know i fyou need any more details or examples to save me from this road block.

 

Thank you!

0 Likes
Accepted solutions (2)
3,106 Views
12 Replies
Replies (12)
Message 2 of 13

hmsilva
Mentor
Mentor

@Anonymous wrote:

Hi Everyone,

             I have been searching forever to find a solution. The closest routine I came across is CookieCutter2 v1.2.lsp. What I am trying to do is have a user select more than 1 polyline (polygon), to use for the CP, to erase all objects crossing or within them. CookieCutter is used to trim and delete, which i can work with, but unfortunately it is limited to only 1 CP selection set.

 

Please let me know i fyou need any more details or examples to save me from this road block.

 

Thank you!


Hello RClough0212 and welcome to the Autodesk Community!

Quick and dirty, but it should do the trick...

 

(vl-load-com)
(defun c:demo (/ get_lst hnd i obj pts ss ss1)

   ;; Lwpolyline point list with fuzz in curve
   ;; obj - a vlaObject
   ;; fuzz - a real number
   (defun get_lst (obj fuzz / B D I LST PAR)
      (setq par 0)
      (while (< par (vlax-curve-getEndParam obj))
         (if (/= (vla-getbulge obj par) 0)
            (progn
               (setq d (- (vlax-curve-getDistAtParam obj (1+ par))
                          (setq b (vlax-curve-getDistAtParam obj par))
                       )
                     i (1+ (fix (/ d fuzz)))
                     d (/ d i)
               )
               (repeat i
                  (setq lst (cons (trans (vlax-curve-getPointAtDist obj b) 0 1) lst)
                        b   (+ b d)
                  )
               )
               (setq par (1+ par))
            )
            (setq lst (cons (trans (vlax-curve-getPointAtParam obj par) 0 1) lst)
                  par (1+ par)
            )
         )
      )
      lst
   )

   (command "_.undo" "_G")
   (if (setq ss (ssget '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))
      (repeat (setq i (sslength ss))
         (setq hnd (ssname ss (setq i (1- i)))
               obj (vlax-ename->vla-object hnd)
               pts (get_lst obj 0.01)
         )
         (command "_.zoom" "_O" hnd "")
         (if (setq ss1 (ssget "_CP" pts))
            (command "_.erase" ss1 "_R" hnd "")
         )
         (command "_.zoom" "_P")
      )
   )
   (command "_.undo" "_E")
   (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 3 of 13

Anonymous
Not applicable

Thank you Henrique. Glad to be apart of the community. I just tried to load the .lsp and received ; error: malformed list on input. This prevented me testing it out. I forgot to note that i am using AutoCAD 2012.

0 Likes
Message 4 of 13

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Thank you Henrique. Glad to be apart of the community. I just tried to load the .lsp and received ; error: malformed list on input. This prevented me testing it out. I forgot to note that i am using AutoCAD 2012.


The error msg, probably It refers to a missing parenthesis...

Try the attached demo..

 

Henrique

EESignature

0 Likes
Message 5 of 13

Anonymous
Not applicable

This is awesome! I am so releived to finally have a solution. What would make this perfect for my daily use it to have it recognize polylines and circles as the CP as well and to allow the user to either select all CP objects prior to the command and/or allow some sort of select similar or even by layer. I dont want to kick a gift horse though because this is most certainly a leg up to how I am currently operating.

 

Thank you both VERY much!

0 Likes
Message 6 of 13

hmsilva
Mentor
Mentor

@Anonymous wrote:

This is awesome! I am so releived to finally have a solution. What would make this perfect for my daily use it to have it recognize polylines and circles as the CP as well and to allow the user to either select all CP objects prior to the command and/or allow some sort of select similar or even by layer. I dont want to kick a gift horse though because this is most certainly a leg up to how I am currently operating.

 

Thank you both VERY much!


You're welcome, RClough0212
Glad I could help!

 

Attached a modified 'demo', please have in mind, if the 'curve accuracy' distance is set to a very small distance, and the circle objects have a very big perimeter, the code will be extremely slow...


Hope this helps,
Henrique

EESignature

0 Likes
Message 7 of 13

Anonymous
Not applicable

Henrique, you are kicking butt! This worked like a charm. I have 1 final question. I tried using a single polyline with 2 verticies and it did not erase. i even tried changing it to closed in the properties menu. is there something i may be doing wrong?

0 Likes
Message 8 of 13

hmsilva
Mentor
Mentor

@Anonymous wrote:

... I tried using a single polyline with 2 verticies and it did not erase. i even tried changing it to closed in the properties menu. is there something i may be doing wrong?


RClough0212,

to define a boundary with a lwpolyline with 2 vertices, at least one of the segments must be an arc, and if the lwpolyline is closed, it should work as expected.

Post a sample dwg (r10, in this old laptop, I have an old AutoCAD...) if possible.

 

Henrique

EESignature

0 Likes
Message 9 of 13

Anonymous
Not applicable

Here is a .dwg file that contains a starting point for a typical user, the current outcome of the routine and the desire results. Notice that the only portion that didnt match up to the desire outcome is the vertical pline running through the center.

0 Likes
Message 10 of 13

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Here is a .dwg file that contains a starting point for a typical user, the current outcome of the routine and the desire results. Notice that the only portion that didnt match up to the desire outcome is the vertical pline running through the center.


Revised to use opened lwpolylines...

 

Hope this helps,
Henrique

EESignature

Message 11 of 13

Anonymous
Not applicable

That did it! Thank you so much for all of you help over the past few days. Great work!!

0 Likes
Message 12 of 13

hmsilva
Mentor
Mentor

@Anonymous wrote:

That did it! Thank you so much for all of you help over the past few days. Great work!!


You're welcome, RClough0212
Glad I could help

Henrique

EESignature

0 Likes
Message 13 of 13

Anonymous
Not applicable

Hi Henrique

First of, I hope you and yours are taking care of yourself and everyone is safe.

I am replying to a 2016 message here and I hope you're still in this forum.

I work with complex layouts with thousands of plines crossing each others and I have doing the cleanup by hand for a while until just recently found your demo2.lsp which has make my life very much easier dealing with my tasks.

By quoting one of the sentences en your comment I would like to ask you whether you have been able to fix that problem and quote "Notice that the only portion that didnt match up to the desire outcome is the vertical pline running through the center".

I also notice the same issue when trying to remove plines which are aligned vertically. Is there a new version with correction for that glitch??

Please let me know whether you'd like to see what my layouts look like.

Thanks in advance

Alberto

0 Likes