I want to replace text content with selection text using lisp

I want to replace text content with selection text using lisp

Anonymous
Not applicable
2,903 Views
8 Replies
Message 1 of 9

I want to replace text content with selection text using lisp

Anonymous
Not applicable

hi all,

I want to replace text content with selection text using lisp.

for example, like picture.

step1. select orgin text object

step2  select change text.

step3 result.

 

Thank you very much for reading my message and for your response.

1.png2.png3.png

 

0 Likes
2,904 Views
8 Replies
Replies (8)
Message 2 of 9

hak_vz
Advisor
Advisor

For a start try express tools command TCOUNT (use options:  y direction, start increment <1,1>  and overwrite).

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 9

Shneuph
Collaborator
Collaborator

I'm not sure what type of entities you're trying to copy to/from but this is one I use to just copy annotation w/o formatting etc.  In fact, it may get tripped up if there is formatting inside the text objects.  But, it works for what I use it for:

(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
	 (vl-string-search "BLOCK" (strcase (vla-get-objectname tlv-parent)))
	 (vla-put-textstring tlv-new TLV-Newstring)
	 (command "regenall")
	 );cond2
	);cond
      (vla-put-textstring tlv-new TLV-Newstring)
      );if
    );while
  (command "regenall")
  (princ)
  );defun
---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 4 of 9

Sea-Haven
Mentor
Mentor

This has been asked before you select column1 then column2 and result, only check is have same number of entries, have to go explore have pick column for something else.

 

Did you google. say "copy column text to new column".

0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

@hak_vz wrote:

.... express tools command TCOUNT ....


That raises the question:  @Anonymous , would the text content you want to impose onto other Text objects always be a sequence of integers, in order, as in your image?  If they might be something else, such as 6 3 1 8 9 4, or "Peter" "Paul" "Mary" "Manny" "Moe" "Jack", or I think even equal-difference real numbers such as 1.1 1.7 2.3 2.9 3.5 4.1, then TCOUNT won't help.

Kent Cooper, AIA
0 Likes
Message 6 of 9

Sea-Haven
Mentor
Mentor

Something like this it has no error checks or is ss1 count =ss2 you need to do that.

 

; copy column 1 text to column 2 text
; by Alanh Dec 2021

(defun c:tc2tc ( / ss ss2 lst1 lst2 ent x )
(prompt "\nSelect 1st column of text")
(setq ss (ssget '((0 . "TEXT"))))

(prompt "\nSelect 2nd column of text")
(setq ss2 (ssget '((0 . "TEXT"))))

(setq lst1 '())
(repeat (setq x (sslength ss))
(setq ent (entget (ssname ss (setq x (1- x)))))
(setq pt (cadr (cdr (assoc 10 ent))))
(setq txt (cdr (assoc 1 ent)))
(setq lst1 (cons (list pt txt) lst1))
)

(setq lst1 (vl-sort lst1 '(lambda (x y) (< (car x)(car y)))))

(setq lst2 '())
(repeat (setq x (sslength ss2))
(setq ent (entget (ssname ss2 (setq x (1- x)))))
(setq pt (cadr (cdr (assoc 10 ent))))
(setq ename (cdr (assoc -1 ent)))
(setq lst2 (cons (list pt ename) lst2))
)

(setq lst2 (vl-sort lst2 '(lambda (x y) (< (car x)(car y)))))

(repeat (setq x (length lst2))
(setq ent (entget (cadr (nth (setq x (1- x)) lst2))))
(entmod (subst (cons 1 (cadr (nth x lst1))) (assoc 1 ent) ent))
)

(princ)
)

(c:tc2tc)

 

0 Likes
Message 7 of 9

Anonymous
Not applicable

wow. It's perpectly working!
thank you for your response

0 Likes
Message 8 of 9

Anonymous
Not applicable
thank for yor response. it's helpful.
0 Likes
Message 9 of 9

Anonymous
Not applicable
thank you!
0 Likes