Jump to content

Detect overlapping lines and draw new lines


teknomatika

Recommended Posts

(defun c:t1 (/ en enlist1 enn enlist2 p1 p2)
(setq oldclay (getvar "clayer"))
(command "layer" "new" "nlines" "color" "2" "nlines" "")
(command "layer" "set" "nlines" "")
(setq en(car (entsel "\n Select 1 line: ")))
(setq enlist1(entget en))
(setq enn(car (entsel "\n Select 2 line: ")))
(setq enlist2(entget enn))
(setq p1 (cdr(assoc 11 enlist1)))
(setq p2 (cdr(assoc 10 enlist2)))
(command "_.line" p1 "_non" p2 "_non" "")
(setvar "clayer" oldclay)
(princ)
)

 

 

Thanks to anyone who can and want to help:

Do not know if I've put this question, or like, another time: Following the principle of this simple routine, I intend to expand it to a more global task, allowing within a range of lines (not just selecting one by one), are new lines drawn between the points of overlap. To better understand an image attachment.

cadtutor_exp_6.jpg

Link to comment
Share on other sites

Your routine would trim out the overlapping portion of both lines then add a line segment between the two existing lines. Wouldn't it be more efficient to get the total length of the two overlapping lines and substitute one line for them both?

Link to comment
Share on other sites

Your routine would trim out the overlapping portion of both lines then add a line segment between the two existing lines. Wouldn't it be more efficient to get the total length of the two overlapping lines and substitute one line for them both?

 

ReMark,

I appreciate the interest.

For the purpose I want, even if the idea is to create new lines in overlapping segments. It is not necessary to cut the common thread or join in a single line.

Link to comment
Share on other sites

But wouldn't that just create another overlapping object? I would think you would try to avoid that situation. What is the purpose then of the new line (the yellow one in your example)?

Link to comment
Share on other sites

But wouldn't that just create another overlapping object? I would think you would try to avoid that situation. What is the purpose then of the new line (the yellow one in your example)?

 

In this case demonstrate the overlapping segments and demonstrate that printing with a third color.

Link to comment
Share on other sites

Might I suggest that overlapping lines be circled instead? That would facilitate finding them so the user could go back and correct their mistakes.

Link to comment
Share on other sites

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.

Edited by Lee Mac
Link to comment
Share on other sites

My personal opinion is that creating a third line between the endpoints of overlapping lines is not a good CAD drafting practice. But perhaps there is a practical application that I have failed to recognize.

Link to comment
Share on other sites

My personal opinion is that creating a third line between the endpoints of overlapping lines is not a good CAD drafting practice. But perhaps there is a practical application that I have failed to recognize.

 

I simply viewed the thread as solving a geometrical problem - I'll leave the CAD drafting practices to the OP :thumbsup:

Link to comment
Share on other sites

My personal opinion is that creating a third line between the endpoints of overlapping lines is not a good CAD drafting practice. But perhaps there is a practical application that I have failed to recognize.

 

Maybe the OP needs to know the distances and locations of overlaps. Really doesn't matter if that is what the OP needs.

Link to comment
Share on other sites

My personal opinion is that creating a third line between the endpoints of overlapping lines is not a good CAD drafting practice. But perhaps there is a practical application that I have failed to recognize.

 

ReMark,

I understand your reasoning and apparently use conventional perspective, it makes sense.

However, for the purpose of specifically, this routine and the result will, at the level of printing, represent overlapping elements by using a different color

Link to comment
Share on other sites

I simply viewed the thread as solving a geometrical problem - I'll leave the CAD drafting practices to the OP :thumbsup:

 

Lee,

That's it. As I explained, it may seem unusual, but in this case it is a specific need.

 

I appreciate the help and the routine. It exctamente that he needed. Thank you for the fantastic help.

 

By the way, what other options outstanding have in mind? It would be enriching for the routine can consider them as an option.

 

However, how to prevent small variations in the value of each coordinate coincident, it is not necessary to define a greater number of decimal places? Also note that in the case of coinciding rows in end points, lines are created with zero length. Not very relevant, but perhaps it would be preferable to eliminate or not considering.

I note also that in a situation where the ends point is coincident lines in two partially overlapped, as in the attached drawing, the routine is not drawing.

cadtutor_exp_7.jpg

Edited by teknomatika
Link to comment
Share on other sites

Lee,

Sorry for the insistence.

I tested the routine in different situations, and works match I want. However, in similar situations, some are resolved and others not. Will these unresolved situations in which, apparently, such lines are created with zero length.

 

I admit that when I put the request for help, does not include the variant lines can be matched one or both ends, and this is also important, if possible, of course.

 

With time, I appreciate the help to resolve this apparent inconsistency.

 

DWG file is attached to aid understanding of the situation that occurs.

 

Tanks for the help!

cadtutor_exp_overlap_1.dwg

Link to comment
Share on other sites

This will avoid the zero-length lines:

(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))
                               (not (equal (car a) (car b) 1e-8))
                           )
                           (_line (car a) (car b))
                       )
                       (   (and
                               (_online (car  a) (car b) (cadr b))
                               (_online (cadr b) (car a) (cadr a))
                               (not (equal (car a) (cadr b) 1e-8))
                           )
                           (_line (car a) (cadr b))
                       )
                       (   (and
                               (_online (cadr a) (car b) (cadr b))
                               (_online (car  b) (car a) (cadr a))
                               (not (equal (cadr a) (car b) 1e-8))
                           )
                           (_line (cadr a) (car b))
                       )
                       (   (and
                               (_online (cadr a) (car b) (cadr b))
                               (_online (cadr b) (car a) (cadr a))
                               (not (equal (cadr a) (cadr b) 1e-8))
                           )
                           (_line (cadr a) (cadr b))
                       )
                   )
               )
           )
       )
   )
   (princ)
)
 
Edited by Lee Mac
Link to comment
Share on other sites

Lee,

Excellent.

Thank you.

 

You just solved the issue of zero-length lines as well as the question explained that through the DWG file.

Provisional and partly I was to solve the problem by doubling the routine, and inverting the assoc values.:D

 

l (cons (list (cdr (assoc 10 e)) (cdr (assoc 11 e))) l)

 

l (cons (list (cdr (assoc 11 e)) (cdr (assoc 10 e))) l)

 

Tanks again!

Link to comment
Share on other sites

  • 7 years later...

Hello, I am interested in this lisp, unfortunately I am not able to make it work. I delete the brackets with color indication but I think there is something wrong with code formatting. Please can someone help me? thanks

Link to comment
Share on other sites

5 hours ago, niciolaux said:

Hello, I am interested in this lisp, unfortunately I am not able to make it work. I delete the brackets with color indication but I think there is something wrong with code formatting. Please can someone help me? thanks

 

Unfortunately the update to the forum software implemented several months back caused BBCode formatting tags embedded within code to become visible in code blocks, and also removed every instance of "8)" within code, breaking thousands of programs which previously ran successfully.

 

I've now updated my earlier posts to fix the code.

  • Like 2
Link to comment
Share on other sites

  • 3 weeks later...

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

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...