Jump to content

Recommended Posts

Posted

Hi

 

Is there a way to match text entity, but keep Alphabets for the second text?

For example i have text 123.50 , the second entity is CL1.50. The result I am looking to get is CL123.50

I am using this lisp command currently and adding text prefix after matching the text. Hoping you all could help me to get around it?

 

(defun c:mt  (/ cEnt mEnt)
 (if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
          (member (cdr (assoc 0 (entget cEnt)))
                  '("TEXT" "MTEXT" "ATTRIB")))
   (progn
     (redraw cEnt 3)
     (while (and (setq mEnt (car (nentsel "\nSelect Destination Text: ")))
                 (member (cdr (assoc 0 (entget mEnt)))
                         '("TEXT" "MTEXT" "ATTRIB")))
       (entmod (subst (assoc 1 (entget cEnt))
                      (assoc 1 (entget mEnt))
                      (entget mEnt))))
     (redraw cEnt 4))
   (princ "\n<!> Incorrect Selection <!>"))
 (princ))

 

 

Posted (edited)

Like this?

 

What it does:

I expect 1number between a prefix and postfix (both of which can be empty)

 

So for example: destination = 23.6GT56, source = 123.50 => result = 123.50GT56
From the moment the number starts the prefix ends; from the moment the number stops then all the rest is postfix.

 

It doesn't see 12E+3 (which is 12000) as a number.  That's a TODO.

 

(defun c:mt  (/ cEnt mEnt newString)
	(if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))		;; user selects source TEXT/MTEXT/ATTRIB cEnt
		  (member (cdr (assoc 0 (entget cEnt)))
				  '("TEXT" "MTEXT" "ATTRIB")))
		(progn
			(redraw cEnt 3)
			(while (and (setq mEnt (car (nentsel "\nSelect Destination Text: ")))	;; user selects destination TEXT/MTEXT/ATTRIB mEnt
						 (member (cdr (assoc 0 (entget mEnt)))
								 '("TEXT" "MTEXT" "ATTRIB")))
								 
				(setq newString (keepAlphabets 
						(cdr (assoc 1 (entget cEnt))) 
						(cdr (assoc 1 (entget mEnt)))
				))				 
				(princ newString)				 
			    (entmod (subst 
						(cons 1 newString)
						(assoc 1 (entget mEnt))
						(entget mEnt)
				))
			)
		 (redraw cEnt 4)
		)
	(princ "\n<!> Incorrect Selection <!>")
	)
	(princ)
)

;; For example src = "123.50" , dest = "CL1.50TG" . result = "CL123.50TG"
(defun keepAlphabets ( src dest / chars a prefix num post)
	(setq prefix "")
	(setq num "")
	(setq post "")
	;; string to characters list
	(setq chars (vl-string->list  dest))
	(foreach a chars
		(if (and (= post "") (or (= a 46) (< 47 a 58)))		;; character is a "." or [0->9].  Skip this if the postcript has started
			(progn
				(setq num (strcat num (chr a)))
			)
			(progn
				(if (= num "")
					(setq prefix (strcat prefix (chr a)))
					(setq post (strcat post (chr a)))
				)
			)
		)
	
	)
	(strcat prefix src post)
)

 

Edited by Emmanuel Delay
  • Thanks 1
Posted
12 hours ago, Emmanuel Delay said:

Like this?

 

What it does:

I expect 1number between a prefix and postfix (both of which can be empty)

 

So for example: destination = 23.6GT56, source = 123.50 => result = 123.50GT56
From the moment the number starts the prefix ends; from the moment the number stops then all the rest is postfix.

 

It doesn't see 12E+3 (which is 12000) as a number.  That's a TODO.

 

(defun c:mt  (/ cEnt mEnt newString)
	(if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))		;; user selects source TEXT/MTEXT/ATTRIB cEnt
		  (member (cdr (assoc 0 (entget cEnt)))
				  '("TEXT" "MTEXT" "ATTRIB")))
		(progn
			(redraw cEnt 3)
			(while (and (setq mEnt (car (nentsel "\nSelect Destination Text: ")))	;; user selects destination TEXT/MTEXT/ATTRIB mEnt
						 (member (cdr (assoc 0 (entget mEnt)))
								 '("TEXT" "MTEXT" "ATTRIB")))
								 
				(setq newString (keepAlphabets 
						(cdr (assoc 1 (entget cEnt))) 
						(cdr (assoc 1 (entget mEnt)))
				))				 
				(princ newString)				 
			    (entmod (subst 
						(cons 1 newString)
						(assoc 1 (entget mEnt))
						(entget mEnt)
				))
			)
		 (redraw cEnt 4)
		)
	(princ "\n<!> Incorrect Selection <!>")
	)
	(princ)
)

;; For example src = "123.50" , dest = "CL1.50TG" . result = "CL123.50TG"
(defun keepAlphabets ( src dest / chars a prefix num post)
	(setq prefix "")
	(setq num "")
	(setq post "")
	;; string to characters list
	(setq chars (vl-string->list  dest))
	(foreach a chars
		(if (and (= post "") (or (= a 46) (< 47 a 58)))		;; character is a "." or [0->9].  Skip this if the postcript has started
			(progn
				(setq num (strcat num (chr a)))
			)
			(progn
				(if (= num "")
					(setq prefix (strcat prefix (chr a)))
					(setq post (strcat post (chr a)))
				)
			)
		)
	
	)
	(strcat prefix src post)
)

 

 

 

Emmanuel Delay, Thank you very much for your Help! It works excellent! :)

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...