joining multiple polylines at once

joining multiple polylines at once

arefemami98
Explorer Explorer
713 Views
7 Replies
Message 1 of 8

joining multiple polylines at once

arefemami98
Explorer
Explorer

hi all
is there a way that i can join multiple pairs of polylines that have gaps in between them simultaneously? i want to be able to select all pairs like in the image (each pair in different color is in a different layer) and a segment be added to connect each pair and join each pair, i can click on every pline and add a vertex and connect it to the other one and then join them but considering i have tens of thousands of these to do it would take days to do and i also tried using mpedit but using fillet or add as the jointype will result in either changing the original pline or it will just connect nearest plines to each other and changes their layer

Screenshot (349).pngScreenshot (350).png

0 Likes
714 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

Perhaps the discussion on this thread would help

https://forums.augi.com/showthread.php?125219-Join-all-lines-in-a-drawing


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 8

arefemami98
Explorer
Explorer

unfortunately codes provided in that thread does not seem to help since they need the two polylines to touch eachother in the first place

0 Likes
Message 4 of 8

hak_vz
Advisor
Advisor

Use command PEDIT join option with FUZZ value set to value a bit greater than a distance between lines (polylines) you want to joint. This way lines to join don't need to have zero distance, but they need to be 2d with equal Z value for all start and end point.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 8

arefemami98
Explorer
Explorer

using pedit for each pair seperately could work but scince there are mane of these it would take a long time, i was hoping to find a way to select multiple pairs and join them at once but doing that with pedit will change their layer and also connects different pairs to each other

0 Likes
Message 6 of 8

komondormrex
Mentor
Mentor

are you using only line-segmented polylines?

0 Likes
Message 7 of 8

arefemami98
Explorer
Explorer

yes, all of them are straight

0 Likes
Message 8 of 8

komondormrex
Mentor
Mentor

check the following code with limitations:

1. plines with the same color are joined, regardless of their layer.

2. there are matched plines' pairs and every pair is one in quantity.

3. every pline has no arc segment, otherwise resulting plines will be distorted.

 

;**************************************************************************************************************************************************

(defun reverse_coordinates (coordinates_raw_list / reversed_list)
  	(if coordinates_raw_list
		(setq reversed_list (append
									(reverse_coordinates (cddr coordinates_raw_list))
									(list (car coordinates_raw_list) (cadr coordinates_raw_list))
							)
		)
	)
  	reversed_list
)

;**************************************************************************************************************************************************

(defun remove_duplicates (_list / duplicateless_list)
	(while _list
		(if (not (member (setq list_element (car _list)) (setq _list (cdr _list))))
			(setq duplicateless_list (cons list_element duplicateless_list))
		)
	)
	duplicateless_list
)

;**************************************************************************************************************************************************

(defun join_plines (pair)
	(cond 
		(
			(= 1 (cdar pair))
				(setq joined_pline_coordinates_raw_list (append (reverse_coordinates (vlax-get (vlax-ename->vla-object (cadr pair)) 'coordinates))
																(vlax-get (vlax-ename->vla-object (caddr pair)) 'coordinates)
														)
				)
		)
		(
			(= 2 (cdar pair))
				(setq joined_pline_coordinates_raw_list (append (reverse_coordinates (vlax-get (vlax-ename->vla-object (cadr pair)) 'coordinates))
																(reverse_coordinates (vlax-get (vlax-ename->vla-object (caddr pair)) 'coordinates))
														)
				)
		)
		(
			(= 3 (cdar pair))
				(setq joined_pline_coordinates_raw_list (append (vlax-get (vlax-ename->vla-object (cadr pair)) 'coordinates)
																(vlax-get (vlax-ename->vla-object (caddr pair)) 'coordinates)
														)
				)
		)
		(
			(= 4 (cdar pair))
				(setq joined_pline_coordinates_raw_list (append (vlax-get (vlax-ename->vla-object (cadr pair)) 'coordinates)
																(reverse_coordinates (vlax-get (vlax-ename->vla-object (caddr pair)) 'coordinates))
														)
				)
		)
	)
	(entdel (caddr pair))
	(vla-put-coordinates (vlax-ename->vla-object (cadr pair)) 
						 (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 1 (length joined_pline_coordinates_raw_list)))
	  										  joined_pline_coordinates_raw_list
	  					 )
	)
)

;**************************************************************************************************************************************************

(defun c:joins_pline_pairs (/ pline_color_list color_list one_color_pline_list one_color_pline min_dist_list closest_pair)
	(setq pline_color_list (mapcar '(lambda (pline) (cons (getpropertyvalue pline "color") pline)) 
						   (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "lwpolyline")))))))
		  color_list (remove_duplicates (mapcar 'car pline_color_list))
	)
	(foreach color color_list
		(setq one_color_pline_list (mapcar 'cdr 
										    (vl-remove-if-not '(lambda (pline) (equal color (car pline))) 
												  			   pline_color_list
										    )
								   )
		)
		(while (< 1 (length one_color_pline_list))
			(setq one_color_pline (car one_color_pline_list)
				  one_color_pline_list (cdr one_color_pline_list)
				  min_dist_list (mapcar '(lambda (pline) (list (car (vl-sort (list (cons (distance (vlax-curve-getstartpoint one_color_pline) (vlax-curve-getstartpoint pline)) 1) 
														 					 	   (cons (distance (vlax-curve-getstartpoint one_color_pline) (vlax-curve-getendpoint pline)) 2)
																			 	   (cons (distance (vlax-curve-getendpoint one_color_pline) (vlax-curve-getstartpoint pline)) 3)
																			 	   (cons (distance (vlax-curve-getendpoint one_color_pline) (vlax-curve-getendpoint pline)) 4)
																  	   		  )    
																  	  		 '(lambda (distance_1 distance_2) (< (car distance_1) (car distance_2)))
														 	   		)
															   )
															   one_color_pline
															   pline
														 )
										 )
										 one_color_pline_list
								)      
			)
			(setq closest_pair (car (vl-sort min_dist_list '(lambda (distance_1 distance_2) (< (caar distance_1) (caar distance_2)))))
				  one_color_pline_list (vl-remove (last closest_pair) one_color_pline_list)   
			)  
			(join_plines closest_pair)
		)
	)
)

;**************************************************************************************************************************************************

 

0 Likes