Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

change text (Any Text)

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
darryl.m.bowen
1016 Views, 12 Replies

change text (Any Text)

I used to work at a place that had a chgtxt command.  Plain and simple it would take the text selected regardless if it was in a block, title block, attributed, mtext, any text and change the next item you selected to match the one you picked initially but only the text not the size, color, font nothing but the text was changed.  

 

 

the command was called CD.  

 

would like it to be able to be done like this.

steps

1. type in command "cd"

2. click text I want

3. click text i need to be changed

4. done.

 

 

12 REPLIES 12
Message 2 of 13

Without knowing which Version, why not use the FIND (Find and Replace) Command?

 

 

Ribbon: Annotate tab>  Text panel > Find Text
Menu: Edit >  Find
ToolBar: Text Formatting
Shortcut Menu:With no commands active, right-click in the drawing area and click Find.

 

FYI...I'm using AutoCAD 2012.

If this response answers your question, Please mark this response as "Accept as Solution"

Rocky Brown
AutoCAD 2020 / Inventor 2020 / Plant 3D
Message 3 of 13

Something like this, perhaps?  EDIT: A more direct link to his site sub-page where VALATT.lsp can be downloaded.

Kent Cooper, AIA
Message 4 of 13
aqdam1978
in reply to: darryl.m.bowen

;matches two texts
;By Abbas Aqdam
(defun C:CD(/ v1 e1 t1 v2 e2 t2)
(while
	(setq v1 (cdr (assoc 1 (setq e1 (entget (car (nentsel "\nPlease choose the FIRST object: ")))))))
	(setq t1 (cdr (assoc 0 e1)))
	(princ (strcat "\nYour first selected object is <" t1 "> and its value is: \"" v1 "\""))(princ)
	(setq v2 (cdr (assoc 1 (setq e2 (entget (car (nentsel "\nPlease choose the SECOND object: ")))))))
	(setq t2 (cdr (assoc 0 e2)))
	(princ (strcat "\nYour second selected object is <" t2 "> and its value is: \"" v2 "\""))(princ)
	(entmod (subst (cons 1 v2) (assoc 1 e1) e1 ))
	(princ (strcat "\nThe first object: (" t1 ",\"" v1 "\") matched with the second object: (" t2 ",\"" v2 "\")"))(princ)
);;while
)

 

Message 5 of 13
Shneuph
in reply to: darryl.m.bowen

I changed this to work with dimensions but had to remove the nentsel so now it doesn't work with block attributes.  Can someone help to either A: Get the dimension object when using nentsel and selecting dimension text to change the dimension's textoverride property or B: choose whether to use entsel or nentsel depending on whether the user picks a block or other object?

 

(Defun C:TLC-Copy_Annotation (/ TLV-new TLV-Newstring TLV-txt2)
  ;(vl-load-com)
  (while (not TLV-new)
    (setq TLV-new (vlax-ename->vla-object (car (nentsel "\nSelect Object w/ Desired Annotation:  "))))
    (terpri)
    (princ (vla-get-objectname TLV-new))(princ)
    );while

  (setq TLV-Newstring (vla-get-textstring TLV-new))

  ;remove formatting
  (if (= (vl-string-search "\\" tlv-newstring) 0)
    (Setq tlv-newstring (substr tlv-newstring (+ 2 (vl-string-search ";" tlv-newstring))))
    );if

  (while (setq TLV-txt2 (vlax-ename->vla-object (car (entsel "\nSelect Text to Insert Annontation:  "))))
    (if (vl-string-search "DIMENSION" (strcase (vla-get-objectname tlv-txt2)))
      (vla-put-textoverride TLV-txt2 TLV-Newstring)
      (vla-put-textstring TLV-txt2 TLV-Newstring)
      );if
    );while
  (princ)
  );defun

 Also, anyone have tips for a better [more thorough] /easier way to remove formatting from the textstring?

Message 6 of 13
mid-awe
in reply to: darryl.m.bowen

I often hold the <CTRL> key down and double click the text I want to edit. Seems to work fine. I can't say how far down in nesting it will work but it's worth a try for convienience at least.

Message 7 of 13

find and replace will work for basic text, but I am looking for something that will change text that in a block that can not be changed unless you explode the block, the command/lips i am looking for will change "ANY TEXT" in the drawing.  can be a very dangrous command because of that ...

Message 8 of 13

You should get the following dialog when you click "Replace All" on the Find and Replace Dialog box. Make sure that "Replace text in all blocks" is selected (or either of the other two options if they apply). This works for me (AutoCAD 2012) with static text, mtext, and attribute values. It also works in dimensions where I add text with the default dimension value.

 

Also, if you are exploding blocks, whe not open them in Block Editor (bedit)?

If this response answers your question, Please mark this response as "Accept as Solution"

Rocky Brown
AutoCAD 2020 / Inventor 2020 / Plant 3D
Message 9 of 13
aqdam1978
in reply to: darryl.m.bowen

Hi,

 

Did you tried my lisp?

That is exactly what you describe in your post:

 

--------------------------------------------------------------

the command was called CD.  

 

would like it to be able to be done like this.

steps

1. type in command "cd"

2. click text I want

3. click text i need to be changed

4. done.

-------------------------------------------------------------- 

 


No feedback from you?

Message 10 of 13
Shneuph
in reply to: darryl.m.bowen

Try this now Darryl... Seems to be working..

 

(Defun C:TLC-Copy_Annotation (/ TLV-new TLV-NentSelList tlv-Parent TLV-Newstring TLV-txt2)
  ;(vl-load-com)
  (while (not TLV-new)
    (setq TLV-new (vlax-ename->vla-object (car (nentsel "\nSelect Object w/ Desired Annotation:  "))))
    (terpri)
    (princ (vla-get-objectname TLV-new))(princ)
    );while

  (setq TLV-Newstring (vla-get-textstring TLV-new))

  ;remove formatting
  (if (= (vl-string-search "\\" tlv-newstring) 0)
    (Setq tlv-newstring (substr tlv-newstring (+ 2 (vl-string-search ";" tlv-newstring))))
    );if

  (while (setq TLV-NentSelList (nentsel "\nSelect Text to Insert Annontation:  "))
    (if (> (length TLV-NentSelList) 2)
      (progn
	(Setq tlv-new (vlax-ename->vla-object (car tlv-nentsellist)))
	(Setq tlv-Parent (vlax-ename->vla-object (car (car (reverse tlv-nentsellist)))))
	);progn
      (Setq tlv-new (vlax-ename->vla-object (car tlv-nentsellist)))
      );if
    (if tlv-parent
      (cond
	(;cond1
	 (vl-string-search "DIMENSION" (strcase (vla-get-objectname tlv-parent)))
	 (vla-put-textoverride TLV-Parent TLV-Newstring)
	 );cond1
	(;cond2
	 (= (STRCASE (vla-get-objectname tlv-parent)) "ACDBBLOCKREFERENCE")
	 (vla-put-textstring tlv-new TLV-Newstring)
	 );cond2
	);cond
      (vla-put-textstring tlv-new TLV-Newstring)
      );if
    );while
  (princ)
  );defun

 

Message 11 of 13

shneuph - works good, but will not grab the text in the blocks.  but I will be using it cause I really do not need the text in blocks changes.

 

thank you.  and will be kudos coming your way.

 

Aqdam1978 - works but is backwards, the text I click on first is the text Id like to keep, the second click would be chnnged to the information of the first click...

 

should be source first then destination. but it still works just backwards for me.  

Message 12 of 13
Shneuph
in reply to: darryl.m.bowen

I have blocks that this does not work with as well.  It is due to the fact that I have a hatch in the block.  Eventhough the hantch is behind (draworder) the attribute.  The lisp does not select the attribute.. it selects the hatch.  It works if I set fillmode to 0 (turns hatches off)

 

Maybe this is the problem w/ your blocks as well?

 

Edit:

  oh.  I think I see what you are saying.  You have actual text objects in the block which are not attributes... back to the drawing board.

 

Edit2:

  Looks like it is working for me.  Try regen after running the lisp?

Message 13 of 13
mid-awe
in reply to: Shneuph

Or, ATTSYNC?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost