Jump to content

Detect overlapping lines and draw new lines


teknomatika

Recommended Posts

32 minutes ago, niciolaux said:

I make some tests, the comand doesn't work everytime, because of the direction of the lines, I have to reverse them manually, with the comand "reverse" it doesn't work

 

Could you please upload a sample drawing containing an example for which the program is failing?

Link to comment
Share on other sites

I made some more tests and it seems the problem is the tollerance of the distance between the lines, I just change the value of the tolerance in the code. sorry, it's not related to line's direction

Link to comment
Share on other sites

I am working on a complex file, now I discover that the lisp doesn't work if the start and the end of a line is contained inside another line. Sorry I have to do more tests before writing here

Link to comment
Share on other sites

  • 2 months later...

Lee Mac, 

I hope everything is fine with you.

Hoping for help, I return to routine. I have used it frequently and it has been very useful. However, if possible, I want the overlapping lines to be detected as well, as shown in the example I attached. This is because the routine solves partially overlapping lines very well, but not when fully.
Any help will be welcome.

It would be wonderful to also act on arcs and circles or even replicating the same type of line (in the case of non-continuous lines) but that will be asking for more ... 🙂

EXAMPLE_OVERLAP_ROUTINE.dwg

Link to comment
Share on other sites

  • 2 years later...
On 11/19/2012 at 9:46 PM, Lee Mac said:

There are essentially five cases of overlap to consider between two lines, though, it doesn't make for pretty code:

(defun c:overlap ( / _line _online a e i l s )

   (defun _line ( a b )
       (entmake (list '(0 . "LINE") (cons 10 a) (cons 11 b)))
   )
   (defun _online ( p a b )
       (equal (+ (distance p a) (distance p b)) (distance a b) 1e-8)
   )            
   (if (setq s (ssget '((0 . "LINE"))))
       (progn
           (repeat (setq i (sslength s))
               (setq e (entget (ssname s (setq i (1- i))))
                     l (cons (list (cdr (assoc 10 e)) (cdr (assoc 11 e))) l)
               )
           )
           (while (setq a (car l))
               (foreach b (setq l (cdr l))
                   (cond
                       (   (or
                               (and
                                   (equal (car  a) (car  b) 1e-8)
                                   (equal (cadr a) (cadr b) 1e-8)
                               )
                               (and
                                   (equal (car  a) (cadr b) 1e-8)
                                   (equal (cadr a) (car  b) 1e-8)
                               )
                           )
                           (apply '_line a)
                       )
                       (   (and
                               (_online (car a) (car b) (cadr b))
                               (_online (car b) (car a) (cadr a))
                           )
                           (_line (car a) (car b))
                       )
                       (   (and
                               (_online (car  a) (car b) (cadr b))
                               (_online (cadr b) (car a) (cadr a))
                           )
                           (_line (car a) (cadr b))
                       )
                       (   (and
                               (_online (cadr a) (car b) (cadr b))
                               (_online (car  b) (car a) (cadr a))
                           )
                           (_line (cadr a) (car b))
                       )
                       (   (and
                               (_online (cadr a) (car b) (cadr b))
                               (_online (cadr b) (car a) (cadr a))
                           )
                           (_line (cadr a) (cadr b))
                       )
                   )
               )
           )
       )
   )
   (princ)
)

The above simply creates a third line between the endpoints of the overlapping lines, however, the result could easily be highlighted by other means if necessary.

Thank you for the useful code. If the overlapping distance is zero, the code lefts a dot which is unneeded.

Moreover, Since I am a beginner in lisp, I need lisp to do a bit more regarding overlaps:

1. I want the new overlapping lines to be displayed in optimal position asking for offset distance.

2. The upgraded code should be able to detect the overlapping distance of arcs?

I will be grateful is someone help.

Link to comment
Share on other sites

9 hours ago, Karimi said:

Thank you for the useful code. If the overlapping distance is zero, the code lefts a dot which is unneeded.

 

Do some more reading of this thread you might find something.

 

1. that's simple enough as to update the _line function

(defun _line (a b)
  (entmake (list '(0 . "LINE") (cons 10 a) (cons 11 b)))
  (if d
    (progn
      (setvar 'cmdecho 0)
      (command "_.Offset" d (setq x (entlast)) (getpoint "\nSide?"))
      (entdel x)
      (setvar 'cmdecho 1)
    )
  )
)

(defun c:overlap (/ _line _online a e i l s r d) ;add r and d
;add this to the main function before the ssget
(initget "Yes No")
(setq r
  (cond
    ((getkword "\nOffset overlap Yes/<No>: ")) ("No")
  )
)
(if (eq r "Yes")  
  (setq d (getdist "\nOffset Distance: "))
)

 

2. that seems out of scope of this lisp and would need a complete re-write, maybe someone would want to do that?

Edited by mhupp
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...