Page 1 of 1

read text ID via script?

Posted: Wed Jun 08, 2016 5:44 am
by mmarks
I'm wondering if there is any way to retrieve a string (in the current language) defined under Multiple Languages/ Text IDs via script?

I saw in another topic that the following line compiles (and I tried it myself too):

Code: Select all

Globals.MultipleLanguages.SetLanguage("Default");
So we have access to the MultipleLanguages object but since there is no autocomplete and I can't find any documentation I'm stuck :(

Re: read text ID via script?

Posted: Wed Jun 08, 2016 8:09 am
by AMitchneck
I've never extracted text from screens, but to extract text from Text Library you could use something like

Code: Select all

using Neo.ApplicationFramework.Tools.MessageLibrary;
public string GetTextFromLibrary(int Value)
{
	for (int i = 0; i < Globals.TextLibrary.Group1.Messages.Count; i++)
	{
		if ((Globals.TextLibrary.Group1.Messages[i].StartValue <= Value) &&
			(Globals.TextLibrary.Group1.Messages[i].EndValue >= Value))
		{
			return Globals.TextLibrary.Group1.Messages[i].Message;
		}
	}
	return "";
}

Re: read text ID via script?

Posted: Mon Aug 01, 2016 7:22 am
by AMitchneck
After some digging, I found you can extract text from Text ID using the following

Code: Select all

Neo.ApplicationFramework.Tools.MultiLanguage.MultiLanguageResourceManager resources = new Neo.ApplicationFramework.Tools.MultiLanguage.MultiLanguageResourceManager(typeof(Screen1));
button.Text = resources.GetText(ID, "default");
where
Screen1 is the name of the screen
ID is a uint of the desired textID
"default" is the default text to return if ID not found
button.Text is where to put the result

you can obtain specific text to controls on screen by replacing ID with, for example, "Screen1.button.Text". This example would get the text associated with button on Screen1.