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
Solved! Go to Solution.
Solved by kdub_nz. Go to Solution.
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
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
Thank you for the starting point. The page looks great! I will be reading this tonight.
Can't find what you're looking for? Ask the community or share your knowledge.