Pinnacle :
Remove Illegal Characters


It’s necessary to call a script that generates a text file that contains a Pinnacle scripting command which defines the cleaned variable. For example, if given the string A%^$ 39839 the script will create another script document named Clean.Script containing the command:

Store.StringAt.DummyVariable = A_39839;

That code will then be executed by the cleaning script and read back into the Pinnacle data store.

Create the cleaning script

Create a script named RemoveIllegalChars.Script.p3rtp on the Pinnacle system. Paste the following code into the script:

// This script removes most illegal characters from a string named "Store.At.DummyVariable".
// The script will generate a temporary script file with a Pinnacle scripting command containing the cleaned variable. 
// The text document is deleted after the command is executed by Pinnacle (i.e. the string is read back into the Pinnacle data store).

//The /tmp/ directory should exist. If not, the user must create it.
Store.StringAt.Cleaned = "/usr/local/adacnew/PinnacleSiteData/Scripts/tmp/Clean.Script";

//Generate the cleaning command:
Store.StringAt.SpawnCmd = "echo 'Store.StringAt.DummyVariable = \"'`echo '";
Store.At.SpawnCmd.AppendString = Store.StringAt.DummyVariable;

//The first portion **tr-s '''_'** will replace multiple spaces with an underscores (_).
//The second portion tr -d \"@#$..." will remove each of those characters from the string. 
Store.At.SpawnCmd.AppendString = "\"\;' | tr -s ' ' '_' | tr -d \"@#$%^&*()=+[]{}|/\<>\"` > "; 
Store.At.SpawnCmd.AppendString = Store.StringAt.Cleaned;

//The command above is read. This creates the script file containing the Pinnacle string command.
SpawnCommand = Store.StringAt.SpawnCmd;

//This runs the temporary script file, reading the command into the Pinnacle data store.
Script.ExecuteNow = Store.StringAt.Cleaned;

//Remove the temporary script file
Store.StringAt.RemoveFile= "rm ";
Store.At.RemoveFile.AppendString = Store.StringAt.Cleaned;
SpawnCommand = Store.StringAt.RemoveFile;

//Clear variables
Store.FreeAt.Cleaned = "";
Store.FreeAt.SpawnCmd = "";

Ensure that the directory in which the Cleaned.Script file will be stored actually exists.

Call the cleaning script

Insert the following code into any script:

//Path to illegal character removal script. This can be stored anywhere on the Pinnacle system.
//This script will be passed a string called {{Store.At.DummyVariable}}.
Store.StringAt.RemoveIllegalChars = "/usr/local/adacnew/PinnacleSiteData/Scripts/RemoveIllegeChars/RemoveIllegalChars.Script.p3rtp";
//Copy the string to be cleaned into DummyVariable
Store.StringAt.DummyVariable = Store.StringAt.TempVariableToBeCleaned;
//Execute the script referenced above
//Copy the cleaned variable back into the original variable
//Free the variable so it can be reused

The string Store.At.TempVariableToBeCleaned will then contain the initial string with spaces replaced with underscores (_) and other illegal characters removed.