The goal of this example is to create a network socket integration that includes BTXML Script in an action. BarTender XML Script (BTXML Script) provides the ability to easily automate BarTender while allowing 3rd party programmers a simple way to integrate BarTender into their applications.
An XML response is created after running a BTXML script. The XML response provides you with valuable information about the print job, such as the printer used to complete the job, BarTender's settings during the print job, and complete details about the labels printed.
A company needs to send a print job containing 100 serialized items to Tray 1 of their HP LaserJet printer. The print job will execute when data--in this case, a BTXML Script--is sent over a network socket, and read by the BarTender Integration Service.
The following procedures describe how to set up, deploy, and verify the integration for the scenario outlined above.
Create the BarTender document
- Open BarTender.
- From the File menu, select New to open the New Document Wizard.
- Select Blank Template, and then click Finish to close the New Document Wizard. A new document appears in BarTender.
- From the File menu, select Print to open the Print dialog.
- From the Name dropdown list, select the printer you want to use. Be sure to change the printer name in the BTXML Script to the printer you select here.
- Click Close to close the Print dialog.
- From the File menu, select Page Setup to open the Page Setup dialog and configure your page as needed.
- When you're finished configuring your page, click OK to close the Page Setup dialog.
- From the Create menu, select template objects and configure your BarTender document as desired.
- From the File menu, select Save As, and save the BarTender document under the name Scriptdoc.btw.
- Close BarTender.
Create the BTXML Script trigger document
<?xml version="1.0" encoding="utf-8"?> <XMLScript Version="2.0"> <Command Name="Job1"> <Print> <Format>c:\BarTender\Scriptdoc.btw</Format> <PrintSetup> <NumberSerializedLabels>100</NumberSerializedLabels> <Printer>HP LaserJet</Printer> <PaperTray>Tray 1</PaperTray> </PrintSetup> </Print> </Command> </XMLScript>
<?xml version="1.0" encoding="utf-8"?>
Paste the BTXML script into a text file, and save it under the name BTXMLScript.txt.
Create the Integration File: Select a Network Socket Integration
- Open Integration Builder.
- Click Create New Integration to open the New Integration dialog.
- Click Network Socket and then click OK.
- In the Network Socket Integration pane, select Integration.
- In the Properties pane, enter the Name of your integration as "Print 100".
- From the Start Integration dropdown list, select Automatic.
- Under User Account, specify user credentials. See Print document using an empty file for details.
- In the Network Socket Integration pane, select Socket.
- In the Properties pane, set your Protocol and Port information.
- Under Network Address, select Listen on all network interfaces. Alternatively, select Listen on specific IP address and select an IP address from the dropdown list, or enter an IP address by hand.
- Set your Communication Settings and Connection Protocol if you wish.
- In the Network Socket Integration pane, select Input Data.
- In the Properties pane, select Unicode (UTF-8) for the Encoding property.
- For Stop Reading When, select Sequence of Characters Received.
- In the Characters field, enter </XMLScript>.
- Enable Include sequence in input data contents.
- For Input Data Format, select BTXML Script.
- In the Network Socket Integration pane, select Response.
- In the Properties pane, select your response options.
Create the Integration File: Add an Action to the Network Socket Integration
- In the Network Socket Integration pane, select Actions.
- In the Properties pane, for Execute Actions, select Sequentially.
- For Repeat actions, specify "1".
- In the Network Socket Integration pane under Action, click at the right of Print Document to remove the default action.
- Select Action and click Add to open the New Action dialog.
- Select Print from the list of action types in the left Navigation Pane, and then select Print BTXML Script
- Click OK to close the New Action dialog.
- The action Print BTXML Script appears in the Network Socket Integration pane under Actions.
- If not already selected, click Print BTXML Script in the Network Socket Integration pane.
- In the Properties pane under Action, enter a name and description for the Print BTXML Script action.
- Under Script, select Variable from the Script Source dropdown list.
- If it's not already selected, choose EventData from the Variables dropdown list.
- Click in the top left corner of Integration Builder to save the integration file as
Test the Print BTXML Script Action (Not the Entire Integration)
In order to test a "Print BTXML Script" action, you must change some settings for the test, then restore them to their original state afterward.
- In the Network Socket Integration pane under Actions, select Print BTXML Script.
- In the Properties pane under Script, select Embedded Script from the Script Source dropdown list.
- Click the Import button to import your BTXML file, or just paste the contents of the file in the provided window.
- Click the Test button at the right of the script window.
- If your "Print BTXML Script" action passes testing, in the Network Socket Integration pane under Actions, select Print BTXML Script once more.
- In the Properties pane, set the Script type back to Variable, and the Variable type back to %EventData%.
Test and Deploy the Integration File
- Click Test Integration in the Integration Builder toolbar.
- If your integration passes testing, click Deploy Integration to open the New Deployment dialog.
- Enter a name and description for the deployment.
- Ensure that the Integration File setting lists
BTXML_Integration.btin. Otherwise, click Browse and browse to and select
- For Target Servers, add the server(s) you want to deploy the integration file to.
- Specify the desired Error Handling settings.
- Click OK to close the dialog and deploy the integration file.
- Administration Console will open on the Integrations node, displaying your integration
Run the scenario and view integration processing
- The BarTender Integration Service is monitoring the selected network socket. Send the contents of BTXMLScript.txt over the network socket using your preferred method.
- The Integration Service passes the BTXML Script to BarTender.
- BarTender performs the actions specified in the BTXML Script, printing 100 copies of the document Scriptdoc.btw using tray 1 of the specified printer.