Mtext Extract Colour Formatting and change the Colour Property LISP

Mtext Extract Colour Formatting and change the Colour Property LISP

larkins7XF7L
Explorer Explorer
807 Views
6 Replies
Message 1 of 7

Mtext Extract Colour Formatting and change the Colour Property LISP

larkins7XF7L
Explorer
Explorer

Hello,

I've been trying to understand how this would work most of today, and I think I finally semi-understand so I can explain.

 

My goal: Change the Property Colour to match the Mtext Format colour.

I have a bunch of MText that has their Format overwritten and I can see it in the Property panel

"\pxi-3,l3t3;\C3;\fCombiNumerals Pro|b1|i0;o"

Ignore everything except the \C3, that is what I am trying to get. All Mtext only contain 1 colour.

Does anyone know of a LISP that would be able to search multiple MText for that colour code, then change the Colour Property to match. To clarify Colour Property, I mean the colour you would select using the drop down in the Properties Panel or on your Toolbar.

It doesn't NEED to remove the \C# from the Contents, but that would just be a bonus.

 

Thanks!

0 Likes
Accepted solutions (1)
808 Views
6 Replies
Replies (6)
Message 2 of 7

komondormrex
Mentor
Mentor
0 Likes
Message 3 of 7

larkins7XF7L
Explorer
Explorer

That is partially what I am looking for, the other part is I want the Color Property to change to whatever the MText colour was. Or is that too complicated?

0 Likes
Message 4 of 7

komondormrex
Mentor
Mentor
Accepted solution

nope. for one forcing index color present.

 

 

 

(defun c:de_force_color_m_text (/ m_list m_string coloring_found color_pos color_index)
	(vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
	(setq m_list (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget "_:l" '((0 . "mtext")))))))
	(foreach m_ename m_list 
		(setq m_string (cdr (assoc 1 (entget m_ename))))
		(setq coloring_found nil)
		(while (or 
				(setq color_pos (vl-string-search "\\c" m_string))
				(setq color_pos (vl-string-search "\\C" m_string))
			)
					(setq color_index (substr m_string (+ 3 color_pos) (- (vl-string-search ";" m_string color_pos) color_pos 2))   
						  m_string (strcat (substr m_string 1 color_pos)
										   (substr m_string (+ 2 (vl-string-search ";" m_string color_pos)))
								   )
					      coloring_found (if (null coloring_found) t coloring_found) 
					)
		)
		(if coloring_found 
			(progn
		  		(vla-put-color (vlax-ename->vla-object m_ename) color_index)
		  		(vla-put-textstring (vlax-ename->vla-object m_ename) m_string)
		  	)
		)
	)
	(vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
	(princ)
)
Message 5 of 7

larkins7XF7L
Explorer
Explorer

Thank you for your help!

This worked great with a test MText except I get an error when attempting it on the example I included in the first post. "\pxi-3,l3t3;\C3;\fCombiNumerals Pro|b1|i0;o"

My guess after some testing is it has to do with the Font name starting with a C since other Fonts that start with C give the same error. Also if the Font has a C in the name anywhere else it deleted the text. 

 

Error: "Automation Error DISP_E_TYPEMISMATCH; [IAcadMText] Argument #0 can not be coerced to parameter in [COLOR] property.\n"

0 Likes
Message 6 of 7

komondormrex
Mentor
Mentor

check updated code above.

0 Likes
Message 7 of 7

larkins7XF7L
Explorer
Explorer

This worked perfectly! Thank you so much for the help, I really appreciate it.

0 Likes