.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to change a Mtext color

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
d_prontnicki
1129 Views, 4 Replies

How to change a Mtext color

Hi,

I have a sub that i found on this forum and use to change an mtext's color back to bylayer if portions of the text have been forced to another color. Meaning most of the text is by layer but maybe a user forced a word or sentence to red, or green, or something else. My question is this; with code below I need to account for any possible color, meaning I need to repeat the lines for each color. Obviously this is not ideal. Is there a way to say no matter the color make bylayer?

 

For Each selectedMtextObject As SelectedObject In acPromptResult.Value

                    Dim acMtext = CType(acTrans.GetObject(selectedMtextObject.ObjectId, OpenMode.ForWrite), MText)

                    acMtext.Contents = acMtext.Contents.Replace(MText.ColorChange & "1;", MText.ColorChange & "256;")
                    acMtext.Contents = acMtext.Contents.Replace(MText.ColorChange & "3;", MText.ColorChange & "256;")
                    acMtext.Contents = acMtext.Contents.Replace(MText.ColorChange & "10;", MText.ColorChange & "256;")

                Next

I feel like it something simple that I am missing...

 

Thank you

4 REPLIES 4
Message 2 of 5
kdub_nz
in reply to: d_prontnicki

 

 

Using Regex to change ANY color

perhaps something like :

 

acMtext.Contents = Regex.Replace(acMtext.Contents, @"\\C\d+;", MText.ColorChange + "256;");

 


// Called Kerry in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 3 of 5
d_prontnicki
in reply to: kdub_nz

@kdub_nz 

That did it, Thank you so much. Now I have some research/learning to do. Smiley Happy I have never used Regex before. 

Thank you again, I really appreciate it. 

Message 4 of 5
kdub_nz
in reply to: d_prontnicki

You're welcome.

This may be handy one day  https://www.regular-expressions.info/

You could also test that the original is within a range if that was required.

 

 


// Called Kerry in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 5 of 5
d_prontnicki
in reply to: kdub_nz

Thank you for the starting point. The page looks great! I will be reading this tonight. Smiley Happy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report