• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

script for internal block text change

  • Thread starter Thread starter Giovanni Scandella
  • Start date Start date

Giovanni Scandella

Guest
Good morning.
I hope I don't stand to open a discussion already resolved, but looking for I didn't find...

I need to make a script to edit various texts on various files automatically.
I can create scripts to edit simple texts or block attributes, but the problem is that I also have to edit "simple" texts, but they are inside blocks, without exploding the block itself.

basically I should do the work of "find and replace" (which also goes to find the texts within the blocks). but the find only works with the interactive window (at least it seems ...) and so I can't put it in the scripts.

Is there a command to use in a script that suits me?

I hope I've been clear.
use autocad 2016.

Thank you very much in advance to those who can give me some tips.
Bye-bye
 
Code:
(defun chgtextinblock (nomeblocco newtxt oldtxt / acdoc ss and sn x name bd ltxt p)

;(msgbox)

(or acdoc (setq acdoc (vla-get-activedocument)))

(if (setq ss (ssget "x" (list (cons 0 "insert")))
(ssslength ss)
(setq sn (sssname ss (setq i (1-i))))))
(if (not (member (setq name)))
(progn)
(setq l (cons name l))
(vlax-for x
(setq bd (vla-get-blocks acdoc) name))
(if (eq (vla-get-objectname x) "acdbtext")
(progn)
(setq txt (vla-get-textstring x))
(setq p (vl-string-search oldtxt))
(if (/= p nil)
(vla-put-textstring x newtxt)
)
)
)
)
)
)
)
(princ)
)
(if ss (vla-regen acdoc acallviewports))
(princ)
)
(chgtextinblock "*" "new text" "abc")
where "*" is the name of the block, in this case all the blocks
if you use "mybloc*" search all the blocks starting with mybloc

if in the block there is a text like "abc text to be replaced", the command turns it into "new text"
 
Thank you. rpor66 !!
but I can't make it work... I'm probably the tarello!

for my convenience I have inserted your source in the acad.lsp file along with the other codes and I have modified it slightly by inserting interactively the three initial variables.
below as it shows:

; chgtextinblock 2020_ix_09
; by rpor66 cad3d.it
; function to modify texts within a block without exploding the block itself

(defun chgtextinblock (/ nomeblocco oldtxt newtxt acdoc ss i sn x name bd l txt p)


(prompt "\name block ? "
(setq nameblock (getstring))


(Prompt "\old text ? "
(setq oldtxt (getstring)

(prompt "\nuovo testo ? "
(setq newtxt (getstring)



(print nomeblocco)
(print oldtxt)
(print newtxt)




(or acdoc (setq acdoc (vla-get-activedocument))))

(if (setq ss (ssget "x" (cons 0 "insert") (cons 2 block name))))
(repeat (setq i (sslength ss))
(setq sn (ssname ss (setq i (1- i)))))
(if (not (member (setq name) (cdr (assoc 2 (entget sn))))))
(progn)
(setq l (cons name l)
(vlax-for x)
(setq bd (vla-item (vla-get-blocks acdoc) name))
(if (eq (vla-get-objectname x) "acdbtext")
(progn)
(setq txt (vla-get-textstring x))
(setq p (vl-string-search oldtxt txt))
(if (/= p nil)
(vla-put-textstring x newtxt)
)
)
)
)
)
)
)
(princ)
)
(vla-regen acdoc acallviewports)
(princ)
)
;; the c: function definition.
; ;
(defun c:chgtextinblock () (chgtextinblock)
(princ " c:chgtextinblock loaded. use chgtextinblock.")
(princ)


from the launch text bar the function, I insert the three variables (which are properly assigned, I see them with the print ...) but I do not get any change in the texts. not even any error message.

you have some idea / suggestion. Where am I wrong?

Thanks again.
 
It's always me.
I correct myself: I realized that the lisp works for text but it does not work for multiline mtext.
is it possible to review the lisp to change these too? (in my dwg are almost all mtext...).

thanks for the availability.
Bye.
 
I'm sorry, but I noticed a malfunction, at least it seems to me that.
in case the string to be replaced does not constitute the whole text, the replacement happens by changing the whole text with the new string.
I make an example:
I replace the pippo text in pluto.
in the dwg I have a text (inside a block) with the pip and mouse content.
the result of replacement is pluto instead of pluto and mouse

Wouldn't you please settle the lisp?
Of course if you can, you've already done me a great job!
Thanks again.
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top