I am making a tool to draw text along plines, and need to split my strings to charcaters.
I know to look for %%D, %%C and several others, but I am wondering if there is a way to detect the difference between the original string charcater count, and the one acad would draw with a given text style.
If the lengths were different, I could check for sequences and handle.
I want to avoid checking every time though, and also detect when some exotic sequence got in that I was not checking for.
lisp or .net....
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
Hi, James
I didn't find .net example here is just C# snip:
//using System.Text.RegularExpressions; //string text = "200%%C"; string text ="200%%D"; string pattern = @"(.*?)%%[D,C]"; int dia = 0; MessageBox.Show(text.Contains("%%D").ToString()); Regex.Matches(text, pattern).Cast<Match>().All((Match m) => { dia = Convert.ToInt32(m.Groups[1].Value); return true; }); MessageBox.Show(dia.ToString());
That's slick code, and I will add to my c# library of string extensions.
It approaches things from a standpoint of knowing what to look for though.
What if I said "are there any sequences in some string that get converted to one character, or disappear altogether?"
Things like %%U and %%D.
The only way to test that would be some function that looked at the final text value and gave back ascii character values of final string.
%%D seems the same as (chr 176), but I wonder how dependednt this all is on the font.
What if autodesk changes the allowed sequences in strings?
We really need something that gets down to the final characters being displayed. For mtext too...
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
dim is as dim does, so GET CRACKING!!!!!
kidding, thx for the help so far 🙂
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
sure:
"try this /U+0178"
you see, I have no idea if /U+0178 is a special code that will show as one character, or a typo and it should be /U+0128 or something.
Sequences we think will transform to a character may or may not work in a given environment.
So if my task is to split a string into actual characters that will be drawn, I cannot assume anything.
I will check with Kean W on this, seems like this has come up a while back with .net.
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
In terms of .NET API (I know this thread is still in LISP forum), the TextEditor.Selection.RemoveAllFormatting() Method may be of use here.
"How we think determines what we do, and what we do determines what we get."
I think that was what I recalled, but does not pertain to the special character sequences unfortunately.
This might be a tougher question than I thought.
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
@Anonymous wrote:I think that was what I recalled, but does not pertain to the special character sequences unfortunately.
This might be a tougher question than I thought.
It may very well be; I only meant that the aforementioned Method could be used to quickly strip the text formatting for Text and MText, and then you need only account for the special characters you previously noted (perhaps I misunderstood your comment to mean you've identified all of them?).
Cheers
"How we think determines what we do, and what we do determines what we get."
@Anonymous wrote:
I am making a tool to draw text along plines, and need to split my strings to charcaters.
....
Give this a shot -- StringToSeparateCharacters.lsp with is (S2SC) function. It separates a Text string into strings representing each individual character, including keeping %%D together as a character [as well as %%P & %%C & %%%], likewise %%### special characters and Unicode characters, and retaining under- and/or over-scoring for each character that is within a portion of the original string that has either or both of those.
Make a piece of Text including some special characters, Unicode characters, some combination(s) of under- and/or over-scoring, etc.
Two additional commands are included, not needed as part of the routine itself, but to show what it does:
The S2SCTEST command will ask you to select a piece of Text, and show you the resulting list of the individual characters and special- or Unicode-character strings.
The S2SCDEMO command will ask you to select a piece of Text, and place a series of individual-character Text entities below it, something like what you might use to spread along a Polyline [but here in a straight line, and equally spaced ignoring differences in character width], to demonstrate the preservation of special characters, underlining, etc.
It doesn't work with internal formatting inside Mtext [see comment near top of file], but it does work with Mtext content if it doesn't have any of that. And of course it will work with a text string not associated with an existing Text/Mtext entity, such as might be prompted from a User or constructed within a routine.
Can't find what you're looking for? Ask the community or share your knowledge.