Global $openPath = "F:\Users\Darren\Documents\Astronomy\BAS\" Global $varDSP = "Deep-Sky Planner 6" Global $varDET = "Define Ephemeris Time" Global $varPrintLabel = "Print" Global $varSaveHTMLLabel = "Save As" Global $varSavePDFLabel = "Save As" Global $varOpen = "Open" Global $SolarSystem = StringSplit("Sun,Mercury,Venus,Mars,Jupiter,Saturn,Neptune,Uranus,Pluto,Moon", ",", 2) Global $Reports = StringSplit("bas_simple.plncalc,bas_detailed.plncalc", ",", 2) Global $iLoop Global $Loop1 Global $savePath="F:\Users\Darren\Documents\Astronomy\BAS\Ephemeris\" & StringFormat("%02s",@MON) & StringRight(@YEAR,2) Global $htmlFiles=$savePath & "*.htm" Global $pdfFiles=$savePath & "*.pdf" ; Clear out any files that may have been run already for this month if FileExists($htmlFiles) Then FileDelete($htmlFiles) FileDelete($pdfFiles) EndIf ; Open DSP if not WinExists($varDSP) Then run("C:\Program Files (x86)\Knightware\Deep-Sky Planner 6\Dsp6.exe") Sleep(5000) Else WinActivate($varDSP) EndIf ; Report Loop For $Loop1 = 0 to 1 ; Open the report Send("!fo") WinWaitActive($varOpen) ControlSetText($varOpen, "", "[ID:1148]", $openPath & $Reports[$Loop1]) sleep(500) ControlClick($varOpen, "", "[ID:1]") if $Loop1 = 0 Then send("b") Else send("d") endif ; Select the 'Other' button Sleep(1000) ControlClick("", "Othe&r", "TButton6") WinWaitActive($varDET) ; Click Next Month, then OK, then Calculate ; 8 is Next month, 9 is This month ControlClick($varDET,"","TButton9") ControlClick($varDET,"","TButton3") ; Loop through the solar system objects for $iLoop = 0 to UBound($SolarSystem) - 1 ControlSend($varDSP, "", "[CLASS:TListBox; INSTANCE:1]", $SolarSystem[$iLoop]) CalculateReport() if $Loop1 = 0 Then ExportHTML($SolarSystem[$iLoop], "B") Sleep(1000) ExportPDF($SolarSystem[$iLoop], "B") Else ExportHTML($SolarSystem[$iLoop], "D") Sleep(1000) ExportPDF($SolarSystem[$iLoop], "D") EndIf Next ; Save and Close the report Send("!fl") sleep(500) ControlClick("Confirm","&No","[CLASS:Button; INSTANCE:2]") Next ;Close DSP Send("!fi") Exit Func CalculateReport () ; Click the calculate button ControlClick($varDSP,"","TButton4") Sleep(2000) EndFunc Func ExportHTML (ByRef $object , $type) local $in=$savePath & $object, $out="" local $varSave $varSaveLabel=$varSaveHTMLLabel if $type = "B" then $in = $in & ".htm" Else $in = $in & "_det.htm" Endif send("!feh") WinWaitActive($varSave) Do ControlSetText($varSaveLabel, "" , "[ID:1001]", $in) Sleep(500) ControlSetText($varSaveLabel, "" , "[ID:1001]", "") Sleep(500) ControlSetText($varSaveLabel, "" , "[ID:1001]", $in) Sleep(500) $out=ControlGetText($varSaveLabel, "", "[ID:1001]") If $in<>$out Then ConsoleWrite("HTML path does not match - rewriting" & @CRLF) Exit EndIf Until $in=$out ControlClick($varSaveLabel, "", "[ID:1]") EndFunc Func ExportPDF (ByRef $object, $type) local $in=$savePath & $object, $out="" local $saveTime local $varSaveLabel=$varSavePDFLabel if $type = "B" then $in = $in & ".pdf" $saveTime=2000 Else $in = $in & "_det.pdf" $saveTime=2000 Endif ConsoleWrite("Path= " & $in & @CRLF) Send("!fp") WinWaitActive($varPrintLabel) ControlCommand($varPrintLabel, "", "[ID:1139]", "ShowDropDown") sleep(500) ControlSend($varPrintLabel, "", "[ID:1139]", "CutePDF Writer") Sleep(500) ControlClick($varPrintLabel, "", "[ID:1025]") WinWaitActive("CutePDF Writer Document Properties") Sleep(500) ControlCommand("CutePDF Writer Document Properties", "", "[ID:1232]", "ShowDropDown") Sleep(500) ControlSend("CutePDF Writer Document Properties", "", "[ID:1232]", "Landscape") Sleep(500) ControlClick("CutePDF Writer Document Properties", "", "[ID:1]") ControlClick($varPrintLabel, "", "[ID:1]") WinWaitActive($varSaveLabel) Do ControlSetText($varSaveLabel, "" , "[ID:1152]", $in) $out=ControlGetText($varSaveLabel, "", "[ID:1152]") If $in<>$out Then ConsoleWrite("PDF path does not match" & @CRLF) Exit EndIf Until $in=$out send("!s") ; Wait for the Sleep($saveTime) EndFunc