Author Topic: Delete a line of complete coincidence  (Read 4645 times)

0 Members and 1 Guest are viewing this topic.

mianbaoche

  • Guest
Delete a line of complete coincidence
« on: August 25, 2015, 04:19:34 AM »
Delete a line of complete coincidence,This method is slow!
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt()
  2.   (setq lst (mapcar '(lambda (x)  (list x (cdr (assoc 10 (entget x))) (cdr (assoc 11 (entget x)))))(vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "LINE")))))))
  3.         t1  (getvar "TDUSRTIMER"))
  4.   (item_sort lst)
  5.   (princ (strcat "\n""TIME:" (rtos (* 86400 (- (getvar "TDUSRTIMER") t1)) 2 0)))
  6.   (princ)        
  7.   )
  8.  
  9.  
  10. (defun item_sort ( l / c l r x e  aa ll)
  11.      (while l
  12.        (setq  x (car l)
  13.               e (list x)
  14.               l (cdr l)    
  15.           )    
  16.          (foreach y l
  17.                (if (or
  18.                      (and (equal (distance (cadr y) (cadr x)) 0 1e-6)(equal (distance (caddr y) (caddr x)) 0 1e-6))
  19.                      (and (equal (distance (caddr y) (cadr x)) 0 1e-6)(equal (distance (cadr y) (caddr x)) 0 1e-6))
  20.                      )
  21.                (setq e (cons y e))
  22.                (setq ll (cons y ll))      
  23.                 )
  24.            )
  25.          (if (> (length e) 1) (foreach a e (entdel (car a))))
  26.           (setq  l ll  e nil  ll nil)
  27. ))
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Delete a line of complete coincidence
« Reply #1 on: August 25, 2015, 04:46:50 AM »
If I understood correctly, maybe this :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:remcoincidentlines ( / uniquelilst ss ssl ssrl ssreml )
  2.  
  3.   (defun uniquelilst ( l )
  4.     (if l (cons (car l) (vl-remove-if '(lambda ( x ) (or
  5.                                                        (and (equal (cdr (assoc 10 (entget (car l)))) (cdr (assoc 10 (entget x))) 1e-6) (equal (cdr (assoc 11 (entget (car l)))) (cdr (assoc 11 (entget x))) 1e-6))
  6.                                                        (and (equal (cdr (assoc 10 (entget (car l)))) (cdr (assoc 11 (entget x))) 1e-6) (equal (cdr (assoc 11 (entget (car l)))) (cdr (assoc 10 (entget x))) 1e-6))
  7.                                                      )
  8.                                        ) (uniquelilst (cdr l))
  9.                         )
  10.           )
  11.     )
  12.   )
  13.  
  14.   (setq ss (ssget "_:L" '((0 . "LINE"))))
  15.   (setq ssl (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  16.   (setq ssrl (uniquelilst ssl))
  17.   (setq ssreml (vl-remove-if '(lambda ( x ) (vl-position x ssrl)) ssl))
  18.   (foreach e ssreml
  19.     (entdel e)
  20.   )
  21.   (princ)
  22. )
  23.  

Or a little faster Vlisp variant...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:remcoincidentlines ( / uniquelilst ss ssl ssrl ssreml )
  2.  
  3.  
  4.   (defun uniquelilst ( l )
  5.     (if l (cons (car l) (vl-remove-if '(lambda ( x ) (or
  6.                                                        (and (equal (vlax-curve-getstartpoint (car l)) (vlax-curve-getstartpoint x) 1e-6) (equal (vlax-curve-getendpoint (car l)) (vlax-curve-getendpoint x) 1e-6))
  7.                                                        (and (equal (vlax-curve-getstartpoint (car l)) (vlax-curve-getendpoint x) 1e-6) (equal (vlax-curve-getendpoint (car l)) (vlax-curve-getstartpoint x) 1e-6))
  8.                                                      )
  9.                                        ) (uniquelilst (cdr l))
  10.                         )
  11.           )
  12.     )
  13.   )
  14.  
  15.   (setq ss (ssget "_:L" '((0 . "LINE"))))
  16.   (setq ssl (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  17.   (setq ssrl (uniquelilst ssl))
  18.   (setq ssreml (vl-remove-if '(lambda ( x ) (vl-position x ssrl)) ssl))
  19.   (foreach e ssreml
  20.     (entdel e)
  21.   )
  22.   (princ)
  23. )
  24.  
« Last Edit: August 25, 2015, 07:28:58 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Delete a line of complete coincidence
« Reply #2 on: August 25, 2015, 05:01:08 AM »
Quote
This method is slow
I haven't tested the speed , but say that it takes 3 seconds to run.
Would you consider 1.5 seconds satisfactory ?

Assume the saving can be made ... perhaps it can't ....

Assume you use it every working day for a year, that will be a saving of 5 minutes.
Assume you have 4 people in your office who use it ... that's a saving of 20 minutes.

To be financially viable the changes can't take longer that 20 minutes ... if the routine can be shortened..

The first thing you could do is spend 2 minutes changing the variable names so anyone reading the code knows immediately what each variable represents.

just curious ... why is the routine removing the coincident line and the line overlayed ?


 
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Delete a line of complete coincidence
« Reply #3 on: August 25, 2015, 05:17:24 AM »
This may be marginally quicker:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:linedupes ( / e i l p q r s x )
  2.     (if (setq s (ssget "_:L" '((0 . "LINE"))))
  3.         (progn
  4.             (repeat (setq i (sslength s))
  5.                 (setq e (ssname s (setq i (1- i)))
  6.                       x (entget e)
  7.                       l (cons (list (cdr (assoc 10 x)) (cdr (assoc 11 x)) e) l)
  8.                 )
  9.             )
  10.             (while l
  11.                 (setq p (caar  l)
  12.                       q (cadar l)
  13.                 )
  14.                 (foreach y (cdr l)
  15.                     (if (or (and (equal (car y) p 1e-6) (equal (cadr y) q 1e-6))
  16.                             (and (equal (car y) q 1e-6) (equal (cadr y) p 1e-6))
  17.                         )
  18.                         (entdel (caddr  y))
  19.                         (setq r (cons y r))
  20.                     )
  21.                 )
  22.                 (setq l r r nil)
  23.             )
  24.         )
  25.     )
  26.     (princ)
  27. )

Or perhaps:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:linedupes ( / e i l p q s x )
  2.     (if (setq s (ssget "_:L" '((0 . "LINE"))))
  3.         (progn
  4.             (repeat (setq i (sslength s))
  5.                 (setq e (ssname s (setq i (1- i)))
  6.                       x (entget e)
  7.                       l (cons (list (cdr (assoc 10 x)) (cdr (assoc 11 x)) e) l)
  8.                 )
  9.             )
  10.             (while
  11.                 (setq p (caar  l)
  12.                       q (cadar l)
  13.                       l
  14.                     (vl-remove-if
  15.                        '(lambda ( y )
  16.                             (if (or (and (equal (car y) p 1e-6) (equal (cadr y) q 1e-6))
  17.                                     (and (equal (car y) q 1e-6) (equal (cadr y) p 1e-6))
  18.                                 )
  19.                                 (entdel (caddr y))
  20.                             )
  21.                         )
  22.                         (cdr l)
  23.                     )
  24.                 )
  25.             )
  26.         )
  27.     )
  28.     (princ)
  29. )

(The above is untested)
« Last Edit: August 25, 2015, 06:28:10 AM by Lee Mac »

mianbaoche

  • Guest
Re: Delete a line of complete coincidence
« Reply #4 on: August 25, 2015, 08:35:54 AM »
Thanks for all!I need to learn!

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Delete a line of complete coincidence
« Reply #5 on: August 25, 2015, 10:21:03 AM »
Quote
This method is slow
I haven't tested the speed , but say that it takes 3 seconds to run.
Would you consider 1.5 seconds satisfactory ?

Assume the saving can be made ... perhaps it can't ....

Assume you use it every working day for a year, that will be a saving of 5 minutes.
Assume you have 4 people in your office who use it ... that's a saving of 20 minutes.

To be financially viable the changes can't take longer that 20 minutes ... if the routine can be shortened..

The first thing you could do is spend 2 minutes changing the variable names so anyone reading the code knows immediately what each variable represents.

just curious ... why is the routine removing the coincident line and the line overlayed ?

I approach such evaluations from another perspective: for one person saving 5 minutes over a year, that's in a 50 week x 40 hour/week schedule, or 2000 hours.  Even saving 4 people a cumulative 20 minutes, its negligible.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Delete a line of complete coincidence
« Reply #6 on: August 25, 2015, 10:30:58 AM »
Quote
Even saving 4 people a cumulative 20 minutes, its negligible.

absolutely,
It's the principle I was trying to express ... sometimes the scale is minor but the essence of the evaluation holds.

added:
Just to clarify that:
I've seen people spend a large effort for minimal return ... In fact I've done it myself a couple of times.

Throwing time and money at something because it seems 'too slow' or 'not pretty'  is an easy trap to fall into.


« Last Edit: August 25, 2015, 10:56:11 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

AIberto

  • Guest
Re: Delete a line of complete coincidence
« Reply #7 on: August 25, 2015, 10:34:37 AM »
Quote
This method is slow
I haven't tested the speed , but say that it takes 3 seconds to run.
Would you consider 1.5 seconds satisfactory ?

Assume the saving can be made ... perhaps it can't ....

Assume you use it every working day for a year, that will be a saving of 5 minutes.
Assume you have 4 people in your office who use it ... that's a saving of 20 minutes.

To be financially viable the changes can't take longer that 20 minutes ... if the routine can be shortened..

The first thing you could do is spend 2 minutes changing the variable names so anyone reading the code knows immediately what each variable represents.

just curious ... why is the routine removing the coincident line and the line overlayed ?

I approach such evaluations from another perspective: for one person saving 5 minutes over a year, that's in a 50 week x 40 hour/week schedule, or 2000 hours.  Even saving 4 people a cumulative 20 minutes, its negligible.

Less drink a cup of coffee,  can saving 20 minutes , a man , Less smoke a cigarette, can saving 10 minutes ...

danallen

  • Guest
Re: Delete a line of complete coincidence
« Reply #8 on: August 25, 2015, 12:55:33 PM »
I've seen people spend a large effort for minimal return ... In fact I've done it myself a couple of times.

Is It Worth the Time?
https://xkcd.com/1205/

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Delete a line of complete coincidence
« Reply #9 on: August 25, 2015, 02:32:03 PM »
I've seen people spend a large effort for minimal return ... In fact I've done it myself a couple of times.

Is It Worth the Time?
https://xkcd.com/1205/

It is a valid point, but you also have to factor in how many other people in your company will use it as well?

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Delete a line of complete coincidence
« Reply #10 on: August 25, 2015, 02:40:21 PM »
If I am understanding correctly, wouldn't this work:
Code: [Select]
(defun c:tt (/)
     (command "._-overkill" "All" "" "_O" "0" "_I" "_A" "_P" "_N" "_T" "_N" "_E" "_N" "_A" "Y" "")
)
And it would be by far the fastest method, at least in versions of AutoCAD since Overkill has been a command instead of an express tool. I believe it was around 2012 or so that this became a built-in command.

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Delete a line of complete coincidence
« Reply #11 on: August 25, 2015, 03:21:27 PM »
If I am understanding correctly, wouldn't this work:
Code: [Select]
(defun c:tt (/)
     (command "._-overkill" "All" "" "_O" "0" "_I" "_A" "_P" "_N" "_T" "_N" "_E" "_N" "_A" "Y" "")
)
And it would be by far the fastest method, at least in versions of AutoCAD since Overkill has been a command instead of an express tool. I believe it was around 2012 or so that this became a built-in command.

It would be the fastest way if OP didn't wanted to overkill only coincident lines. So the lisp is more appropriate solution IMHO.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Delete a line of complete coincidence
« Reply #12 on: August 25, 2015, 03:46:14 PM »

Maybe I'm missing something here.  All LINE point values are stored as WCS.  So to me an AutoCAD line of coincidence must have equal X Y & Z axis values ( to within a fuzz factor )  ?

Or do you consider a LINE coincidental if the points are reversed:?

-David

« Last Edit: August 25, 2015, 03:49:38 PM by David Bethel »
R12 Dos - A2K

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Delete a line of complete coincidence
« Reply #13 on: August 25, 2015, 05:20:57 PM »
It is a valid point, but you also have to factor in how many other people in your company will use it as well?

That factors out.  Lets say you have ten users.  That may be ten times the time saved, but over the year that's also ten times more man-hours.  The values stay constant relative to each other.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Delete a line of complete coincidence
« Reply #14 on: August 25, 2015, 05:26:56 PM »
It is a valid point, but you also have to factor in how many other people in your company will use it as well?

That factors out.  Lets say you have ten users.  That may be ten times the time saved, but over the year that's also ten times more man-hours.  The values stay constant relative to each other.
No, what I am saying is a CAD Manager invests say 10 hours in creating a LISP routine that 50 users are going to use. That is a lot different than investing 10 hours in something one user will use.

That being said, let's take a look at the numbers with a command that gets used a modest 25 times in one day per user. Let's say the command typically takes 2 minutes to run and you are able to cut it down to 1 minute. Well, each user has now saved 25 minutes per day. At 50 work weeks of 5 days a week, that equals out to be approximately 100 hours a year per user. At an average billable rate of $50 per hour, that is $5,000 per year, per user in billable times that has been saved. And that is saving just 25 minutes per day per user. Now, if you are a company with say 50 users, that's $250,000 per year in billable time that is saved. Even for just one user, that's three AutoCAD licenses of savings each year.

Even at half the savings, that is still a huge chunk of money. It's amazing how fast the savings can add up, isn't it?

So was 10 hours of the CAD Manager's time, even at the full $50 per hour billable rate, which would come out to $500, a good investment? I think it was given the end savings per year and hopefully it is something the CAD Manager doesn't need to revisit every single year, then the savings are even better.
« Last Edit: August 25, 2015, 06:08:28 PM by cmwade77 »

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Delete a line of complete coincidence
« Reply #15 on: August 25, 2015, 05:46:32 PM »
If I am understanding correctly, wouldn't this work:
Code: [Select]
(defun c:tt (/)
     (command "._-overkill" "All" "" "_O" "0" "_I" "_A" "_P" "_N" "_T" "_N" "_E" "_N" "_A" "Y" "")
)
And it would be by far the fastest method, at least in versions of AutoCAD since Overkill has been a command instead of an express tool. I believe it was around 2012 or so that this became a built-in command.

It would be the fastest way if OP didn't wanted to overkill only coincident lines. So the lisp is more appropriate solution IMHO.
If you want to limit it to lines only, simply make the following change:
Code: [Select]
(defun c:tt (/)
     (command "._-overkill" (ssget "_X" '((0 . "LINE"))) "" "_O" "0" "_I" "_A" "_P" "_N" "_T" "_N" "_E" "_N" "_A" "Y" "")
)

As far as I can see, this will only remove lines that match exactly, here's how:
Code: [Select]
(defun c:tt (/)
     (command "._-overkill" ; Begins the Overkill command
                     (ssget "_X" '((0 . "LINE"))) ;selects all lines within the drawing, but only lines, change this filter if you only want lines within the current space.
                      "" ;Ends the selecting of lines
"_O" "0" ; Sets the tolerance to 0, you can increase this tolerance if needed.
 "_I" "_A" ; Tells the command to Ignore all of the following differences: Color, Layer, Linetype, ltScale, LWeight, Thickness, Transparency, plotStyle & Material - This can be easily changed to suit any needs.
"_P" "_N" ; Tells the overkill command not to optimize plines - since only lines are selected, this is not an issue, but I left here in case the ssget above is changed to include plines
"_T" "_N" ; Tells the command not to combine partially overlapping objects.
"_E" "_N" ; Tells the command not to combine co-linear objects end to end
"_A" "Y" ; Tells the overkill command to maintain associativity, in this case, this will do nothing, but may be important if the ssget filter were adjusted to include dimensions.
"" ; Completes the Overkill command
)
)

It uses a tolerance of 0, does not allow for partial overlaps, will not combine end to end, so this will only handle coincident lines that are exactly the same length, unless I am missing something. And if you want to remove all overlapping lines, even if they are different length, simply change the option above. Please let me know if I am missing something, but I believe it accomplishes the desired effect, right? But perhaps I am missing something, please let me know if I am.
« Last Edit: August 25, 2015, 05:53:01 PM by cmwade77 »