Lisp that moves alot of blocks to the nearest vertex of a polyline at once (end of Polyline vertex or either closest vertex)

Lisp that moves alot of blocks to the nearest vertex of a polyline at once (end of Polyline vertex or either closest vertex)

t_pladet
Contributor Contributor
2,030 Views
32 Replies
Message 1 of 33

Lisp that moves alot of blocks to the nearest vertex of a polyline at once (end of Polyline vertex or either closest vertex)

t_pladet
Contributor
Contributor

Hello everyone,

 

Been moving alot of blocks manually for a couple of months now and it is really sucking alot of energy out of me haha.

is there a option to resolve this problem with a lisp? Images included for explanation!

Schermafbeelding 2023-11-03 095653.png

Schermafbeelding 2023-11-03 095712.png

Schermafbeelding 2023-11-03 095738.png

 

All the help would be really appreciated! thanks in advance!

0 Likes
Accepted solutions (3)
2,031 Views
32 Replies
Replies (32)
Message 21 of 33

t_pladet
Contributor
Contributor

My bad for not clarifying. What I am trying to say is that when I used the lisp that was made for the sample drawing, the LISP was working as intended (So I thought).

 

What I found out though, is that only the Donut moves to the end of the Polyline. but the text of the donut is connected too stays in the exact same position, it is not moving with it. 

 

So that was my question.

 

Now for coming back with what I did with the block was: Delete the donut (Pline) and put 3 circles back instead. as you showed me. But none of the commands seems to work. I don't really know how to explain it better haha.

0 Likes
Message 22 of 33

Kent1Cooper
Consultant
Consultant

@t_pladet wrote:

.... only the Donut moves to the end of the Polyline. but the text of the donut is connected too stays in the exact same position, it is not moving with it. ....


I don't know what to suggest.  It works for me [I tried again from scratch, just to be sure].  I think that changing the insertion point of a Block using the (subst)/(entmod) method in entity data leaves Attributes not moved along with the rest of the Block, since they have their own entity data lists.  But for me, this approach takes the whole thing.  But I need to be Zoomed out to where they're all visible -- if not, I get an "ADS request error," but not the problem you describe.

Kent Cooper, AIA
0 Likes
Message 23 of 33

t_pladet
Contributor
Contributor
0 Likes
Message 24 of 33

komondormrex
Mentor
Mentor

hey,

cant understand what are you talking about. try using move_me_too custom command.

 

komondormrex_0-1699966925470.gif

 

0 Likes
Message 25 of 33

t_pladet
Contributor
Contributor

I tried copying your code of the 'move_me_too'  and make the lisp file out of it, but the 'move_me_too' command is not working at all for me. in the video you just send me it is working? weird..

0 Likes
Message 26 of 33

t_pladet
Contributor
Contributor

I tried copying your code of the 'move_me_too'  and make the lisp file out of it, but the 'move_me_too'command is not working at all for me. in the video you just send me it is working? weird..

0 Likes
Message 27 of 33

komondormrex
Mentor
Mentor
Accepted solution

you need to load remove_duplicates function too!

and hope you do not zeroed 'pickfirst variable! it must be set to 1 to use ssget mode "_i".

check update in message 10 with force setting 'pickfirst to 1.

Message 28 of 33

t_pladet
Contributor
Contributor

I forgot the first step of removing duplicates that you did before the move_me_too LISP! now it is working. But why would I have to run the remove duplictas lisp in the first place. can you elaborate? I am interested in why it would work after 🙂

0 Likes
Message 29 of 33

komondormrex
Mentor
Mentor

it is a function. once loaded it stays in memory for future use. you have to save both in one lisp file and load it when you want to use it. surely they may be joined in one command.

0 Likes
Message 30 of 33

komondormrex
Mentor
Mentor
Accepted solution

a joined version

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

(defun c:move_me_too (/ vertices_list insertion_point)

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

	(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
	)

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

	(setvar 'pickfirst 1)
	(prompt "\nSelect plines and blocks...")
	(sssetfirst nil (ssget '((0 . "insert,lwpolyline"))))
	(setq vertices_list 
		  (remove_duplicates 
		  		(vl-sort 
					(apply 'append (mapcar '(lambda (ename) (mapcar 'cdr (vl-remove-if-not '(lambda (group) (= 10 (car group))) (entget ename)))) 
					 	  		   			(vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget "_i" '((0 . "lwpolyline"))))))
				 		  		   )
					)
			 	   '(lambda (vertex_1 vertex_2) (< (car vertex_1) (car vertex_2)))
				)
		  )
	)
	(foreach insert (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget "_i" '((0 . "insert") (2 . "kabelid"))))))
		(setq insertion_point (cdr (assoc 10 (entget insert))))
		(setq closest_vertex (car (vl-sort vertices_list
										   '(lambda (vertex_1 vertex_2) (< (distance insertion_point vertex_1)
																		   (distance insertion_point vertex_2)
																		)
											)
								  )
							 )
			  vertices_list (vl-remove closest_vertex vertices_list) 
		)
		(vla-put-insertionpoint (vlax-ename->vla-object insert) (vlax-3d-point closest_vertex))
	)
	(sssetfirst)
	(princ)
)

;*****************************************************************************************************************************
Message 31 of 33

Kent1Cooper
Consultant
Consultant

Message 23 should not have been in Reply to me -- it uses the MOVEME command, which is not mine.  Mine [B2V] would possibly not work there, either, unless Zoomed out a lot farther, because it depends on insertion points being within Osnap Aperture distance from the Polyline vertices they should be moved to, as was always the case in the original sample drawing.

 

Was Message 19 also mistakenly in Reply to me, and based on something other than my command suggestion?

Kent Cooper, AIA
0 Likes
Message 32 of 33

komondormrex
Mentor
Mentor

hey,

another one that moves inserts to closest ends of nearest plines.

 

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

(defun c:move_insert_closest_plend (/ vertices_list insertion_point)

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

	(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
	)

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

	(setvar 'pickfirst 1)
	(prompt "\nSelect plines and blocks...")
	(sssetfirst nil (ssget '((0 . "insert,lwpolyline"))))
	(setq vertices_list 
		(remove_duplicates 
			(vl-sort 
				(apply 'append (mapcar '(lambda (_list) (list (car _list) (last _list)))
							 			(mapcar '(lambda (ename) (mapcar 'cdr (vl-remove-if-not '(lambda (group) (= 10 (car group))) 
																								 (entget ename)
																			  )
																 )
												 ) 
							 					 (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget "_i" '((0 . "lwpolyline"))))))
							 			)
							   )
				)
			   '(lambda (vertex_1 vertex_2) (< (car vertex_1) (car vertex_2)))
			)
		)
	)
	(foreach insert (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget "_i" '((0 . "insert") (2 . "kabelid"))))))
		(setq insertion_point (cdr (assoc 10 (entget insert))))
		(setq closest_vertex (car (vl-sort vertices_list
										   '(lambda (vertex_1 vertex_2) (< (distance insertion_point vertex_1)
																		   (distance insertion_point vertex_2)
																		)
											)
								  )
							 )
			  ;vertices_list (vl-remove closest_vertex vertices_list) 
		)
		(vla-put-insertionpoint (vlax-ename->vla-object insert) (vlax-3d-point closest_vertex))
	)
	(sssetfirst)
	(princ)
)

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

 

Message 33 of 33

t_pladet
Contributor
Contributor

Thank you very much! Really appreciate your help. Wish I could do something back for you haha

0 Likes