I need a Lisp to copy a number and paste in another object

I need a Lisp to copy a number and paste in another object

mmprakash90
Participant Participant
1,821 Views
20 Replies
Message 1 of 21

I need a Lisp to copy a number and paste in another object

mmprakash90
Participant
Participant

Hi All,

 

I have a scenario where I need a Lisp program to copy and paste within same DWG

 

In a DWG I have a number for

EX :123456

And another object like ADD=XXXXXX 

Now , I want that 123456 in the place of XXXXXX like ADD= 123456 in just two three clicks

 

Need your help

 

 

 

 

0 Likes
Accepted solutions (2)
1,822 Views
20 Replies
Replies (20)
Message 21 of 21

komondormrex
Mentor
Mentor

check the following code

(defun c:replace_X-X ( / num_text num_string start_x_pos end_x_pos target_string target_dxf)
	(while (setq num_text (car (entsel "\nPick text with number to get from: ")))
	 	   (setq num_string (cdr (assoc 1 (entget num_text))))
	 		(while (null (setq start_x_pos (acet-str-find "[xX]+" 
							(cdr
							  (cond
							     ((setq target_string_group 
				  				  	(assoc 1 (setq target_dxf 
											(entget (car (entsel (strcat "\nPick text to replace \"X...X\" with \"" 
															  num_string 
															  "\": "
													     )
												     )
												)
											)
		  								 )
				  					)
							        )
							      )
							      ((setq target_string_group (assoc 304 target_dxf)))
							     )
					  		  ) t t
							)
							end_x_pos start_x_pos 
			 		)
				)
			  )
	 		  (entmod (subst (cons (car target_string_group) (vl-string-subst 
					 					num_string 
					 					(substr (cdr target_string_group) 
				 								start_x_pos
												(progn
												  (while (or (= "X" (substr (cdr target_string_group) (setq end_x_pos (1+ end_x_pos)) 1)) 
													     (= "x" (substr (cdr target_string_group) end_x_pos 1)) 
													 )
												  )
												  (- end_x_pos start_x_pos)
												)
										)
										(cdr target_string_group)
					 				)
					) 
					target_string_group 
					target_dxf
			 	)
	 		  )
	 )
	 (princ)
)
0 Likes