Question Dymolabelwriter

Just starting out? Need help? Post your questions and find answers here.
Little_man
Enthusiast
Enthusiast
Posts: 152
Joined: Fri Mar 29, 2013 4:55 pm
Location: The Netherland

Question Dymolabelwriter

Post by Little_man »

A question about a "Dymo "LabelWriter";

Remark_line: ''Open the "Adres (breed).LWT" template in Dymo Label Software(DLS).                                      
DymoAddIn.Open (LabelFileType$) -- (code-line in code VB6)

How do I put the line above to PureBasic
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Question Dymolabelwriter

Post by luis »

I don't have the slightest idea.

BUT the DymoAddIn seems to be a COM object, so I imagine there is some kind of SDK for that and maybe you could use srod's COMate to create the object

http://www.purecoder.net/comate.htm
"Have you tried turning it off and on again ?"
Little_man
Enthusiast
Enthusiast
Posts: 152
Joined: Fri Mar 29, 2013 4:55 pm
Location: The Netherland

Re: Question Dymolabelwriter

Post by Little_man »

Already exists:

Code: Select all

EnableExplicit

Global DymoAddin, DymoLabels
Global Dymo_Software.s

;- Include File.
XIncludeFile "C:\Program Files (x86)\PureBasic 5.11\COMatePLUS.pbi"

;"Check of Dymo LabelWriter Software is Installed.
DymoAddin  = COMate_CreateObject("DYMO.DymoAddIn")
DymoLabels = Comate_createobject("DYMO.DymoLabels")
  
If COMate_GetLastErrorCode() = 0 Or COMate_GetLastErrorDescription() = "Okay"
    Dymo_Software.s = "Dymo LabelWriter Software Installed"
  Else
    Dymo_Software.s = "Dymo LabelWriter Software ''NOT'' installed"
EndIf
  
;If Dymo_Software = "Dymo LabelWriter Software ''NOT'' installed"
;  Debug "Dymo LabelWriter Software ''NOT'' installed"
;  End
;EndIf

DymoAddIn.Open(GetCurrentDirectory()  + "Adres.lwa") ; (<<===== ) 
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Question Dymolabelwriter

Post by IdeasVacuum »

Have you seen this?
ABBKlaus PureDYMO lib
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4799
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Question Dymolabelwriter

Post by Fangbeast »

You could also use the routines below that I use with existing Dymo label templates. I just went into dymo software one day and created a lot of templates that I wanted and threw them intot he program directory that I wanted. Then the user selects the template that they want and uses the code below to add the user selected details.

I had a lot of help getting this going.

Code: Select all

; Find the specific printer needed for Dymo labels and warn user if it doesn't exist

Procedure FindNeededPrinter(NeededPrinter.s)
  ;#PRINTER_ENUM_LOCAL | #PRINTER_ENUM_CONNECTIONS;| #PRINTER_ENUM_REMOTE
  ;"DYMO LabelWriter"
  ; 
  ; Find the list of printers installed on the system
  EnumPrinters_(#PRINTER_ENUM_LOCAL | #PRINTER_ENUM_CONNECTIONS, 0, 1, #Null, 0, @dwNeeded, @dwReturned)
  ; Show the error returned by this system call. There will be one but not critical
  Debug GetLastErrorString(GetLastError_())
  ; 
  If dwNeeded
    *buffer = AllocateMemory(dwNeeded)
    EnumPrinters_(#PRINTER_ENUM_LOCAL | #PRINTER_ENUM_CONNECTIONS, 0, 1, *buffer, dwNeeded, @dwNeeded, @count) 
    For i = 1 To count
      PointerString = PeekI(*buffer + (i - 1) *SizeOf(PRINTER_INFO_1) + OffsetOf(PRINTER_INFO_1\pName))
      ;Debug PeekS(PointerString)
      If FindString(PeekS(PointerString), NeededPrinter.s, 1)
        PrinterFound.i = 1
      EndIf
    Next
    FreeMemory(*buffer)
  EndIf
  ; 
  If PrinterFound.i
    Debug NeededPrinter.s + " was found in the system. Labels can be printed."
  Else
    Debug "Needed label printer: " + NeededPrinter.s + " was Not found in the system!!"
  EndIf
  ; 
EndProcedure

; Read and load Dymo XML data off disk to extract the images too display to the user

Procedure DecodeDymoXMLFile(*CurrentNode, CurrentSublevel.i)
  ;
  If XMLNodeType(*CurrentNode) = #PB_XML_Normal
    ;
    *ChildNode = ChildXMLNode(*CurrentNode)
    ;
    While *ChildNode <> 0
      ; Returns the tagname of the given XML node;
      NodeName.s =  GetXMLNodeName(*ChildNode)
      ;
      If NodeName.s = "Image"
        ; Returns the text inside the given XML node.
        Program\DecodedLabelGraphic = GetXMLNodeText(*ChildNode)
        ;
      EndIf
      ;
      DecodeDymoXMLFile(*ChildNode, CurrentSublevel.i + 1)
      *ChildNode = NextXMLNode(*ChildNode)
      ;
    Wend
    ;
  EndIf
  ;
EndProcedure 

; Show the dymo label graphic next to the label template picker in my data form

Procedure ShowDymoLabelGraphic()
  ; 
  LabelName.s = GetGadgetText(#Gadget_Address_template)
  ; 
  If LabelName.s <> ""
    ; Did we get a file handle?
    FileId.i = LoadXML(#PB_Any, Program\LabelDirectory + LabelName.s)
    ; Did we get a file handle?
    If FileId.i
      ; Get the main node of the XML document
      *MainNode = MainXMLNode(FileId.i)
      ; Parse the XML file
      DecodeDymoXMLFile(*MainNode, CurrentSublevel.i)
      ; 
      If Program\DecodedLabelGraphic <> ""
        ; Get the real file length
        ActualLen.i   = Len(Program\DecodedLabelGraphic)
        ; Create a buffer for the file to decode
        *DecodeBuffer = AllocateMemory(ActualLen.i)
        ; Create a buffer for the decoded file
        *OutputBuffer = AllocateMemory(ActualLen.i)
        ; 
        If PokeS(*DecodeBuffer, Program\DecodedLabelGraphic, ActualLen.i) <> 0
          ; Decode the file
          ActualBytes.i = Base64Decoder(*DecodeBuffer, ActualLen.i, *OutputBuffer, ActualLen.i)
          ; 
          If ActualBytes.i
            ; 
            DecodedPictureHandle.i    = CatchImage(#PB_Any, *OutputBuffer, ActualBytes.i)
            ; 
            If DecodedPictureHandle.i
              ; 
              ResizeImage(DecodedPictureHandle.i, 85, 55, #PB_Image_Smooth)
              ; 
              SetGadgetState(#Gadget_Address_itemplate, ImageID(DecodedPictureHandle.i))
              ; 
              Program\DecodedLabelGraphic = ""
              ; 
            Else
              Debug "Could not create the output file on disk, no handle"
            EndIf
            ; 
          Else
            Debug "Didn't manage to decode any data damn it"
          EndIf
          ; 
        Else
          Debug "Didn't manage to poke any string data!!"
        EndIf
        ; 
      Else
        Debug "No image found in label code."
      EndIf
      ; 
    Else
      Debug "Cold not load the XML label code."
    EndIf
    ; 
  Else
    ; SetGadgetState(#Gadget_Address_template, ImageID(#Image_Address_itemplate))
  EndIf
  ; 
EndProcedure

; Create a dymo label for each passed address string

Procedure MakeDymoLabel(AddressString.s, LabelTemplate.s)
  ; 
  AddressString.s = ReplaceString(AddressString.s,  #CRLF$, Chr(34) + " + chr(10) + " + Chr(34))
  ; 
  If AddressString.s
    ; 
    DymoScript.i = CreateFile(#PB_Any, Program\TemporaryDirectory + "DymoLabel.vbs")
    ; 
    If DymoScript.i
      ; 
      WriteStringN(DymoScript.i, "Dim DymoAddIn")
      WriteStringN(DymoScript.i, "Dim DymoLabel")
      WriteStringN(DymoScript.i, "Set DymoAddIn = CreateObject(" + Chr(34) + "DYMO.DymoAddIn"  + Chr(34) + ")")
      WriteStringN(DymoScript.i, "Set DymoLabel = CreateObject(" + Chr(34) + "DYMO.DymoLabels" + Chr(34) + ")")
      ; 
      If LabelTemplate <> ""    ; Blank template selected
        If FileSize(Program\LabelDirectory + LabelTemplate.s) > 3   ; If the label file is GREATER THAN 3 characters and exists
          WriteStringN(DymoScript.i, "DymoAddIn.Open " + Chr(34) + Program\LabelDirectory + LabelTemplate.s + Chr(34))
;       Else
;         Debug "No template file found, writing to blank label."
        EndIf
      EndIf
      ; 
      WriteStringN(DymoScript.i, "DymoLabel.SetAddress 1, " + Chr(34) + AddressString.s + Chr(34))
      WriteStringN(DymoScript.i, "DymoAddIn.Print 1, TRUE") 
      ; 
      CloseFile(DymoScript.i)
      ; 
      RunProgram(Program\TemporaryDirectory + "DymoLabel.vbs", "", "", #PB_Program_Hide|#PB_Program_Wait)
      ; 
    Else
      Debug "Dymo label VBScript file could not be created."
    EndIf
    ; 
  Else
    Debug "Address string cannot be empty"
  EndIf
  ; 
EndProcedure

And as for how I personally collect the data and send it to the MakeDymoLabel routine..

Code: Select all

; Print labels for the selected addresses

Procedure PrintLabel(SourceForm.s)
  ; Work out the source of the record number
  Select SourceForm.s
    Case "MainForm"
      CurrentLine.i   = GetGadgetState(#Gadget_AddressMuncher_NameList)
      RecordNumber.s  = GetGadgetItemText(#Gadget_AddressMuncher_NameList, CurrentLine.i, Program\AddressColumn)
    Case "AddressForm"
      RecordNumber.s  = Program\CurrentAddressRecord
  EndSelect
  ; Setup a query to get the elements needed for the label
  DatabaseQuery.s = "SELECT "
  DatabaseQuery.s + "Title, Firstname, Middlename, Lastname, Pobox, Street, Suburb, City, "
  DatabaseQuery.s + "State, Postcode, Template "
  DatabseQuery.s  + "FROM Addresses "
  DatabaseQuery.s + "WHERE Record = '" +  RecordNumber.s + "'"
  ; 
  If DatabaseQuery(Program\DatabaseHandle, DatabaseQuery.s)
    ; Loop through all returned data
    While NextDatabaseRow(Program\DatabaseHandle)
      ; 
      Title.s       = KillQuote(GetDatabaseString(Program\DatabaseHandle,  0))
      Firstname.s   = KillQuote(GetDatabaseString(Program\DatabaseHandle,  1))
      Middlename.s  = KillQuote(GetDatabaseString(Program\DatabaseHandle,  2))
      Lastname.s    = KillQuote(GetDatabaseString(Program\DatabaseHandle,  3))
      PoBox.s       = KillQuote(GetDatabaseString(Program\DatabaseHandle,  4))
      Street.s      = KillQuote(GetDatabaseString(Program\DatabaseHandle,  5))
      Suburb.s      = KillQuote(GetDatabaseString(Program\DatabaseHandle,  6))
      City.s        = KillQuote(GetDatabaseString(Program\DatabaseHandle,  7))
      State.s       = KillQuote(GetDatabaseString(Program\DatabaseHandle,  8))
      Postcode.s    = KillQuote(GetDatabaseString(Program\DatabaseHandle,  9))
      Template.s    = KillQuote(GetDatabaseString(Program\DatabaseHandle, 10))
      ; 
    Wend
    FinishDatabaseQuery(Program\DatabaseHandle)
  EndIf
  ; 
  RequesterString.s = "Print label for:" + Chr(10) +  Chr(10) + Title.s + " " + Firstname.s + " " + Middlename.s + " " + Lastname.s + Chr(10)
  If PoBox.s <> ""
    RequesterString.s + PoBox.s + Chr(10)
  EndIf
  If Street.s <> ""
    RequesterString.s + Street.s + Chr(10)
  EndIf
  RequesterString.s + Suburb.s + " " + City.s + " " + State.s + " " + Postcode.s
  ; 
  If MessageRequester("Print label for current address.", RequesterString.s, #PB_MessageRequester_YesNo) = PB_MessageRequester_Yes
    ; 
    If Title.s        <> ""   : NameString.s    + Title.s         + " "     : EndIf ; Mr_
    If Firstname.s    <> ""   : NameString.s    + Firstname.s     + " "     : EndIf ; Gary_
    If Middlename.s   <> ""   : NameString.s    + Middlename.s    + " "     : EndIf ; John_
    If Lastname.s     <> ""   : NameString.s    + Lastname.s                : EndIf ; Rhinoceros
    If PoBox.s        <> ""   : PoBoxString.s   + PoBox.s                   : EndIf ; P.O Box 1238
    If Street.s       <> ""   : StreetString.s  + Street.s                  : EndIf ; 12 Rototruah Way
    If Suburb.s       <> ""   : SuburbString.s  + Suburb.s        + " "     : EndIf ; Wakatonky_
    If City.s         <> ""   : SuburbString.s  + City.s          + " "     : EndIf ; Braxtonia__
    If State.s        <> ""   : SuburbString.s  + State.s         + " "     : EndIf ; Hamilton_
    If Postcode.s     <> ""   : SuburbString.s  + Postcode.s                : EndIf ; 20398
    ; 
    If NameString.s   <> ""   : DymoString.s    + NameString.s    + #CRLF$  : EndIf
    If PoBoxString.s  <> ""   : DymoString.s    + PoBoxString.s   + #CRLF$  : EndIf
    If StreetString.s <> ""   : DymoString.s    + StreetString.s  + #CRLF$  : EndIf
    If SuburbString.s <> ""   : DymoString.s    + SuburbString.s            : EndIf
    ; 
    MakeDymoLabel(DymoString.s, Template.s)
    ; 
  Else
    Debug "User elected to cancel the label print job."
  EndIf
  ; 
EndProcedure                                                                                  ; 
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Little_man
Enthusiast
Enthusiast
Posts: 152
Joined: Fri Mar 29, 2013 4:55 pm
Location: The Netherland

Re: Question Dymolabelwriter

Post by Little_man »

I have already the code below:

Code: Select all

EnableExplicit
Global Text.s
Global Dymo_label.s

Procedure Dymo_PrintLabel(Text.s, Dymo_Labels.s)
  Protected Fill.l
  Protected Dymo_label.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>", "")

  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))
  
  Fill.l = CreateFile(#PB_Any, GetCurrentDirectory() + "Dymo.vbs")
    WriteStringN(Fill.l, "Dim DymoAddIn")
    WriteStringN(Fill.l, "Dim DymoLabel")
    WriteStringN(Fill.l, "Set DymoAddIn  =  CreateObject(" + Chr(34) + "DYMO.DymoAddIn"  + Chr(34) + ")")
    WriteStringN(Fill.l, "Set DymoLabel  =  CreateObject(" + Chr(34) + "DYMO.DymoLabels" + Chr(34) + ")")
    
    If FileSize(GetCurrentDirectory() + Dymo_label.s) > 3
      WriteStringN(Fill.l, "DymoAddIn.Open " + Chr(34) + GetCurrentDirectory() + Dymo_Label.s + Chr(34))
    EndIf
    
    WriteStringN(Fill.l, "DymoLabel.SetAddress 1, " + Chr(34) + Text.s + Chr(34))
    WriteStringN(Fill.l, "DymoAddIn.Print 1, TRUE")  
  CloseFile(Fill.l)
  RunProgram(GetCurrentDirectory() + "Dymo.vbs", "", "",#PB_Program_Hide)
  ;CompilerEndIf

  If FileSize(GetCurrentDirectory() + "Dymo.vbs") > 0
    DeleteFile(GetCurrentDirectory() + "Dymo.vb")
  EndIf
EndProcedure

Text.s       =  "Name" + #CRLF$ + "Addres" + #CRLF$ + "Zipcode City" + #CRLF$ + "Country"
Dymo_label.s = "Adres (breed).lwa"
Dymo_PrintLabel(Text.s, Dymo_Label.s)
But is it to do without a script-file ?
Little_man
Enthusiast
Enthusiast
Posts: 152
Joined: Fri Mar 29, 2013 4:55 pm
Location: The Netherland

Re: Question Dymolabelwriter

Post by Little_man »

In Visual Basic 6.0:

Code: Select all

    ;This function uses high-level OLE to have VB communicate with Dymo Label                                
    ;Software.  It uses the PrintAddress sample form in VB to print out the Address                          
    ;on the label in Dymo Label Software.
                                                
    Dim q, LabelFileType As String
    
    ;Dymo_String$(0) = "Text for Label"                                                
    ;Dymo_String$(1) = "Label name"                                                                          
    ;Dymo_String$(2) = "making copies"                                                                     
    LabelFileType$   = 
    
    ;Create Dymo OLE objects.                                                                                
    Call CreateOLEObjects
    
    ; Open the template Dymo Label.                                      
    DymoAddIn.Open (Dymo_String$(1))

    ;Place the text on te label.   
    DymoLabels.SetAddress 1, Dymo_String$(0)
    DymoLabels.SetField "Address", Dymo_String$(0)

    q = DymoAddIn.Print(CLng(Val(Dymo_String$(2))), True)
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Question Dymolabelwriter

Post by jesperbrannmark »

Hi.
I posted some code a while back that was the VBS and then run it thou CMD line.
However, there is differences in Dymo version 7 and 8.
Version 7 works with VBS, version 8 does not.
I do version 8 using javascript actually.
And I think it can be a good idea to look at their website for the JS code, since the version 7 is a bit old and outdated...
Little_man
Enthusiast
Enthusiast
Posts: 152
Joined: Fri Mar 29, 2013 4:55 pm
Location: The Netherland

Re: Question Dymolabelwriter

Post by Little_man »

jesperbrannmark; Thanks for Information
Post Reply