View Full Version : joining all lines that share a point
hokie555
27th Oct 2009, 07:06 pm
In my plot style I have the "Line End Style" set to "Butt", and the "Line Join Style" set to "Round". The problem is that even though many of these lines touch at the same point, they are still not recognized by AutoCAD as being Joined since they were created separately. This results in a Butt end on each of the lines at the intersection point. Is there anything out there that will join all lines that share a common point, without having to manually join them one at a time? Thanks!
JohnM
27th Oct 2009, 10:35 pm
Just line objects or plines also?
You can use SSGET with the line polyline filter
Then use the pedit command
;;; depending on what you want you can comment out the ssget function that does not apply
(defun c:jln ( / ss)
;(setq ss (ssget "_X" '((0 . "LINE")(410 . "Model"))));_gets only lines
;(setq ss (ssget "_X" '((0 . "LWPOLYLINE")(410 . "Model")(70 . 0))));_gets only polylines
(setq ss (ssget "_X"
'(
( -4 . "<OR")
( -4 . "<AND")
(0 . "LWPOLYLINE");(410 . "Model")(70 . 0)
(-4 . "AND>")
(-4 . "<AND")
(0 . "LINE");(410 . "Model")
(-4 . "AND>")
( -4 . "OR>")
)
)
);_gets both pline and lines
(command "pedit" "Multiple" "Previous" "" "Yes" "Join" "" "")
(princ)
);_defun
CAB
28th Oct 2009, 01:31 pm
Another version:
(defun c:jln ( / ss)
(if (setq ss (ssget "_X" (list '(0 . "LINE,LWPOLYLINE")(cons 410 (getvar "ctab"))))); current space
(command "pedit" "Multiple" ss "" "Yes" "Join" "" "")
)
(princ)
)
hokie555
28th Oct 2009, 01:34 pm
That's great, thank you very much!
hokie555
29th Oct 2009, 05:21 pm
taking this one step further, I want to only join polylines that are on the same layer and have the same lineweight, so that the newly joined sections don't inheret the properties of the source polyline. I know i can create this using what I was given with each combination of layer and lineweight, but I imagine a loop would be a whole lot easier. Any assistance would be much appreciated.
CAB
29th Oct 2009, 05:53 pm
No test for lineweight but add your layer name and the routine will select only that layer.
Then it will set line width to zero.
No testing so you must debug it. :)
(defun c:jln ( / ss)
(if (setq ss (ssget "_X" (list '(0 . "LINE,LWPOLYLINE")
'(8 . "LayerName")
(cons 410 (getvar "ctab"))))); current space
(progn
(command "pedit" "Multiple" ss "" "Yes" "Join" "" "")
(setq elst (entget (entlast)))
(entmod (subst '(43 0.0) (assoc 43 elst) elst))
)
)
(princ)
)
hokie555
29th Oct 2009, 06:35 pm
Thanks again CAB. I was thinking more of automatically performing the pedit command for each lineweight and for each layer, and also not changing any properties. I'm clearly not setting this loop up correctly, and possibly not using "cons" correctly, but this may help you better understand where I'm headed.
(loop for lw in '(-2 -3 0 5 9 13 15 18 20 25 30 35 40 50 53 60 70 80 90 100 106 120 140 158 200 211)
(loop for lyr in '("layer1" "layer2" "layer3")
(setq ss1 (ssget "_X" '((0 . "LINE,LWPOLYLINE")(cons 8 lyr)(cons 370 lw)(410 . "Model"))))
(if (/= ss1 nil) (command "pedit" "Multiple" ss1 "" "Join" "" "") (princ)
)
)
CAB
29th Oct 2009, 07:18 pm
Try this: (not tested)
You'll run into problems with LINES set to line weight ByLayer!
(defun c:MyLisp (/ lyr lw ss1)
(foreach lyr '("layer1" "layer2" "layer3")
(foreach lw '(-2 -3 0 5 9 13 15 18 20 25 30 35 40 50 53 60 70 80 90 100 106 120 140 158 200 211)
(setq ss1 (ssget "_X" (list '(0 . "LINE,LWPOLYLINE") (cons 8 lyr) (cons 370 lw) '(410 . "Model"))))
(if ss1
(command "pedit" "Multiple" ss1 "" "Join" "" "")
)
)
)
(princ)
)
hokie555
29th Oct 2009, 08:11 pm
thanks, that worked like a charm! didn't know this, but bylayer cooresponds to a "-1" in the list of lineweights so I added that. The problem I assume you are referring to is the program not combining two lines with the same lineweight value but a different setting (such as a line of 0.05mm and a line of bylayer when the layer is set to 0.05mm). I'm willing to overlook this instance.
Thank you!
Powered by vBulletin™ Version 4.1.2 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.