JessicaJG Posted February 14, 2018 Share Posted February 14, 2018 Hello, I am trying to automate the printing of PDF files from a dashboard that I created in Tableau. I found a "how to" video suggesting that I use AutoIT and it looked to be exactly what I needed so I tried it. I have been unable to get my script to work at all however, even when I used the sample script provided by the author of the video. Therefore, I've come here to ask for help. I was able to find the various _Excel functions that let me get my excel workbook to open, but I can't find anything similar for Tableau. Here is my script, if anyone can help me figure out how to get this working it would be a great help to me. ; This script shows how to use AutoIt to print multiple Tableau dashboard to PDF files based on a parameter ; all values of the parameter are copied to an Excel file, startig with cell A2. When Excel is first opened, ; the active cell is A1, which is blank ; The default printer has been set to PDF. The option "View PDF after printing" has been disabled #include<excel.au3> Local $excelfile = "E:\AutoIT Scripts\Category.xlsx" ;this is the location and name of my excel file Local $oExcel_1 = _Excel_Open() Local $tableaufile = "E:\AutoIT Scripts\DemoForPOC" ;this is the location and name of my tableau file Local $repeattime = 3 for $i = 3 to $repeattime _Excel_BookOpen($oExcel_1, $excelfile); this opens the Excel file with the filter values Send("{DOWN}"); Send a down arrow, which moves cursor to cell A2 Send("^c");Copy value in cell A2. For all menu command, use lower case if upper case doesn't work sleep(1000) WinActivate($tableaufile); Activate Tableau - NOT WORKING FROM THIS POINT ONWORD... WinWaitActive($tableaufile); waiting for Tableau window to show up MouseClick("Left",848,120); click the parameter window Send("{BACKSPACE 3}"); delete existing content Sleep(1000); wait 1 second Send("^v"); paste in new code from the Excel file Send("{ENTER}"); Send enter key Do sleep(500) until WinExists("Computing visualization of ")= 0 ; wait until tableau finishes processing Send("^p"); print out current dashboard WinWaitActive("Print"); wait for print window to show up sleep(1000) Send("{ENTER}");send enter to select ADOBE PDF printer WinWaitActive("Save PDF File As"); wait for window to prompt for file name Send("^v"); send paremeter name as file name Send("{Enter}"); print sleep(3000); wait until ADOBE finishes printing Next msgbox(0,"Complete","Finished printing. Please verify the output and compile into one document using binder.") Category.xlsx DemoForPOC.twb ScriptforAutoITTableauDemo.au3 Link to comment Share on other sites More sharing options...
Subz Posted February 15, 2018 Share Posted February 15, 2018 You need to get the Tableaus Window Handle, so something like: expandcollapse popup; This script shows how to use AutoIt to print multiple Tableau dashboard to PDF files based on a parameter ; all values of the parameter are copied to an Excel file, startig with cell A2. When Excel is first opened, ; the active cell is A1, which is blank ; The default printer has been set to PDF. The option "View PDF after printing" has been disabled #include <Array.au3> #include <Excel.au3> Local $sExcelFile = "E:\AutoIT Scripts\Category.xlsx" ;this is the location and name of my excel file Local $oExcel = _Excel_Open() Local $oWorkBook = _Excel_BookOpen($oExcel, $sExcelFile) Local $aWorkBook = _Excel_RangeRead($oWorkBook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) _Excel_Close($oExcel) Local $hTableauWnd Local $sTableauWndTitle = "Tableau - DemoForPOC" If WinExists($sTableauWndTitle, "") Then $hTableauWnd = WinGetHandle($sTableauWndTitle, "") Else Local $iTableauPid = ShellExecute("E:\AutoIT Scripts\DemoForPOC\DemoForPOC.twb") WinWaitActive($sTableauWndTitle, "", 15) $hTableauWnd = _ProcessWindow($iTableauPid) EndIf For $i = 0 To UBound($aWorkBook) - 1 WinActivate($hTableauWnd); Activate Tableau - NOT WORKING FROM THIS POINT ONWORD... WinWaitActive($hTableauWnd); waiting for Tableau window to show up MouseClick("Left",848,120); click the parameter window Send("{BACKSPACE 3}"); delete existing content Sleep(1000); wait 1 second Send($aWorkBook[$i]); paste in new code from the Excel file Send("{ENTER}"); Send enter key Do sleep(500) until WinExists("Computing visualization of ")= 0 ; wait until tableau finishes processing Send("^p"); print out current dashboard WinWaitActive("Print"); wait for print window to show up sleep(1000) Send("{ENTER}");send enter to select ADOBE PDF printer WinWaitActive("Save PDF File As"); wait for window to prompt for file name Send($aWorkBook[$i]); send paremeter name as file name Send("{Enter}"); print sleep(3000); wait until ADOBE finishes printing Next msgbox(0,"Complete","Finished printing. Please verify the output and compile into one document using binder.") Func _ProcessWindow($iPID) Local $hWnd If ProcessExists($iPID) = 0 Then Exit MsgBox(32, "Error", "Process cannot be found") Local $aWinList = WinList() For $i = 1 to $aWinList[0][0] If $aWinList[$i][0] <> "" And BitAnd(WinGetState($aWinList[$i][1]),2) Then $hWnd = WinGetProcess($aWinList[$i][0]) If $hWnd = $iPID then Return $aWinList[$i][0] EndIf Next MsgBox(32, "Error", "Process cannot be found") Exit EndFunc JessicaJG 1 Link to comment Share on other sites More sharing options...
JessicaJG Posted February 16, 2018 Author Share Posted February 16, 2018 Thank you! I'll try that! Link to comment Share on other sites More sharing options...
martinberlin Posted August 3, 2018 Share Posted August 3, 2018 Hello, thanky you very much for your help. I am trying to use this script and is seems to work fine until this point and then it stops here. WinWaitActive("Save PDF File As"); wait for window to prompt for file name Send($aWorkBook[$i]); send paremeter name as file name Send("{Enter}"); print sleep(3000); wait until ADOBE finishes printing It does open the window, but it does not enter what I entered into the search filter and it does not save it. Any idea why that might be? Could you please help me with that? Your help would be greatly appreciated. Thanks Link to comment Share on other sites More sharing options...
water Posted August 3, 2018 Share Posted August 3, 2018 Do not use Send to automate the parameter window. Use the AutoIt Window Info Tool to get the IDs of the controls and then use Control* functions to automate this controls. Much more reliable My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
martinberlin Posted August 6, 2018 Share Posted August 6, 2018 Hello Water, would you mind providing an example for this? I am completely new to AutoIt so some example would be really helpful. Martin Link to comment Share on other sites More sharing options...
water Posted August 6, 2018 Share Posted August 6, 2018 This are the functions I use in another project to print PDF files. If needed I can translate the german comments. expandcollapse popup;=============================================================================== ; Function _PrintPDF ; PDF Datei ausdrucken ;=============================================================================== Func _PrintPDF() _Splash() ShellExecute($AcrobatReader, '"' & $In & '"') $DocumentOpened = 1 $TitelPDF = $InName & ".PDF - Adobe Reader" $RC = WinWait($TitelPDF) $RC = WinActivate($TitelPDF) ;---------------------------------------- ; Ctrl-P: Drucken ;---------------------------------------- $RC = Send("^p") $TitelDrucken = "Drucken" $RC = WinWait($TitelDrucken, "") $RC = WinActivate($TitelDrucken, "") ;---------------------------------------- ; Favorit des Druckers einrichten - Button Eigenschaften ;---------------------------------------- $RC = ControlClick($TitelDrucken, "", "[CLASSNN:Button2]") $TitelEinrichten = "Eigenschaften von " $RC = WinWait($TitelEinrichten, "") $RC = WinActivate($TitelEinrichten, "") ;---------------------------------------- ; Favorit einrichten ;---------------------------------------- $RC = ControlCommand($TitelEinrichten, "", "[CLASSNN:ComboBox1]", "SelectString", $Favorit) ;---------------------------------------- ; OK Button klicken ;---------------------------------------- $RC = ControlClick($TitelEinrichten, "", "[CLASSNN:Button35]") If $Groesse <> "" Then ;---------------------------------------- ; Button: Seite einrichten ;---------------------------------------- $RC = ControlClick($TitelDrucken, "", "[CLASSNN:Button45]") $TitelEinrichten = "Seite einrichten" $RC = WinWait($TitelEinrichten, "") $RC = WinActivate($TitelEinrichten, "") ;---------------------------------------- ; Papierformat festlegen ;---------------------------------------- $RC = ControlCommand($TitelEinrichten, "", "[CLASSNN:ComboBox1]", "SelectString", $Groesse) If @error Then MsgBox(4096, @ScriptName, "Format '" & $Groesse & "' ist auf dem Drucker '" & $Drucker & "' nicht definiert.") $RC = Send("{ESC}") $TitelDrucken = "Drucken" $RC = WinWaitActive($TitelDrucken, "") $RC = Send("{ESC}") _ClosePDF("") SetError(3) Return EndIf ;---------------------------------------- ; OK Button klicken ;---------------------------------------- $RC = ControlClick($TitelEinrichten, "", "[CLASSNN:Button6]") EndIf ;---------------------------------------- ; Name des Druckers festlegen ;---------------------------------------- #cs $RC = ControlCommand($TitelDrucken, "", "[CLASSNN:ComboBox1]", "SelectString", $Drucker) If @error Then MsgBox(4096, @ScriptName, "Drucker '" & $Drucker & "' ist auf diesem System nicht definiert.") $RC = WinWaitActive($TitelDrucken, "") $RC = Send("{ESC}") _ClosePDF("") SetError(2) Return EndIf #ce ;---------------------------------------- ; Button "Größe" klicken ;---------------------------------------- $RC = ControlClick($TitelDrucken, "", "[CLASSNN:Button13]") ;---------------------------------------- ; Übergroße Seiten verkleinern ;---------------------------------------- $RC = ControlCommand($TitelDrucken, "", "[CLASSNN:Button19]", "Check", "") #cs - Wird ignoriert - Favorit dazu verwenden ;---------------------------------------- ; Beidseitig drucken ;---------------------------------------- $RC = ControlCommand($TitelDrucken, "", "[CLASSNN:Button28]", "UnCheck", "") If $Zweiseitig = "Ja" Then $RC = ControlCommand($TitelDrucken, "", "[CLASSNN:Button28]", "Check", "") #ce ;---------------------------------------- ; Anzahl Exemplare ;---------------------------------------- $RC = ControlSetText($TitelDrucken, "", "[CLASSNN:RICHEDIT50W1]", $Exemplare) ;---------------------------------------- ; Sortieren - damit bei mehreren Kopien in Reihenfolge 1,2,3 - 1,2,3 ; und nicht 1,1 - 2,2 - 3,3 gedruckt wird ;---------------------------------------- If $Exemplare > 1 Then $RC = ControlCommand($TitelDrucken, "", "[CLASSNN:Button1]", "Check", "") ;---------------------------------------- ; Papierquelle anhand der PDF Seitengröße auswählen ;---------------------------------------- If $Groesse = "" Then $RC = ControlCommand($TitelDrucken, "", "[CLASSNN:Button21]", "Check", "") Else $RC = ControlCommand($TitelDrucken, "", "[CLASSNN:Button21]", "UnCheck", "") EndIf ;---------------------------------------- ; Drucken Button klicken ;---------------------------------------- $RC = ControlClick($TitelDrucken, "", "[CLASSNN:Button47]") ;---------------------------------------- ; Warten bis Druckvorgang beendet ist ;---------------------------------------- $RC = WinWait("Vorgang wird bearbeitet", "") $RC = WinWaitClose("Vorgang wird bearbeitet", "") ;---------------------------------------- ; Datei beenden ;---------------------------------------- _ClosePDF("") EndFunc ;==>_PrintPDF ;=============================================================================== ; Function _ClosePDF ; Aktuell offene PDF Datei schliessen ;=============================================================================== Func _ClosePDF($Param) If $Param = "F" Then $TitelPDF = "Adobe Reader" Else $TitelPDF = $InName & ".PDF - Adobe Reader" EndIf WinWait($TitelPDF) WinActivate($TitelPDF) WinWaitActive($TitelPDF) If $Param = "F" Then Send("^q") Else Send("^w") EndIf EndFunc ;==>_ClosePDF My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
kangwei Posted October 11, 2019 Share Posted October 11, 2019 Hi, I am interested to use Tableau to split my files into different twbx files and send them out. There are around 100 files to be split. Anyone got the code to get this done effectively? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now