How to strip information from a Print Command Script trigger file, then reuse it to set a Print Document action
How do you strip information out of a trigger file containing Print Command Script instructions, then use it to set variable data and print options in a Print Document action?
The following methods can be used to pull named data sources from the trigger file containing command script parameters, then use the data like a normal csv file. For both of these methods, you will need to create a File Integration that contains a Print Document command.
Using Regular Expressions
The shorter of the two methods is using Regular Expressions (regex). The entire process through the Print Document action is here:
The first three actions are Search and Delete actions. This is the sample data used in the example:
%BTW% /AF="C:\Users\framos\Desktop\TempFiles\PALLET-0.btw" /PRN="PFM_ADV_COP" /R=3 /P /D="%Trigger File Name%" /DD
;BLE-0230ABU;40000,00;;100000025;S;VERSEUR 29MM;BH0290ABU190I01;BLEDINA;69400;VILLEFRANCHE SUR SAONE;;111,38;BH0290ABU190I01;40000,00;PCE;170215;P;;1;100,00;OF000006;K;OF000006;;R;;PCE;Commission client;;40000,00;PCE;40000,00;PCE;UNITED CAPS MESSIA;39570 MESSIA SUR SORNE FRANCE;P01;;;;;CUS002474;;0;036610641000000258;0;63661064000055;02;4;2,00;TOTO est parti chez le boulanger pour acheter un croissant;END
1. Retrieve the document name from the Event Data pulled from the trigger file
The Regular expression deletes everything before and including /AF=" and everything after and including " /PRN. Here is the regex to copy and use:
2. Retrieve the printer name from the Event Data
Like the previous action, this one strips out and deletes anything not included between the quotes for the /PRN parameter. Here is the regex to copy and use:
3. Delete the command script so the Print Document action can use the trigger file data like a regular csv file:
This regex simply deletes the first two rows and leaves the remaining data intact. Here is the regex to copy and use:
A note when building your own Regex
BarTender uses % to denote variables in Integrations. The Command script uses two of these, %BTW% and %END%. If your regex contains two %, BarTender interprets whatever's between them as a variable and may throw a warning: "Unable to apply transform because search criteria has one or more unresolved names."
If possible, try to avoid using two %. If you must use both, such as the regex used to delete the command script above, you can use the dot wildcard character in place of the % or uncheck the variable checkbox on the action:
Printing the document using the stripped information
The last step is to plug all this information into your Print Document Action. Using the variables you've created, you can simply add them into the Document and Printer fields on the Print Document Action:
You can use other information stripped from the command script here as well, such as number of copies or any custom variables you added. You can add a named data source like this where %NamedVariable1% contains the data you extracted from the command script:
If you are having trouble with Regular Expressions or do not wish to work with them, here's an alternate method you can use to extract information.
Using Search and Delete
This method is the longer of the two methods. This is a good method if you don't want to use Regular Expressions or modify them. For each piece you want to strip out of the Command Script, you'll need this series of Search actions:
1. First step searches for /AF=" then strips out anything before it:
2. Second step deletes the /AF=" used to search in the first step:
3. Now we need to delete everything after the actual file name. Since we don't know what the file name will be, we can strip everything after the quote, as this will be the first one the search finds:
4. Like before, we need to delete the quote.
You now have the BTW file path and name. For each piece, such as the printer and any other information you wish to strip out of the Command Script, you'll need to do these four steps.