Jump to content

Recommended Posts

Posted

I'm trying to find a lisp routine that searches the current drawing for a certain string and replaces that with the string of a variable already defined by the user (in this case the text to look for is "****" and the variable is called "offerte"). Not only in the Text, Mtext but also in the Blocks, Dynamic blocks, attributes and fields...

Following code gets the job done but only for normal Text and Mtext.

 

(defun tekstreplace (/ tss tdata)
(setq tss (ssget "X" (list (cons 1 "****"))))
 	(repeat (sslength tss)
   		(setq
     			tdata (entget (ssname tss 0))
     			tdata (subst (cons 1 offerte) (assoc 1 tdata) tdata)
   		)
   		(entmod tdata)
   		(ssdel (ssname tss 0) tss)
 	)
)

 

Thanx in advance for any comments!

Posted

Well, i would really want it to be automated so the user isn't bothered with to much dialog boxes.

I did already perform a search on the site of Lee Mac, but without result for this specific issue.

I'm actually not sure if this is possible at all. As I've searched the Web, but didn't find any solution.

That's why I need some help from much more experienced lisp users than myself.

Again, any help or suggestions would be much appreciated!

Posted

found this one old lisp in my code library, try it on your end,

change old and new text values, block name to your suit

(vl-load-com)
(defun c:RTO  (/ ablocks acapp adoc blkdef blklist blkobj en i newtext oldtext sset)
(setq acapp (vlax-get-acad-object)
      adoc (vla-get-activedocument acapp)
      ablocks (vla-get-blocks adoc))
 
 
(setq oldtext  "ahha" newtext "new text");change to suit
(if (setq sset (ssget "_X" (list (cons 0  "INSERT")(cons 66  1)(cons 2  "`*U*,DynBlock"))));DynBlock is name for your interest
(progn
(setq i (sslength sset))
(while (setq en (ssname sset (setq i (1- i))))
(setq blkobj    (vlax-ename->vla-object en))
      (if (not (member "DynBlock" blklist)); use DynBlock only
 (setq blklist (cons (vla-get-effectivename blkobj) blklist)))
(ssdel en sset))
(repeat (length blklist)
 (if (not (vl-catch-all-error-p
  (setq blkdef (vl-catch-all-apply 'vla-item (list ablocks (nth 0 blklist))))))
 (progn
   (vlax-for a blkdef
     (if (eq "ACDBTEXT" (strcase (vla-get-objectname a)))
(if (eq oldtext (vla-get-textstring a))
(vla-put-textstring a newtext)))
(if (eq "ACDBMTEXT" (strcase (vla-get-objectname a)))
(if (eq oldtext (vla-get-textstring a))
(vla-put-textstring a newtext))))
     ))
 (setq blklist (cdr blklist)))
(command "_attsync" "_N" "*")
(command "_regenall")
)
)
(princ)
)

Posted

Thanks for your post fixo. I've implemented it into my code, but it didn't work out.

Maybe if you could specify what i should place instead of Dynblock. I've already tried ceveral blocknames that has been inserted into the drawing, but again no result.

I've also noticed that the searched string in a regular Mtext isn't changed as well. Could i be doing something wrong here?

Thanks in advanced for your much needed help!

Posted

Not sure but what did FIND do it certainaly changes attribute values in blocks.

Posted

I've tried every option available again, but still can't get above code to work??? @ BIGAL: You mean you do?

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...