Plumbing fittings at intersection of single lines

Plumbing fittings at intersection of single lines

DC-MWA
Collaborator Collaborator
3,746 Views
27 Replies
Message 1 of 28

Plumbing fittings at intersection of single lines

DC-MWA
Collaborator
Collaborator

Hi all,

Hard to describe in words what I'm trying to do. So here is an image.

0 Likes
Accepted solutions (2)
3,747 Views
27 Replies
Replies (27)
Message 21 of 28

Sea-Haven
Mentor
Mentor

Trying to automate every angle combo can just not work some times. For me a pick image dcl then you know what the line pattern looks like, like Tharwat pre pattern objects but with variable angles. Just window the lines.

 

Look at screen shot the last pick is remembered.

 

0 Likes
Message 22 of 28

DC-MWA
Collaborator
Collaborator

I have managed to cut and paste some code together that works for what I'm trying to achieve. I used the fast sample you created for me in addition to some other code to trim out the polyline after wrapping the rectangles drawn by your code.

Most intersection conditions seem to work well (see image). I still am unable to solve the "corner issue" caused by the drawing of two rectangles on a corner situation.

4.JPG

I'm hoping that you or someone else may have a solution for this?

I have attached my cut n paste lisp. I know it will offend you true programmers, so I apologize in advance for my lack of lisp skills, and my methods.

-dc 

0 Likes
Message 23 of 28

doaiena
Collaborator
Collaborator
Accepted solution

Here is a complete solution to your request.

(defun c:test ( / DrawRect line1 line2 len width fuzz line1Start line1End line2Start line2End intersPt line1Ang line2Ang p1 p2 p3 p4 sel regions lastEnt)

(defun DrawRect (lst)
(entmake (append (list (cons 0 "LWPOLYLINE")
(cons 100 "AcDbEntity")
(cons 100 "AcDbPolyline")
(cons 90 (length lst))
(cons 70 1))
(mapcar (function (lambda (p) (cons 10 p))) lst)))
);defun

(while (not line1) (setq line1 (entsel "\nPick first line: ")))
(while (not line2) (setq line2 (entsel "\nPick second line: ")))

(setq len 80)
(setq width 20)
(setq fuzz 0.01)

(setq line1Start (cdr (assoc 10 (entget (car line1)))))
(setq line1End (cdr (assoc 11 (entget (car line1)))))
(setq line2Start (cdr (assoc 10 (entget (car line2)))))
(setq line2End (cdr (assoc 11 (entget (car line2)))))

;If the 2 lines intersect
(if (setq intersPt (inters line1Start line1End line2Start line2End))
(progn

(command "_.undo" "_begin")

(setq sel (ssadd) regions (ssadd))
(setq line1Ang (angle line1Start line1End))
(setq line2Ang (angle line2Start line2End))

(mapcar '(lambda (line / lineStart lineEnd lineAng lineEnt)

(setq lineStart (car line) lineEnd (cadr line) lineAng (caddr line) lineEnt (cadddr line))

(cond
;Intersection point is on the start point of the line
((equal intersPt lineStart fuzz)
(setq p1 (polar intersPt (- (- line1Ang (/ pi 2)) (/ (- line1Ang line2Ang) 2)) (/ (/ width 2) (cos (/ (- line1Ang line2Ang) 2)))))
(setq p2 (polar (polar intersPt lineAng len) (- lineAng (/ pi 2)) (/ width 2)))
(setq p3 (polar (polar intersPt lineAng len) (+ lineAng (/ pi 2)) (/ width 2)))
(setq p4 (polar intersPt (- (+ line1Ang (/ pi 2)) (/ (- line1Ang line2Ang) 2)) (/ (/ width 2) (cos (/ (- line1Ang line2Ang) 2)))))
(DrawRect (list p1 p2 p3 p4))
(ssadd (entlast) sel)
(command "break" lineEnt intersPt (polar intersPt lineAng len))
)

;Intersection point is on the end point of the line
((equal intersPt lineEnd fuzz)
(setq p1 (polar intersPt (- (- line1Ang (/ pi 2)) (/ (- line1Ang line2Ang) 2)) (/ (/ width 2) (cos (/ (- line1Ang line2Ang) 2)))))
(setq p2 (polar (polar intersPt (+ lineAng pi) len) (- lineAng (/ pi 2)) (/ width 2)))
(setq p3 (polar (polar intersPt (+ lineAng pi) len) (+ lineAng (/ pi 2)) (/ width 2)))
(setq p4 (polar intersPt (- (+ line1Ang (/ pi 2)) (/ (- line1Ang line2Ang) 2)) (/ (/ width 2) (cos (/ (- line1Ang line2Ang) 2)))))
(DrawRect (list p1 p2 p3 p4))
(ssadd (entlast) sel)
(command "break" lineEnt intersPt (polar intersPt (+ lineAng pi) len))
)

;Intersection point is in the middle of the line
(T
(setq p1 (polar (polar intersPt lineAng len) (- lineAng (/ pi 2)) (/ width 2)))
(setq p2 (polar (polar intersPt (+ lineAng pi) len) (- lineAng (/ pi 2)) (/ width 2)))
(setq p3 (polar (polar intersPt (+ lineAng pi) len) (+ lineAng (/ pi 2)) (/ width 2)))
(setq p4 (polar (polar intersPt lineAng len) (+ lineAng (/ pi 2)) (/ width 2)))
(DrawRect (list p1 p2 p3 p4))
(ssadd (entlast) sel)
(command "break" lineEnt (polar intersPt lineAng len) (polar intersPt (+ lineAng pi) len))
)
);cond

)
(list (list line1Start line1End line1Ang (car line1)) (list line2Start line2End line2Ang (car line2)))
);mapcar

(setq lastEnt (entlast))
(command "region" sel "")
(command "erase" sel "")
(while (setq lastEnt (entnext lastEnt))
(ssadd lastEnt regions))
(command "union" regions "")
(command "_.undo" "_end")
))

(princ)
);defun
0 Likes
Message 24 of 28

DC-MWA
Collaborator
Collaborator

Thank you very much. There is much to be learned from this code.

I appreciate your knowledge and time.

-dc

0 Likes
Message 25 of 28

doaiena
Collaborator
Collaborator
Accepted solution

I had completely forgotten the 3 line example. I've changed the way lines are selected. Now you don't have to pick individual lines one at a time, you can now select the entire drawing and the function will do its magic. Have in mind that i haven't made any optimizations to the code, so the more lines you select at once, the performance will get exponentially worse. It's barely tested on relatively simple examples.

(defun c:test ( / DrawRect line1 line2 len width fuzz line1Start line1End line2Start line2End intersPt line1Ang line2Ang p1 p2 p3 p4 sel regions lastEnt ctr ctr2 ss lines)

(defun DrawRect (lst)
(entmake (append (list (cons 0 "LWPOLYLINE")
(cons 100 "AcDbEntity")
(cons 100 "AcDbPolyline")
(cons 90 (length lst))
(cons 70 1))
(mapcar (function (lambda (p) (cons 10 p))) lst)))
);defun

(prompt "\nSelect lines: ")
(if (setq ss (ssget '((0 . "LINE"))))
(progn

(command "_.undo" "_begin")

(setq len 80)
(setq width 20)
(setq fuzz 0.01)
(setq sel (ssadd) regions (ssadd))

(setq ctr 0)
(repeat (sslength ss)
(setq line1 (ssname ss ctr))
(setq ctr2 0)
(repeat (sslength ss)
(setq line2 (ssname ss ctr2))

(setq line1Start (cdr (assoc 10 (entget line1))))
(setq line1End (cdr (assoc 11 (entget line1))))
(setq line2Start (cdr (assoc 10 (entget line2))))
(setq line2End (cdr (assoc 11 (entget line2))))

;If the 2 lines intersect
(if (and (/= line1 line2) (setq intersPt (inters line1Start line1End line2Start line2End)))
(progn

(setq line1Ang (angle line1Start line1End))
(setq line2Ang (angle line2Start line2End))
(setq lines (cons (list (list line1Start line1End line1Ang line1) (list line2Start line2End line2Ang line2) intersPt) lines))
))
(setq ctr2 (1+ ctr2))
)
(setq ctr (1+ ctr))
)

(mapcar '(lambda (linePair)

(setq line1 (car linePair))
(setq line2 (cadr linePair))
(setq line1Start (car line1))
(setq line1End (cadr line1))
(setq line1Ang (caddr line1))
(setq line2Start (car line2))
(setq line2End (cadr line2))
(setq line2Ang (caddr line2))
(setq intersPt (caddr linePair))

(mapcar '(lambda (line / lineStart lineEnd lineAng lineEnt)

(setq lineStart (car line) lineEnd (cadr line) lineAng (caddr line) lineEnt (cadddr line))

(cond
;Intersection point is on the start point of the line
((equal intersPt lineStart fuzz)
(setq p1 (polar intersPt (- (- line1Ang (/ pi 2)) (/ (- line1Ang line2Ang) 2)) (/ (/ width 2) (cos (/ (- line1Ang line2Ang) 2)))))
(setq p2 (polar (polar intersPt lineAng len) (- lineAng (/ pi 2)) (/ width 2)))
(setq p3 (polar (polar intersPt lineAng len) (+ lineAng (/ pi 2)) (/ width 2)))
(setq p4 (polar intersPt (- (+ line1Ang (/ pi 2)) (/ (- line1Ang line2Ang) 2)) (/ (/ width 2) (cos (/ (- line1Ang line2Ang) 2)))))
(DrawRect (list p1 p2 p3 p4))
(ssadd (entlast) sel)
(command "break" lineEnt intersPt (polar intersPt lineAng len))
)

;Intersection point is on the end point of the line
((equal intersPt lineEnd fuzz)
(setq p1 (polar intersPt (- (- line1Ang (/ pi 2)) (/ (- line1Ang line2Ang) 2)) (/ (/ width 2) (cos (/ (- line1Ang line2Ang) 2)))))
(setq p2 (polar (polar intersPt (+ lineAng pi) len) (- lineAng (/ pi 2)) (/ width 2)))
(setq p3 (polar (polar intersPt (+ lineAng pi) len) (+ lineAng (/ pi 2)) (/ width 2)))
(setq p4 (polar intersPt (- (+ line1Ang (/ pi 2)) (/ (- line1Ang line2Ang) 2)) (/ (/ width 2) (cos (/ (- line1Ang line2Ang) 2)))))
(DrawRect (list p1 p2 p3 p4))
(ssadd (entlast) sel)
(command "break" lineEnt intersPt (polar intersPt (+ lineAng pi) len))
)

;Intersection point is in the middle of the line
(T
(setq p1 (polar (polar intersPt lineAng len) (- lineAng (/ pi 2)) (/ width 2)))
(setq p2 (polar (polar intersPt (+ lineAng pi) len) (- lineAng (/ pi 2)) (/ width 2)))
(setq p3 (polar (polar intersPt (+ lineAng pi) len) (+ lineAng (/ pi 2)) (/ width 2)))
(setq p4 (polar (polar intersPt lineAng len) (+ lineAng (/ pi 2)) (/ width 2)))
(DrawRect (list p1 p2 p3 p4))
(ssadd (entlast) sel)
(command "break" lineEnt (polar intersPt lineAng len) (polar intersPt (+ lineAng pi) len))
)
);cond

)
(list line1 line2)
);mapcar

)
lines
);mapcar

(setq lastEnt (entlast))
(command "region" sel "")
(command "erase" sel "")
(while (setq lastEnt (entnext lastEnt))
(ssadd lastEnt regions))
(command "union" regions "")
(command "_.undo" "_end")

));if ss

(princ)
);defun
0 Likes
Message 26 of 28

DC-MWA
Collaborator
Collaborator

This is awesome! Thank you so very much for your time and effort.

0 Likes
Message 27 of 28

doanvietdung2020
Community Visitor
Community Visitor

MISTAKE.png

connection error
0 Likes
Message 28 of 28

DOODLEANU
Enthusiast
Enthusiast

Thank you so much for this amazing lisp, is there any chance to do multiple selection on this? instead of selecting one by one ? 

0 Likes