PureDYMO library : control DYMO label writers (Windows only)

Developed or developing a new product in PureBasic? Tell the world about it.
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: PureDYMO library : control DYMO label writers (Windows o

Post by jesperbrannmark »

You can always use this script

Code: Select all

text.s="this is my address"+#CRLF$+"line 2"+#CRLF$+"line 3"
fil.l=CreateFile(#PB_Any,GetTemporaryDirectory()+"dymo.vbs")
WriteStringN(fil.l,"Dim DymoAddIn")
WriteStringN(fil.l,"Dim DymoLabel")
WriteStringN(fil.l,"Set DymoAddIn = CreateObject("+Chr(34)+"DYMO.DymoAddIn"+Chr(34)+")")
WriteStringN(fil.l,"Set DymoLabel = CreateObject("+Chr(34)+"DYMO.DymoLabels"+Chr(34)+")")
If FileSize("c:\label.LWT")>3
  WriteStringN(fil.l,"DymoAddIn.Open "+Chr(34)+"C:\label.LWT"+Chr(34))
EndIf
WriteStringN(fil.l,"DymoLabel.SetAddress 1,"+Chr(34)+text+Chr(34))
WriteStringN(fil.l,"DymoAddIn.Print 1, TRUE")  
CloseFile(fil.l)
RunProgram(GetTemporaryDirectory()+"dymo.vbs","","",#PB_Program_Hide)
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4790
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: PureDYMO library : control DYMO label writers (Windows o

Post by Fangbeast »

That's very interesting, thanks.

Does "DYMO.DymoAddIn" infer that some sort of addin needs to be installed or has been installed already somehow?
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4790
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: PureDYMO library : control DYMO label writers (Windows o

Post by Fangbeast »

I'm getting this error below

Script:
Line: 6
Char: 42
Error: Unterminated string constant
Code: 800A0409
Source: Microsoft VBScript compilation error

Because the string below:

text.s="this is my address"+#CRLF$+"line 2"+#CRLF$+"line 3"

Looks like this in the VBScript file split across three lines and thus is unterminated. Any idea how to fix this?

Dim DymoAddIn
Dim DymoLabel
Set DymoAddIn = CreateObject("DYMO.DymoAddIn")
Set DymoLabel = CreateObject("DYMO.DymoLabels")
DymoLabel.SetAddress 1, "this is my address
line 2
line 3"
DymoAddIn.Print 1, TRUE
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: PureDYMO library : control DYMO label writers (Windows o

Post by jesperbrannmark »

I send the whole thing instead of half a code.
Dymo Addin is the VBS way of calling DYMO Labelwriter software.
If you get script error (windows) you need to reinstall DYMO Labelwriter software.
And by the way. Dymo v7 is much much better than v8. I have been in contact with their support sooooo much and they admit to a lot of bugs and problems with the SDK. Its all documented in their forum, and they also advice coders to use v7 (which actually does its job). If you have dymo label writer 450 you need a patch to be able to use v7.

Here is the entire code, both PC and Mac:

Code: Select all

Procedure dymo_printlabel(text.s)
  text.s=ReplaceString(text.s,"<p>","")
  text.s=ReplaceString(text.s,"&nbsp;"," ")
  text.s=ReplaceString(text.s,"<br>",#CRLF$)
  text.s=ReplaceString(text.s,"</p>",#CRLF$)
  text.s=ReplaceString(text.s,"<html>","")
  text.s=ReplaceString(text.s,"</html>","")
  text.s=ReplaceString(text.s,"<body>","")
  text.s=ReplaceString(text.s,"</body>","")
  text.s=ReplaceString(text.s,"<head>","")
  text.s=ReplaceString(text.s,"</head>","")
  text.s=ReplaceString(text.s,"<strong>","")
  text.s=ReplaceString(text.s,"</strong>","")
  
  CompilerIf #PB_Compiler_OS=#PB_OS_MacOS
    text.s=ReplaceString(text.s,#CR$,Chr(34)+" & crlf & "+Chr(34))
    text.s=ReplaceString(text.s,Chr(10),"")
    a.s="try"+#CRLF$
    a.s+"set crlf to (ASCII character 13) & (ASCII character 10)"+#CRLF$
    a.s+"set the_address To "+Chr(34)+text.s+Chr(34)+#CRLF$
    a.s+"tell application "+Chr(34)+"DYMO Label"+Chr(34)+#CRLF$
    a.s+"set object text of address 1 To the_address"+#CRLF$
    a.s+"set content of address 1 To the_address"+#CRLF$
    a.s+"printLabel2"+#CRLF$
    a.s+"End tell"+#CRLF$
    a.s+"End try"+#CRLF$
    b.s=COCOA_AppleScript(a.s)
    Debug "Returned result from APPLESCRIPT:"+b.s
  CompilerElse
    text.s=ReplaceString(text.s,Chr(10),"")
    If Left(text.s,1)=Chr(10)
      text.s=Right(text.s,Len(text.s)-1)
    EndIf
    text.s=ReplaceString(text.s,#CR$,Chr(34)+"+chr(10)+"+Chr(34))
    
    fil.l=CreateFile(#PB_Any,GetTemporaryDirectory()+"dymo.vbs")
    WriteStringN(fil.l,"Dim DymoAddIn")
    WriteStringN(fil.l,"Dim DymoLabel")
    WriteStringN(fil.l,"Set DymoAddIn = CreateObject("+Chr(34)+"DYMO.DymoAddIn"+Chr(34)+")")
    WriteStringN(fil.l,"Set DymoLabel = CreateObject("+Chr(34)+"DYMO.DymoLabels"+Chr(34)+")")
    If FileSize("c:\label.LWT")>3
      WriteStringN(fil.l,"DymoAddIn.Open "+Chr(34)+"C:\label.LWT"+Chr(34))
    EndIf
    WriteStringN(fil.l,"DymoLabel.SetAddress 1,"+Chr(34)+text+Chr(34))
    WriteStringN(fil.l,"DymoAddIn.Print 1, TRUE")  
    CloseFile(fil.l)
    RunProgram(GetTemporaryDirectory()+"dymo.vbs","","",#PB_Program_Hide)
  CompilerEndIf
EndProcedure
And I don't mean at all to take focus from PureDYMO. Just needed a cross platform way of printing labels myself, that worked in thread safe mode and this did its job so..
Post Reply