last selected text

last selected text

Anonymous
Not applicable
1,158 Views
6 Replies
Message 1 of 7

last selected text

Anonymous
Not applicable

 

I have lisp routine that request the user to select a close polyline and this polyline is around  one text and nothing else. once the user select the polyline the code will drop the selection of the polyline and select the text inside of it. Also, I have a function that accept two string and replace the first string with the second text string. (f2 "old string" "new string")

 

Now that I have the text selected how do i use this last selection to feed it the function as a string to replace this text with new preset string. 

 

0 Likes
Accepted solutions (2)
1,159 Views
6 Replies
Replies (6)
Message 2 of 7

pbejse
Mentor
Mentor

@Anonymous wrote:

 

I have lisp routine that request the user to select a close polyline and this polyline is around  one text and nothing else. once the user select the polyline the code will drop the selection of the polyline and select the text inside of it. Also, I have a function that accept two string and replace the first string with the second text string. (f2 "old string" "new string")

 

Now that I have the text selected how do i use this last selection to feed it the function as a string to replace this text with new preset string. 

 


 

Where is that lisp?

And where is that function?

 

Post the above codes and we will piece it together for you.

 

 

 

 

0 Likes
Message 3 of 7

Anonymous
Not applicable

Here is the routine called "change it" which is my attempt to do that. the function pts will select anything enclosed in a polyline and in this case it will be just the text. the function f2 is to replace old with new. 

0 Likes
Message 4 of 7

pbejse
Mentor
Mentor

 

Are you wanting this to work on multiple polylines or single selection?

 

 

0 Likes
Message 5 of 7

Anonymous
Not applicable

This is the first step. Idont want to select all polyline or text manually. I will have to eventually change how the function pts work to make it work on all similar polyline shape using (commagd Similar " """ ")

0 Likes
Message 6 of 7

pbejse
Mentor
Mentor
Accepted solution

use this as your starting point

 

(defun c:changeit ( / pl ptlist ss )
(if   
	(and (setq pl (ssget "_:S:E" '((0 . "LWPOLYLINE"))))
	     (setq ptlist (mapcar 'cdr
				     (vl-remove-if-not
				       '(lambda	(x)
					  (= (car x) 10)
					)
				       (entget (ssname pl 0))
					     )
				     )
			)
	     (setq ss (ssget "_CP" ptlist '((0 . "TEXT,MTEXT"))))
	       	)
  	(foreach itm '(("58" "(4-D1)")("61" "(4-D1)"))
	  	(f2 ss (CAr itm)(cadr itm))
	  )
  	)
  )

(defun f2 (selset OldTxt NewTxt) ;function that will replace old with new text
	(if selset
	    (progn
		(setq i (sslength selset))
		(while (not (minusp (setq i (1- i))))
			(setq oText (vlax-ename->vla-object (ssname selset i)))
			(setq Txt (vlax-get-property oText 'TextString))
			
			(if (vl-string-search OldTxt txt)
				(progn
					(setq newChg (vl-string-subst NewTxt OldTxt txt))
					(vlax-put-property oText 'TextString newchg)
					(vlax-invoke-method oText 'Update)
				)
			)
		)
	      )
	  )
	(princ)
)
    

 

 

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

Here is the routine called "change it" which is my attempt to do that. the function pts will select anything enclosed in a polyline and in this case it will be just the text. the function f2 is to replace old with new. 


 

You're going to need to change what the f2 function does -- it's built to do it to all  Text/Mtext in the entire drawing.  Do you want to change it to lose that do-it-all capability, or to keep it as it is and define a different  [but similar] function for the single object found inside your Polyline?

Kent Cooper, AIA
0 Likes