Lisp to Change Mtext Format

Lisp to Change Mtext Format

hythamthelove
Advocate Advocate
3,264 Views
11 Replies
Message 1 of 12

Lisp to Change Mtext Format

hythamthelove
Advocate
Advocate

Hello everyone,

 

I am looking for a lisp to change the format of the Mtext in white to the Mtext in blue, of course i am not talking about the colour but about the format itself. The green clouds shows the parts that are common between both of them and the red clouds shows the diffirences between the two formats. Btw the numbers and texts of the white Mtext can change but generaly the format will be the same for example T12 can be T16 or B can be T or @150 can be @Anonymous and so on but generally they will have the same format. Is there is a lisp that changes the format of the Mtext to white to match the one on blue and make the needed changes ?

 

Thanks in advance

1.PNG

 

0 Likes
Accepted solutions (3)
3,265 Views
11 Replies
Replies (11)
Message 2 of 12

ronjonp
Advisor
Advisor

Can you simply put those items on another layer that is blue?

0 Likes
Message 3 of 12

hythamthelove
Advocate
Advocate

yes sure the color of the mtext is not a problem i will match them easily but the format it self is what i am asking about. Btw i am a huge fan of your work i see your replies to people you are really great and your replies to others helped me alot

0 Likes
Message 4 of 12

ronjonp
Advisor
Advisor

Thanks for the kind words :). Can you post a sample drawing? If there is internal formatting on MTEXT, this causes other hurdles.

0 Likes
Message 5 of 12

hythamthelove
Advocate
Advocate

To give you a wider vision, i actually have the orange text, but i can simply use the match order to make it match with the blue text, but just the formatting and the arrangement of the text is what i care about as explained in the post 

2.PNG

0 Likes
Message 6 of 12

ronjonp
Advisor
Advisor
Accepted solution

Here's a quick one to help with the formatting:

 

 

(defun c:foo (/ a b o s st)
  (if (setq s (ssget "_:L" '((0 . "*TEXT") (1 . "*x*`@*"))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (setq st (vla-get-textstring (setq o (vlax-ename->vla-object e))))
      (setq a (substr st 1 (vl-string-position (ascii "x") st)))
      (setq b (substr st (1+ (vl-string-position (ascii "@") st))))
      (vla-put-textstring
	o
	(strcat a (substr b 1 (1- (strlen b))) " (" (substr b (strlen b)) ")\\PL= 6000mm")
      )
    )
  )
  (princ)
)

 

 

Message 7 of 12

hythamthelove
Advocate
Advocate
Accepted solution

This is really great you are brilliant, but there is a case that does not work like the attached photo. because the number is not 1 digit ( it is 2.55 instead of 6 in the previous example) so it does not work. can you make changes so that the lisp takes any number between "x" and "@" and this number to be multiplied by 1000 and be put in the proper format ? i don't know if that is possible but you are really graeat and really i appreciate your efforts 3.PNG

0 Likes
Message 8 of 12

ronjonp
Advisor
Advisor

Use the code above again .. it just needed the mtext filter to be updated.

2021-08-23_16-02-09.gif

0 Likes
Message 9 of 12

hythamthelove
Advocate
Advocate

ok i did, but it should give L=2550 (like the one i green) instead of L=6000 . i am really sorry for bothering you that much but i really appreciate your efforts.

4.PNG

0 Likes
Message 10 of 12

ronjonp
Advisor
Advisor
Accepted solution

I gotcha ... try this:

 

(defun c:foo (/ a b c o s st)
  (if (setq s (ssget "_:L" '((0 . "*TEXT") (1 . "*x*`@*"))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (setq st (vla-get-textstring (setq o (vlax-ename->vla-object e))))
      (setq a (substr st 1 (setq c (vl-string-position (ascii "x") st))))
      (setq b (substr st (setq d (1+ (vl-string-position (ascii "@") st)))))
      (setq c (substr st (+ 2 c)))
      (if (numberp (setq c (read (substr c 1 (vl-string-position (ascii "@") c)))))
	(vla-put-textstring
	  o
	  (strcat a
		  (substr b 1 (1- (strlen b)))
		  " ("
		  (substr b (strlen b))
		  ")\\PL= "
		  (itoa (fix (* 1000 c)))
		  "mm"
	  )
	)
      )
    )
  )
  (princ)
)

 

Message 11 of 12

hythamthelove
Advocate
Advocate

This is really brilliant. You are the best. Thank you so much 😍

0 Likes
Message 12 of 12

ronjonp
Advisor
Advisor

@hythamthelove wrote:

This is really brilliant. You are the best. Thank you so much 😍


Glad to help. 🍻