Printing DYMO Labels with Tcl and tcom

Call it blatant commercialism, but DYMO label writers are a cool product. In my experience, printing sucks. Not with the little DYMO printers, it just works and is completely trivial to do with Tcl and tcom or dde, choose your own poison.

- 24Aug2003 PS

You can make your own label template or use a preinstalled one. You don't need the SDK (included on the driver CD) installed to use the API. The SDK mostly provides a Word document with the API reference. You are just six lines of code away from a label!

The Short-short version

 package require tcom
 set dymo [::tcom::ref createobj DYMO.DYMOAddIn]
 set label [::tcom::ref createobj DYMO.DYMOLabels]
 $dymo Open Address.lwt
 $label SetField Address "Name\nAddress\nTown"
 $dymo Print 1 0

Using tcom

 package require tcom

 # The DYMO has two objects for the highlevel API
 # AddIn has the calls like Open, SaveAs, Close, Print
 set dymo [::tcom::ref createobj DYMO.DYMOAddIn]
 # And Labels has methods to examine a label template, SetFields, etc.
 set label [::tcom::ref createobj DYMO.DYMOLabels]

 # I store my custom label templates in the same directory as my script.
 # You do not need to supply the full path to user templates installed in the
 # DYMO standard location, for example [$dymo Open Address.lwt] will correctly 
 # the standard Address template. 
 set base [file dirname [info script]]
 if { ![$dymo Open [string map {/ \\} [file normalize $base/mylabel.lwt]]] } {
    error "Could not open label template"

 #Now set some fields on the label. You can right click in the template designer
 #to set the field names (they default to TEXT, TEXT1, BARCODE2, etc.)
 $label SetField barcode 0142575
 $label SetField product "WizzBang by Acme"
 $label SetField expiry "August 2004"

 #And print 1 copy, keeping the 'printing...' dialog hidden.
 $dymo Print 1 0

Using dde

dde is available to any win32 tclsh, so here is a sample of that too. If at all possible, use tcom. It is faster and friendlier to the user (who doesn't see the program with the tcom version).

For dde to work, the C:\Program Files\Dymo Label\Dymolbl.exe must be started. You can find it's location in the registry. Use exec, registry and friends.

 package require dde

 proc dymo { cmd } {
    return [dde execute DYMO SYSTEM $cmd]

 proc dymo? { what } {
    return [dde request DYMO SYSTEM $what]

 #Read the manual: there is a registry key that has the correct location
 exec "C:\\Program Files\\Dymo Label\\Dymolbl.exe"
 #Status needs to be 'Ready'
 if { [dymo? Status] ne "Ready" } {
    error "Labelwriter not ready"

 dymo "Open(C:\labels\mylabel.lwt)"
 #which fields are available on the label 
 puts [dymo? Fields]

 dymo "SetObjectText(Address, Pascal Scheffers|Somestreet 1|1234 AZ My Town)"
 dymo "print"

And that's it. Labels roll out of the printer.