Author Topic: [RESOLVED] That is a BOLD statement sir...  (Read 2099 times)

Castleberg

  • Newbie
  • *
  • Posts: 37
[RESOLVED] That is a BOLD statement sir...
« on: December 03, 2021, 05:04:47 AM »
For my intended purposes I need to preserve text formating, such that I can maintain formating like bold, and underlining, etc. In a variable.

Is this possible?

Ideally I would like something like the "copy this to the clipboard" dialogue box, that allows spaces, line breaks, etc, along with some formating options, such that I can save a paragraph with all it's intricate formatting.

I can see no way to do this.

My workaround thus far has been to use a WordPad file, and to try to copy information from it directly, but thus far have not been successful in doing so.

What I could do us brute force copy from it (i.e by having the file open, and having voice attack switch window focus, open find, search for an title, press down, hold shift while pressing down x amount of lines required, Ctrl C, switch focus, Ctrl v).

A combersome ordeal, that still doesn't let me programmatically edit the text, and brings tokens embedded in the text into question.
.further, every time the text changes, I would have to reprogram the steps to ensure it did not miscopy.

Ugh.

What I would like is to be able to say:

Canned text 1 = This is canned text 1
And
Canned text 2 = This is canned text 2

And have those variables saved as such.


Thoughts?

« Last Edit: December 11, 2021, 03:49:52 PM by Castleberg »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: That is a BOLD statement sir...
« Reply #1 on: December 03, 2021, 12:23:17 PM »
That could be done using a plugin or inline function, to get and set the text data to and from the clipboard in the appropriate format.

E.G.
Code: [Select]
using System;
using System.Text;
using System.Windows.Forms;

public class VAInline
{
public void main()
{
if (Clipboard.ContainsText(TextDataFormat.Rtf))
{
VA.SetText("richText", Clipboard.GetText(TextDataFormat.Rtf));
}
else
{
VA.SetText("richText", Clipboard.GetText());
VA.WriteToLog("No Rich Text Format data in clipboard; copied as regular text", "yellow");
}
}
}
can retrieve Rich Text Format text from the clipboard (assuming you have first copied text into the clipboard, E.G. using Ctrl-C in WordPad), and store it in a VoiceAttack text variable

and
Code: [Select]
using System;
using System.Text;
using System.Windows.Forms;

public class VAInline
{
public void main()
{
string richText = VA.GetText("richText");
if (!String.IsNullOrEmpty(richText))
{
Clipboard.SetText(richText, TextDataFormat.Rtf);
}
else
{
VA.WriteToLog("No text to paste", "red");
}
}
}
Can set Rich Text Format text to the clipboard (after which it can be pasted in applications that accept that format, using Ctrl-V)

If you want to manually store the literal text, including the formatting, you can use
Code: [Select]
using System;
using System.Text;
using System.Windows.Forms;

public class VAInline
{
public void main()
{
string richText = VA.GetText("richText");
if (!String.IsNullOrEmpty(richText))
{
Clipboard.SetText(richText.Replace("{", "|{").Replace("\r\n", "{NEWLINE}"));
}
else
{
VA.WriteToLog("No text to paste", "red");
}
}
}
to paste that into a "Set a Text Value" action's "Text" field, which will escape the curly braces (so the token parser doesn't strip them) and newline sequences (so it can be pasted into a single-line field).

Castleberg

  • Newbie
  • *
  • Posts: 37
Re: That is a BOLD statement sir...
« Reply #2 on: December 03, 2021, 05:52:59 PM »
Thank you, as always. I will apparently bave to dive into, and learn inline functions (which I have been meaning to do anyway....) Any resources appreciated, I will see if I can't make this work!

Castleberg

  • Newbie
  • *
  • Posts: 37
Re: That is a BOLD statement sir...
« Reply #3 on: December 03, 2021, 07:38:08 PM »
One thing I am curious about, just so I know how to best allocate my study....

Are the above examples implementable for me now, without additional code? Or, would I first need to build out a plugin.

I have no idea how to make a plugin, or inline function, and suspect I need to turn my attention tords learning these topics before implementing the solution provided, yes?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: That is a BOLD statement sir...
« Reply #4 on: December 03, 2021, 07:41:12 PM »
You can literally paste those into inline functions, overwriting the example contents, and either run the inline function from the editor, or the command they're in, once saved.

The one thing you'd probably want to add, as mentioned, is actions to press Ctrl-C and Ctrl-V, where appropriate


Inline functions are generally completely independent from plugins.

Castleberg

  • Newbie
  • *
  • Posts: 37
Re: That is a BOLD statement sir...
« Reply #5 on: December 04, 2021, 04:08:48 PM »
Forgive my slowness...just struggling to get a grasp on this specific implementation so I have a base to learn from, and can't seem to get it to work...

I am sure what is to follow is in error (otherwise I wouldn't be having a problem), but perhaps if I lay my thought process out you can point to where I am making my mistake....

As I understand it you provided the code for 3 inline functions, to be used as follows:

1) move Rich text contained in the Clipboard into a variable
2) move Rich text contained in a variable into the clipboard
3).....(gets fuzzy), take rich text contained in the clipboard, and run a regex on it to convert it into a VA friendly form, to save it directly.

1 and 2 I have figured out.
3 I feel would be ideal for my purposes, but can't quite figure out how to get it to work. When taking a text
"This is a example."

I manually copy the text.
run function 1 to move that to "richText"
run function 3 to convert "richText" to a VA friendly format
But seemingly no matter what I do with that...it ends up looking like this...

|{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033|{\fonttbl|{\f0\fnil\fcharset0 Calibri;}}{NEWLINE}\uc1 {NEWLINE}\pard\sa200\sl276\slmult1\b\f0\fs22\lang9 This\b0  \ul is\ulnone  \i a\i0  \strike test}{NEWLINE}

Where am I going wrong?



Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: That is a BOLD statement sir...
« Reply #6 on: December 04, 2021, 04:15:00 PM »
What it ends up looking like is what you'd want to paste into the "Text" field of a "Set a Text Value" action, which is the Rich Text Format markup, escaped for VoiceAttack's token parser.

Then, after using that "Set a Text Value" action to set a variable, you'd use the second inline function to copy that value into the clipboard, so it can be pasted.


There are no regular expressions involved, just two normal text replacement method calls.

Castleberg

  • Newbie
  • *
  • Posts: 37
Re: That is a BOLD statement sir...
« Reply #7 on: December 05, 2021, 03:24:05 AM »
Having had a bit of time to tinker......I just have to come back and say THANK YOU!  This accomplishes what I needed to do adequetly.

I would love to be able to nest tokens within the variable text, but I suspect that isn't possible...

i.e.

{TXT:var1} = "This is a {TXT:var3} variable"
{TXT:var2} = "Freaking".
{TXT:var3} = "{TXT:var2} Awesome"


Such that when I copy/save the richText "This is an {TXT:var3} variable" as var1, (via method 3 above), and then recall it it would copy "This is a Freaking Awesome variable".

It seems like it SHOULD work....but appear not to. Am I missing something?

In either case, what you have provided me was a huge huge help, thank you!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: That is a BOLD statement sir...
« Reply #8 on: December 05, 2021, 03:26:56 AM »
What does the command that you're setting these variables in actually look like? Right-click the action list, choose "Copy All as Text" from the context menu, then paste here into a code block (click the # button)

Castleberg

  • Newbie
  • *
  • Posts: 37
Re: That is a BOLD statement sir...
« Reply #9 on: December 05, 2021, 06:00:19 PM »
Well, it is a little combersome, so I'm not sure you want me to do that...I'll cut out a reoccuring example to make it more manageable.

Reoccurring structure follows the pattern:
Line 1: variable declaration
Line 2: appending name index to recall easily in a input list
Line 3+?: declare aliases that will link to the same value.
Line 4: append variable to array of all such variables.
Line 5: move to next array.

Code: [Select]
Set integer [~i] value to 0

Set text [hpi Adult (Healthy)] to '|{\rtf1\ansi\ansicpg1252\deff0\nouicompat|{\fonttbl|{\f0\fnil\fcharset0 Calibri;}}{NEWLINE}|{\*\generator Riched20 10.0.19041}\viewkind4\... (save value to profile)
Set text [hpiName({INT:~i})] to 'Adult (Healthy)'
Set text [hpi adult] to [{TXT:hpi {TXT:hpiName({INT:~1})}}]
Set text [hpiList({INT:~i})] to [{TXT:hpi {TXT:hpiName({INT:~1})}}]
Set integer [~i] to [~i] plus 1

=========================

Set integer [hpiCount] value to the value of [~i]
Write [Green] '{INT:hpiCount} HPIs READY' to log


Castleberg

  • Newbie
  • *
  • Posts: 37
Re: That is a BOLD statement sir...
« Reply #10 on: December 05, 2021, 06:03:05 PM »
With the command to call said variables looking like this:

Code: [Select]
Set text [~Launch] to [Not Set]
Set text [~Order] to [Not Set]
Set text [~Command] to [Not Set]
Get Choice Input [~hpi]
DISABLED - Get Text Input [~hpi]


Begin Text Compare : [hpi {TXT:~hpi}] Has Been Set
    Set text [richText] to [hpi {TXT:~hpi}]
    Execute precompiled Inline Function: 'C:\Program Files\VoiceAttack\Apps\Inline Functions\Rich Text Variable to Clipboard.dll'
    Press Left Ctrl+V keys and hold for 0.08 seconds and release
    Write [Yellow] 'Pasted HPI (~hpi)' to log
End Condition

If your wondering about the aliases, when I am using a slection....it is because I have another command that lets me just free text commands, I am experimenting with both....

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: That is a BOLD statement sir...
« Reply #11 on: December 05, 2021, 06:59:29 PM »
There appears to be a fair amount of information missing there.


Having tokens embedded into the values of variables is possible, however you need to keep in mind that the token parser will run when setting a variable.

E.G. if you have
Code: [Select]
Set text [var1] to 'This is a {TXT:var3} variable'
Set text [var2] to 'Freaking'
Set text [var3] to '{TXT:var2} Awesome'

The value of "var1" will be the literal text "This is a Not set variable", as "var3" has not been set yet
The value of "var2" will obviously be the literal text "Freaking"
The value of "var3" will be the literal text "Freaking Awesome"
(assuming the command is running for the first time in that session)

If you retrieve the value of "var1", E.G. using
Code: [Select]
Write [Blue] '{TXT:var1}' to log
the log output will then be "This is a Not set variable", as the token was parsed at the moment the variable was set, so all that remains is literal text.


If, on the other hand, you escape the tokens, E.G.
Code: [Select]
Set text [var1] to 'This is a |{TXT:var3|} variable'
Set text [var2] to 'Freaking'
Set text [var3] to '|{TXT:var2|} Awesome'

The value of "var1" will be the literal text "This is a {TXT:var3} variable", as the token parser removes the escape symbols but does not parse the actual token
The value of "var2" will obviously still be the literal text "Freaking"
The value of "var3" will be the literal text "{TXT:var2} Awesome", as the token parser removes the escape symbols but does not parse the actual token

Retrieving the value of "var1" now, again using
Code: [Select]
Write [Blue] '{TXT:var1}' to log
will result in the log output "This is a Freaking Awesome variable", as the tokens in the values of the variables are parsed from the inside-out when the "Write a Value to the Event Log" action runs

Note that the variables are not written to when they're parsed (I.E. they maintain their value), so if you change the value of "var2" to the literal text "Quite" later on, and use
Code: [Select]
Write [Blue] '{TXT:var1}' to log
the log output will then be "This is a Quite Awesome variable"

Castleberg

  • Newbie
  • *
  • Posts: 37
Re: That is a BOLD statement sir...
« Reply #12 on: December 07, 2021, 03:42:28 AM »
That all is straightforward when it comes to executing normal variables within voice attack, and I seem to have little issues with nesting variables in general.  My problems comes when applying it to the discussion above. 

After your comments, I experimented, and with some success, but am experiancing very odd and inconsistent behavior. In one case the variable reliable resulted....but only if numbers were entered (it was a TXT variable). any text was missing.

Then I noticed the letters following the variable were also missing, until I put a space after the variable, suggesting some REGEX like behavior where letters were being escaped until a space....but couldn't quite figure it out (I would paste the example...but it is currently non-existent).

A simplier example, which I will include to convey a dumbed down version of my issue is this :

Code: [Select]
Set text [testVar] to 'Test Variable'
Set text [Test Sentence] to '|{\rtf1\ansi\ansicpg1252\deff0\nouicompat|{\fonttbl|{\f0\fnil\fcharset0 Calibri;}}{NEWLINE}\uc1 {NEWLINE}\pard\sa200\sl276\slmult1\ul\b\f0\fs22...
Set text [richText] to [Test Sentence]
Execute precompiled Inline Function: 'C:\Program Files\VoiceAttack\Apps\Inline Functions\Rich Text Variable to Clipboard.dll'

with a full copy of the "Test Sentence" variable being :

Code: [Select]
|{\rtf1\ansi\ansicpg1252\deff0\nouicompat|{\fonttbl|{\f0\fnil\fcharset0 Calibri;}}{NEWLINE}\uc1 {NEWLINE}\pard\sa200\sl276\slmult1\ul\b\f0\fs22\lang9 This \ulnone is \b0 a \|{TXT:testVar\}!}{NEWLINE}
Which is what resulted after :

1) Typing "This is a {TXT:testVar}!" into WordPad
2) Copying "This is a {TXT:testVar}!"
3) Running inline function to move clip board into "richText"

Code: [Select]
using System;
using System.Text;
using System.Windows.Forms;

public class VAInline
{
public void main()
{
if (Clipboard.ContainsText(TextDataFormat.Rtf))
{
VA.SetText("richText", Clipboard.GetText(TextDataFormat.Rtf));
}
else
{
VA.SetText("richText", Clipboard.GetText());
VA.WriteToLog("No Rich Text Format data in clipboard; copied as regular text", "yellow");
}
}
}

4) running inline function to convert "richText" data into a version I could store literally:

Code: [Select]
using System;
using System.Text;
using System.Windows.Forms;

public class VAInline
{
public void main()
{
string richText = VA.GetText("richText");
if (!String.IsNullOrEmpty(richText))
{
Clipboard.SetText(richText.Replace("{", "|{").Replace("\r\n", "{NEWLINE}"));
}
else
{
VA.WriteToLog("No text to paste", "red");
}
}
}

Per our prior conversations.

Castleberg

  • Newbie
  • *
  • Posts: 37
Re: That is a BOLD statement sir...
« Reply #13 on: December 07, 2021, 04:04:04 AM »
I was able to reproduce the behavior.

Typing, "This is a number : {TXT:number} This is a word : {TXT:word}". then copying it and adding it to a variable as literal text results in:

|{\rtf1\ansi\ansicpg1252\deff0\nouicompat|{\fonttbl|{\f0\fnil\fcharset0 Calibri;}}{NEWLINE}|{\*\generator Riched20 10.0.19041}\viewkind4\uc1 {NEWLINE}\pard\sa200\sl276\slmult1\f0\fs22\lang9 This is a \b number \b0 : \|{TXT:number\} This is a \b word \b0 : \|{TXT:word\}\par{NEWLINE}}{NEWLINE}

which, does not allow the tokens to function. when manually removing the | and \ characters (I wish I knew a automatic way.....) I get :

|{\rtf1\ansi\ansicpg1252\deff0\nouicompat|{\fonttbl|{\f0\fnil\fcharset0 Calibri;}}{NEWLINE}|{\*\generator Riched20 10.0.19041}\viewkind4\uc1 {NEWLINE}\pard\sa200\sl276\slmult1\f0\fs22\lang9 This is a \b number \b0 : \{TXT:number} This is a \b word \b0 : \{TXT:word}\par{NEWLINE}}{NEWLINE}

allows the tokens to function....with one exception. As noted before, it only allows the numbers to pass through. When converting the variable to the clipboard and pasting, it results in :

This is a number : 56 This is a word :


To Summerize:
Copied text : "This is a number : {TXT:number} This is a word : {TXT:word}"
TXT:number set to "56"
TXT:word set to "Sputnik"
Expected result: This is a number : 56 This is a word : Sputnik
Actual Result: This is a number : 56 This is a word :

Code: [Select]
Set text [number] to '56'
Set text [word] to 'Sputnik'
Set text [~test] to '|{\rtf1\ansi\ansicpg1252\deff0\nouicompat|{\fonttbl|{\f0\fnil\fcharset0 Calibri;}}{NEWLINE}|{\*\generator Riched20 10.0.19041}\viewkind4\uc1 {NEWLINE}\...
Set text [richText] to [~test]
Execute precompiled Inline Function: 'C:\Program Files\VoiceAttack\Apps\Inline Functions\Rich Text Variable to Clipboard.dll'

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: That is a BOLD statement sir...
« Reply #14 on: December 07, 2021, 04:10:26 AM »
The output I get with that example command is a literal "This is a {TXT:testVar}!", which is to be expected as the tokens use also uses curly braces, just as the Rich Text Markup does, so they're both escaped and therefore not parsed by the token parser.

You can either manually remove the pipe ("|") symbols and the backslash escape characters from the braces of the token in your "Set a Text Value" action, or you can use different characters (that you wouldn't normally use as part of the text itself), like "[" instead of "{", and "]" instead of "}", and have the inline function replace those with curly braces
E.G.
Code: [Select]
using System;
using System.Text;
using System.Windows.Forms;

public class VAInline
{
public void main()
{
string richText = VA.GetText("richText");
if (!String.IsNullOrEmpty(richText))
{
Clipboard.SetText(richText.Replace("{", "|{").Replace("\r\n", "{NEWLINE}").Replace("[", "{").Replace("]", "}"));
}
else
{
VA.WriteToLog("No text to paste", "red");
}
}
}

Do note that if the text in any variable value you're retrieving using a token contains curly braces, those should be escaped using backslash characters, as otherwise the Rich Text parser (in the application your pasting into) will likely attempt to interpret them part of the markup
The same would likely apply to backslashes, which should be doubled up (I.E. "\\" instead of "\")


EDIT: That'll happen when you don't remove the backslashes, which are used as escape characters in the markup for the curly braces.

The literal text would be "\Sputnik\", which causes the Rich Text parser to interpret it incorrectly


EDIT#2: Actually, given that curly braces need to be escaped when part of the text content, it stands to reason that an escaped brace therefore cannot be part of the markup

This modified inline function will first replace any escaped opening curly braces with a temporary non-printable character (I.E. one that should never be part of the copied text, so no conflicts arise), replace escaped closing braces to remove the escape character, escape any remaining opening braces that weren't escaped in the Rich Text markup for the token parser, and then replace the temporary characters with their final regular opening curly brace:
Code: [Select]
using System;
using System.Text;
using System.Windows.Forms;

public class VAInline
{
public void main()
{
string openingBraceSubstitute = ((char)2).ToString();

string richText = VA.GetText("richText");
if (!String.IsNullOrEmpty(richText))
{
Clipboard.SetText(richText.Replace("\\{", openingBraceSubstitute).Replace("\\}", "}").Replace("\r\n", "{NEWLINE}").Replace(openingBraceSubstitute, "{"));
}
else
{
VA.WriteToLog("No text to paste", "red");
}
}
}
« Last Edit: December 07, 2021, 06:10:59 AM by Pfeil »

Castleberg

  • Newbie
  • *
  • Posts: 37
Re: That is a BOLD statement sir...
« Reply #15 on: December 09, 2021, 01:52:10 PM »
I just wrote a long response / question, and deleted it all.  Suffice it to say, "I don't understand".

Instead of vomiting out all of my ignorance at once, let me try to tackle smaller concepts at a time.

In this code :

Code: [Select]
string openingBraceSubstitute = ((char)2).ToString();
I initially thought that this was a declaration, with the inteded purpose of me changing the definition to match my desired character. i.e.  string openingBraceSubstitute = "["; .

But, I believe that ((char)2).ToString() would result in openingBraceSubstitute being equal to "STX (start of text)". Which makes me believe something more nuanced / sophisticated is going on here. In particular, I suspect that just as

However, I can't figure out how this would function exactly.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: That is a BOLD statement sir...
« Reply #16 on: December 09, 2021, 10:57:53 PM »
Aah, something got lost in modifying that example

Initially I had it replacing both "{" and "}" with temporary characters, which I then realized was unnecessary as the closing brace doesn't need to be escaped for the token parser
In quickly removing that part, I must have also removed the replacing of non-escaped opening braces


The corrected version should look something like
Code: [Select]
using System;
using System.Text;
using System.Windows.Forms;

public class VAInline
{
public void main()
{
string openingBraceSubstitute = ((char)2).ToString();

string richText = VA.GetText("richText");
if (!String.IsNullOrEmpty(richText))
{
Clipboard.SetText(richText.Replace("\\{", openingBraceSubstitute).Replace("{", "|{").Replace("\\}", "}").Replace("\r\n", "{NEWLINE}").Replace(openingBraceSubstitute, "{"));
}
else
{
VA.WriteToLog("No text to paste", "red");
}
}
}


It uses ASCII character 2, "STX", to get around a chicken-and-egg problem when replacing the same character twice

E.G. if the input is "{markup \{TOKEN}}", and you replace "{" with "|{", the result would be "|{markup \|{TOKEN}}", so if you then try to replace "\{" with "{", there are no instances of "\{", as due to the replacement they're now "\|{"

Similar issue with the order is reversed: "{markup \{TOKEN}}", replace "\{" with "{" -> "{markup {TOKEN}}", replace "{" with "|{" -> "|{markup |{TOKEN}}"


So instead, it goes "{markup \{TOKEN\}}", replace "\{" with STX -> {markup STXTOKEN}}", replace "{" with |{" -> "|{markup STXTOKEN}}", replace STX with "{" -> "|{markup {TOKEN}}"


You could certainly use "[" instead, if that is your preference, but by using the temporary substitution (and the fact that the Rich Text parser escapes literal braces, so they're distinct from markup braces) there is no need to use the "wrong" character when typing in your text in WordPad
« Last Edit: December 11, 2021, 02:43:26 PM by Pfeil »

Castleberg

  • Newbie
  • *
  • Posts: 37
Re: That is a BOLD statement sir...
« Reply #17 on: December 10, 2021, 12:38:57 PM »
Ok. That makes sense. The char2 has nothing to do with finding a start of text in the file, it is just an arbitrary placeholder at the location of the bracket. I could just as well have used "©". (Not sure if that is a usable character...but I get the point)

Ultimately, the point is (I'm just reiterating because I have got myself in knots) to go from:

WordPad as I see it when using :

Rich text {TXT:MyToken}

Which is actually this within the file:

[Bunch of header crap, ending in "\lang9 "] [contents of file ]
Where [contents of file] is:

[Markup openers] characters I care about [/markup closers]...with some line breaks and such thrown in. - ((Rich text {TXT:Token}) with intersparced markup)

Such that, my goal is to convert :

{markup {TOKEN}}

Into

|{markup {TOKEN}}

Which poses a problem, because I only want to change "{" associated with the file markup, not the "{" associated with myToken.

In my example:

Rich text {TXT:MyToken}

Which is really:

{Header crap and markup Rich text {TXT:MyToken}}

Which I need to be stored in a variable as :

|{Header crap and markup Rich text {TXT:MyToken}}

But must avoid :

|{Header crap and markup Rich text |{TXT:MyToken}}

Which I do by
1) escaping the tokens in the actual text :

Rich text \{TXT:MyToken}

and then
2) using a arbitrary intermediary (in our case "STX") to produce :

{Header crap and markup Rich text STXTXT:MyToken}}

Which I will then switch the out the remaining, non escaped (non-Token) brackets:

|{Header crap and markup Rich text STXTXT:MyToken}}

and then safely ad back my token brackets such that VA can properly substitute the text:

|{Header crap and markup Rich text {TXT:MyToken}}

Which will be converted by voice attack to:

|{Header crap and markup Rich text Variable Output}

And then then I go to paste this variable in the future, I will have a more simple process of converting to the final output

{Header crap and markup Rich text Variable Output}
 
Which when added to the clipboard and pasted in a richText compatible field, windows / application will strip the remaining headers, with the visual result of pasting:

Rich text Variable Output

------

Do I have that general flow and thought process correct?

One thing Im still not clear on, is if you had a typo here:

"{markup \{TOKEN\}}", replace "\{" with STX -> {markup STXTOKEN}}", replace "{" with |{" -> "|{markup STXTOKEN}}", replace STX with "{" -> "|{markup {TOKEN}}"

Or just showing half the process. That is, you have :

{markup \{TOKEN\}}

to

|{markup {TOKEN}}

But we didn't discuss the closing bracket escape.  I just erased it in my citation above, (assume I don't need to escape it).

Alternatively I would need to duplicate the process with:

string closingBraceSubstitute = ((char)3).ToString();

Which would make my token "STXTXT:MyTokenETX"

Im assuming this is not needed.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: That is a BOLD statement sir...
« Reply #18 on: December 10, 2021, 12:54:11 PM »
Looks about right.

Though near the end, what you'd get out of the inline function would be something like "|{markup {TOKEN}}", to paste into the "Text" field of a "Set a Text Value" action.
When that action is executed, that's when the token parser will replace the token with its return value, and remove one escape character from the first brace, resulting in something like "{markup returnValue}" in the clipboard (though, as the format of the clipboard data is set to RTF, you won't actually see the markup, of course)

I.E. at no point (aside from internally in the token parser) should the value be "|{markup returnValue}", as the token parser will both remove the escape character, and replace the token with its return value

Castleberg

  • Newbie
  • *
  • Posts: 37
Re: That is a BOLD statement sir...
« Reply #19 on: December 11, 2021, 02:41:30 PM »
Minor edit to anyone following along :

Code above cited by Pfeil Should read:

Code: [Select]
using System;
using System.Text;
using System.Windows.Forms;

public class VAInline
{
public void main()
{
string openingBraceSubstitute = ((char)2).ToString();

string richText = VA.GetText("richText");
if (!String.IsNullOrEmpty(richText))
{
Clipboard.SetText(richText.Replace("\\{", openingBraceSubstitute).Replace("{", "|{").Replace("\\}", "}").Replace("\r\n", "{NEWLINE}").Replace(openingBraceSubstitute, "{"));
}
else
{
VA.WriteToLog("No text to paste", "red");
}
}
}

Changed was line 17, removed redundant "richText" :

Clipboard.SetText(richText.Replace("\\{", openingBraceSubstitute).richText.Replace

to

Clipboard.SetText(richText.Replace("\\{", openingBraceSubstitute).Replace

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: That is a BOLD statement sir...
« Reply #20 on: December 11, 2021, 02:54:46 PM »
Normally I run things through the compiler, but this was a quick, inattentive edit.


Splitting across multiple lines for readability may have prevented that:
Code: [Select]
using System;
using System.Text;
using System.Windows.Forms;

public class VAInline
{
public void main()
{
string openingBraceSubstitute = ((char)2).ToString();

string richText = VA.GetText("richText");
if (!String.IsNullOrEmpty(richText))
{
Clipboard.SetText
(
richText.Replace("\\{", openingBraceSubstitute)
.Replace("{", "|{")
.Replace("\\}", "}")
.Replace("\r\n", "{NEWLINE}")
.Replace(openingBraceSubstitute, "{")
);
}
else
{
VA.WriteToLog("No text to paste", "red");
}
}
}

Castleberg

  • Newbie
  • *
  • Posts: 37
Re: That is a BOLD statement sir...
« Reply #21 on: December 11, 2021, 03:45:48 PM »
Oh, I know :). I only added it for others that may have been following along and been met with errors :).

Although, I like the line split, I may have to adopt that in the future....As always, thanks and cheers!

P.S. I did get the Tokens working, as well as the rich text etc.  So I will consider this RESOLVED for now! :).

Now, onto my other issues (i.e. auto importing / parsing from files to avoid having to use the "set text to" field.....

I salute you. o7