KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method To Get Printers List In an Object
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: September 27, 2018

Below is a Utility Method to get the list of printers visible to 4D in an Object:

// Method: Util_Printers_List_To_Object
// Description: Outputs the list of printer's names,
//     alternative names, and models to an object

//
// Output: Object output of printers list
//
// ---------------------------------------------------------------------------

C_OBJECT($0)

ARRAY TEXT($print_at;0)
ARRAY TEXT($alt_at;0)
ARRAY TEXT($models_at;0)
C_OBJECT($printList_ob)
C_LONGINT($i)
C_TEXT($result_t)

PRINTERS LIST($print_at;$alt_at;$models_at)

$printList_ob:=New object

For ($i;1;Size of array($print_at))
   $printList_ob["Printer "+String($i)]:=New object
   $printList_ob["Printer "+String($i)].Name:=$print_at{$i}
   $printList_ob["Printer "+String($i)].AltName:=$alt_at{$i}
   $printList_ob["Printer "+String($i)].Model:=$models_at{$i}
End for

$0:=$printList_ob


Example of use of the method:
C_OBJECT($result_ob)
$result_ob:=Util_Printers_List_To_Object
$result_t:=JSON Stringify($result_ob;*)
SET TEXT TO PASTEBOARD($result_t)

Results in:
{
   "Printer 1": {
      "Name": "Send To OneNote 2016",
      "AltName": "nul:",
      "Model": "Send to Microsoft OneNote 16 Driver"
   },
   "Printer 2": {
      "Name": "Send To OneNote 2010",
      "AltName": "nul:",
      "Model": "Send To Microsoft OneNote 2010 Driver"
   },
   "Printer 3": {
      "Name": "PDFCreator",
      "AltName": "pdfcmon",
      "Model": "PDFCreator"
   },
   "Printer 4": {
      "Name": "Microsoft XPS Document Writer",
      "AltName": "XPSPort:",
      "Model": "Microsoft XPS Document Writer"
   },
   "Printer 5": {
      "Name": "Fax",
      "AltName": "SHRFAX:",
      "Model": "Microsoft Shared Fax Driver"
   }
}