1

Using Python, I am trying to create an exe that will print barcode labels. This will interact with BarTender labeling software. I understand this is possible but I am new to Python and not sure how to go about this. I have it in C# but I need to convert to Python. Would this be a simple conversion for someone who knows both languages ;)

// Declare a BarTender application variable
BarTender.Application btApp;
// Declare two BarTender document variables
BarTender.Format btFormat1;
BarTender.Format btFormat2;
// Create a new instance of BarTender
btApp = new BarTender.Application();
// Set the BarTender application visible
btApp.Visible = true;
// Open a BarTender document
btFormat1 = btApp.Formats.Open("c:\\Format1.btw", false, "");
// Open a second BarTender document
btFormat2 = btApp.Formats.Open("c:\\Format2.btw", false, "");
// Set focus to the first opened document
btFormat1.Activate();
// End the BarTender process
btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

So far I have

import win32.com.client

btApp = win32com.client.Dispatch("BarTender.Application")
btApp.Visible = 1
btFormat = btApp.Formats.Open(r"C:\Users\kmoe\Desktop\Print-Self_Labels.btw", false, "")

The first argument is required and is a string containing the path and file name of the document to open. The second argument is a Boolean: if it is true, the method will close the default blank document called "Document1" that BarTender automatically opens when it starts. It cannot close documents that have any other name. The third argument specifies a printer to use.

However, this only opens the correct label template but does not print to the default printer

More info can be found here

http://help.seagullscientific.com/2016/en/#../Subsystems/ActiveX/Content/opening_format.htm%3FTocPath%3DAutomating%2520BarTender%7CAutomation%2520with%2520ActiveX%7CGetting%2520Started%7CExamples%2520Using%2520ActiveX%2520Automation%7C_____1

Thanks in advance!

KMoe
  • 125
  • 10
  • Keep going it doesnt look like you have much more to code and almost certainly dont need our help with finishing it off – BugFinder May 03 '18 at 10:04
  • I just googled `python barcode` and first result is: https://pypi.org/project/python-barcode/ – Samuel GIFFARD May 03 '18 at 10:06
  • Hi Samuel, I did find that page but from my understanding, this will help me create new labels but not interact with BarTender. I must be able to use new and existing BarTender .btw templates. Have spent a while on this but have not cracked the actual printing part! – KMoe May 03 '18 at 10:28

1 Answers1

0

I had to implement Bartender label print from web server and I was unable to use Integration builder due version of the Bartender installed, so I decided to go ahead with ActiveX. Old post, but here is tested code if someone else needs it.

import win32com.client as win32

btApp = win32.Dispatch("BarTender.Application")
btApp.Visible = True


btFormat = btApp.Formats.Open("C:\\Users\\someUser\\Desktop\\YourLabel.btw", False, "PrinterName")

btFormat.SetNamedSubStringValue("btField1", "Data1")
btFormat.SetNamedSubStringValue("btField2", "Data2")
btFormat.SetNamedSubStringValue("btField3", "Data3")

btFormat.IdenticalCopiesOfLabel = 1
btFormat.PrintOut(False, False)
btFormat.Close(1)
btApp.Quit(1)