Command line find and replace for Multileader text

Command line find and replace for Multileader text

Joel_S_Hills
Enthusiast Enthusiast
1,598 Views
7 Replies
Message 1 of 8

Command line find and replace for Multileader text

Joel_S_Hills
Enthusiast
Enthusiast

So far the lisp files I have found wont address the contents of a multileader for find and replace. The only command I found that does it reliably is the FIND (command) but I cant send lisp code to that.

 

Has anyone made something that works?

0 Likes
1,599 Views
7 Replies
Replies (7)
Message 2 of 8

pbejse
Mentor
Mentor

@Joel_S_Hills wrote:

So far the lisp files I have found wont address the contents of a multileader for find and replace. The only command I found that does it reliably is the FIND (command) but I cant send lisp code to that.

 

Has anyone made something that works?


Is that just using textstring and/or ContentBlockName?

 

 

0 Likes
Message 3 of 8

Kent1Cooper
Consultant
Consultant

How 'bout this?  It's unlike FIND in that it just replaces them all, rather than letting you look around and decide for each instance.  So maybe this is just a starting point....

(defun C:MLFR ; = MultiLeader Find/Replace
  (/ old new ss n mldata)
  (setq
    old (getstring T "\nText content to be replaced: ")
    new (getstring T "\nText content to replace it with: ")
  ); setq
  (if (setq ss (ssget "_X" (list '(0 . "MULTILEADER") (cons 304 (strcat "*" old "*")))))
    (repeat (setq n (sslength ss))
      (setq mldata (entget (ssname ss (setq n (1- n)))))
      (entmod
        (subst
          (cons 304 (vl-string-subst new old (cdr (assoc 304 mldata))))
          (assoc 304 mldata)
          mldata
        ); subst
      ); entmod
    ); repeat
  ); if
  (princ)
); defun

AND, I find in quickie trial that it doesn't affect the arrows associated with the Mleader, so if the result changes the length noticeably, the arrows don't attach right.  But if I just tweak the "box" width for it, they fix themselves.

Kent Cooper, AIA
0 Likes
Message 4 of 8

dbhunia
Advisor
Advisor

To Find and Replace whole matching Text, try this.......

 

(defun C:MLTRA ( / Txt_Find Txt_Repl ss) ;; MultiLeader Text Replace All
	(setq Txt_Find (getstring t "\nMultileader Text to Replace: "))
	(setq Txt_Repl (getstring t "\nMultileader Text to Replace With: "))
	(if (setq ss (ssget "_A" (list '(0 . "MULTILEADER") (cons 304 Txt_Find))))
		(foreach Ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
			(vla-put-textstring (vlax-ename->vla-object Ent) Txt_Repl)
		)
	)
	(princ)
)

To Find and Replace a part of matching Text with all occurrences , try this.......

 

(defun C:MLTRP ( / Txt_Find Txt_Repl ss obj txt_str) ;; MultiLeader Text Replace Part
	(setq Txt_Find (getstring t "\nMultileader Text to Replace: "))
	(setq Txt_Repl (getstring t "\nMultileader Text to Replace With: "))
	(if (setq ss (ssget "_A" (list '(0 . "MULTILEADER") (cons 304 (strcat "*" Txt_Find "*")))))
		(foreach Ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
			(setq txt_str (vla-get-textstring (setq obj (vlax-ename->vla-object Ent))))
			(while (vl-string-search Txt_Find txt_str)
				(setq txt_str (vl-string-subst Txt_Repl Txt_Find txt_str))
			)
			(vla-put-textstring obj txt_str)
		)
	)
	(princ)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 8

Joel_S_Hills
Enthusiast
Enthusiast

Thanks, both of you! So far this one is working the closest of what I need,

(defun C:MLTRP ( / Txt_Find Txt_Repl ss obj txt_str) ;; MultiLeader Text Replace Part
	(setq Txt_Find (getstring t "\nMultileader Text to Replace: "))
	(setq Txt_Repl (getstring t "\nMultileader Text to Replace With: "))
	(if (setq ss (ssget "_A" (list '(0 . "MULTILEADER") (cons 304 (strcat "*" Txt_Find "*")))))
		(foreach Ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
			(setq txt_str (vla-get-textstring (setq obj (vlax-ename->vla-object Ent))))
			(while (vl-string-search Txt_Find txt_str)
				(setq txt_str (vl-string-subst Txt_Repl Txt_Find txt_str))
			)
			(vla-put-textstring obj txt_str)
		)
	)
	(princ)
)

 

 One snag, I see is I am trying to also replace text with field formatting, Closest example I see is using this as the new text %<\AcVar Date \f "M/d/yy">%, the field will populate, but just show as ####, is there a way to refresh the field?

0 Likes
Message 6 of 8

dlanorh
Advisor
Advisor
A regen or a regenall should do it.

I am not one of the robots you're looking for

0 Likes
Message 7 of 8

Joel_S_Hills
Enthusiast
Enthusiast

"A regen or a regenall should do it", This dosen't work at all, also closing and reopening the drawing dosent work, but if you double clock the field it will refresh

0 Likes
Message 8 of 8

Joel_S_Hills
Enthusiast
Enthusiast

originally I was changing textstring, haven't thought about block content

0 Likes