; ; LOLA.WBT ; Revision 10/09/00 5:49pm - added comments below after confirming 110 now work. ; ; Fixed problem with 110/120/130 # of files in folder, ie numbers ending with 0. ; Changed the following line: ; ; if len!=1 && secnum!=0 ;if filecount !evenly divisible by 100, then there will 1 more run after timesthru ; to: ; if secnum!=0 ;if filecount !evenly divisible by 100, then there will 1 more run after timesthru, ie lastrun=1 ; ; ; ; added new F-key action file stuff ; ; commented out the trace files ; ; in lines 211-233 I added space for 6 characters to name the folder to be more descriptive ;***************************************************************************** i=1 ; Used later in handle for LogFile1.txt. Initializing it here... j=1 ; Used later in handle2 for LogFile2.txt m=1 ; Used later in trace%m%.txt countfiles=0 endoffile=0 finaltime=0 ; Initialize the variable that checks to see if we're on the last loop through KERCHUNK timebeg=TimeYmdHms() ;get the beginning time of the job ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FileTypeFormat=`WWWDLGED,5.0` FileTypeCaption=`Choose Image File Type` FileTypeX=57 FileTypeY=74 FileTypeWidth=158 FileTypeHeight=90 FileTypeNumControls=6 FileType01=`8,8,145,DEFAULT,STATICTEXT,DEFAULT,"Please select the image file type you would like to process:"` FileType02=`54,25,51,DEFAULT,RADIOBUTTON,def,"JPG image files",1` FileType03=`54,40,51,DEFAULT,RADIOBUTTON,def,"TIF image files",2` FileType04=`54,54,51,DEFAULT,RADIOBUTTON,def,"BMP image files",3` FileType05=`14,73,51,DEFAULT,PUSHBUTTON,DEFAULT,"OK",1` FileType06=`84,73,51,DEFAULT,PUSHBUTTON,DEFAULT,"Cancel",0` ButtonPushed=Dialog("FileType") jpg=0 tif=0 bmp=0 if def==1 then jpg=1 ;ok, they want jpg files if def==2 then tif=1 ;ok, they want tif files if def==3 then bmp=1 ;ok, they want bmp files ;~~~~~~~~~~~~~~~~~~~~Get the SOURCE and DESTINATION directories~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ flags=1|2 dir1=AskDirectory("Directory #1: Choose the SOURCE directory where your image source files are located:","","", "Directory Path selected was:",flags) dir2="C:\WORKING\" ;set working directory DirChange("C:\") ;change to root of C:\ before doing DirMake TimeDelay(0.5) if !DirExist("C:\WORKING") then DirMake("C:\WORKING") DirChange(dir1) ;now change to source directory ;if FileExist("D:\firsttrace.txt") then FileDelete("D:\firsttrace.txt") ;DebugTrace(@on, "D:\firsttrace.txt") ;~~~~~~~~~~~~~~~~~Now Count the Files in the Source Directory and Do a Little Math~~~~~~~~~~~~~~~~~ dafiles=FileItemize(strcat(dir1,"*.*")) ;itemize the files in the source directory filecount=ItemCount(dafiles,@tab) ;count the files if filecount>100 ;see if the count is larger than 100 timesthruX=filecount/100.0 ;if so, divide the count by 100 timesthru=ItemExtract(1,timesthruX,".") ;this extracts out the first number secnum=ItemExtract(2,timesthruX,".") ;look at the number after the decimal ;len=StrLen(secnum) ;get the length of this number //LP 10/09/00 this variable not needed now if secnum!=0 ;if filecount !evenly divisible by 100, then there will 1 more run after timesthru, ie lastrun=1 ;;; if len!=1 && secnum!=0 ;if filecount !evenly divisible by 100, then there will 1 more run after timesthru //LP 10/09/00 bufix above lastrun=1 else lastrun=0 endif onetime=0 ;need to run more than once ;the following used later in FOR loop that goes through the file list if lastrun==1 && timesthru<2 ;x1="1 to 100" nextcount=101 endif if timesthru==2 ;x2="101 to 200" nextcount=201 endif if timesthru==3 nextcount=301 endif if timesthru==4 nextcount=401 endif if timesthru==5 nextcount=501 endif if timesthru==6 nextcount=601 endif if timesthru==7 nextcount=701 endif if timesthru==8 nextcount=801 endif if timesthru==9 nextcount=901 endif if timesthru==10 nextcount=1001 endif else timesthru=1 ;if there are < than 100 files, then got thru loop 1x. onetime=1 ;Flag that indicates there are < than 100 files in source lastrun=0 endif ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dir3=AskDirectory("Directory #2: DESTINATION directory for finished files (MUST be a subfolder within your drive):","","", "Directory Path selected was:",flags) pass=1 ;pass=1 for first pass; pass=2 for second pass flagpass=0 ;flagpass=0 for first pass; flagpass=1 for second pass ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~New Ask Dialog Box for the Randomplot.xls location~~~~~~~~~~~~~~ xlsdir=AskDirectory("Directory #3: Where is your RANDOMPLOT.XLS file located?","","", "Directory Path selected was:",flags) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;timewait("00:00:00:23:00:00") ;this needs to be commented out eventually after betatesting is over ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~Startup the old JALOPY and go through some contortions~~~~~~~~~~~~~~~~ dacounter=1 ;counter to be used by strcat("logfile",pass,"_",dacounter,".txt") For xyz=timesthru to 1 by -1 ;we'll loop through the number of timesthru and decrement to 1 until we get to 0 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :KERCHUNK ;if FileExist("D:\trace%m%.txt") then FileDelete("D:\trace%m%.txt") ;DebugTrace(@on, "D:\trace%m%.txt") m=m+1 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~FIRST RUN: Startup Excel and run Random Plot 3X~~~~~~~~~~~~~~~~~~~~~ if !WinExist("~Microsoft Excel") then run(strcat(xlsdir,"randomplot.xls"), "") ;starts up Excel with randomplot.xls (location was specified by user) Sendkeysto("~Microsoft Excel", "!e") ;now run the macro 3 times to get it warmed up Sendkeysto("~Microsoft Excel", "^+p") TimeDelay(10) Sendkeysto("~Microsoft Excel", "^+p") TimeDelay(3) Sendkeysto("~Microsoft Excel", "^+p") TimeDelay(3) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~START UP PHOTOSHOP AND DO IT!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;Add registry lookup here to find where Photoshop is located. Errormode(@off) adobeloc=RegQueryValue(@regmachine, "Software\Microsoft\Windows\CurrentVersion\App Paths\Photoshp.exe[]") Errormode(@cancel) if adobeloc=="" then adobeloc=AskDirectory("Please browse to find your PHOTOSHP.EXE file:","","", "Directory Path selected was:",flags) if !WinExist("~Adobe Photoshop") then Run(adobeloc, "") TimeDelay(10) if WinExist("~alert") Sendkeysto("~alert", "{ENTER}") endif while @true if WinExist("~Adobe Photoshop") ;test to see if Adobe is ready for input ;IntControl(43,0,0,0,0) ;maybe add this in later if the sendkey still isn't working SendKeysTo("~Adobe Photoshop", "{TAB}") ;to hide toolbar - getting 1045 error on this line break else Timedelay(0.5) endif endwhile ;Temporarily change the title of the Adobe Photoshop window if !Winexist("ChopChop") WinTitle("~Adobe Photoshop", "ChopChop") endif ;now start dealing with the Adobe window by it's unique window identifier adobewin=WinIDGet("ChopChop") ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Initialize some critical variables~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;timebeg=TimeYmdHms() deskdir=ShortcutDir("Desktop") ;get Desktop directory ;~~~~~~~~~~~~~~THIS IS THE MAIN LOG FILE - THERE WILL BE A PASS1 and a PASS2 LOGFILE~~~~~~~~~~~~~~~ handle=FileOpen(strcat(deskdir,"\",strcat("logfile",pass,"_",dacounter,".txt")),"WRITE") ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~LOGFILE CLOSED AROUND LINE 323 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ BoxOpen("Initializing...", "Image File Processing") ;~~~~~~~~~~~~~~~~~~~~~~~~~~~Start working with the files in the source~~~~~~~~~~~~~~~~~~~~~~~~~~ DirChange(dir1) ;SOURCE directory ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;Here's where we distinguish between the folks who want to process jpg's versus other files types: if jpg==1 myfiles=FileItemize("*.jpg") ext="jpg" drafthorse=strcat(dir2,"drafthorse.%ext%") ;drafthorse can now have 1 of 3 file extensions getfirstfile=ItemExtract(1,myfiles,@tab) name=StrSub(getfirstfile,3,6) ;here's where we pull out the 6-char filename (like "tran01") endif if tif==1 myfiles=FileItemize("*.tif") ext="tif" drafthorse=strcat(dir2,"drafthorse.%ext%") ;drafthorse can now have 1 of 3 file extensions getfirstfile=ItemExtract(1,myfiles,@tab) name=StrSub(getfirstfile,3,6) ;here's where we pull out the 4-char filename (like "tran") endif if bmp==1 myfiles=FileItemize("*.bmp") ext="bmp" drafthorse=strcat(dir2,"drafthorse.%ext%") ;drafthorse can now have 1 of 3 file extensions getfirstfile=ItemExtract(1,myfiles,@tab) name=StrSub(getfirstfile,3,6) ;here's where we pull out the 4-char filename (like "tran") endif ;Whatever they want, count them up... count=ItemCount(myfiles,@tab) if FileExist(drafthorse) then FileDelete(drafthorse) ;~~~~~~~~~~~~~~~~~~~~~~this is the loop for the last run through~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if finaltime!=1 then goto JUSTONCE ;continue on with the next bit of code if finaltime==1 ;:LASTFILES ;work on the last few files now For i=nextcount to count ;(1) for i=nextcount to count myjpg=ItemExtract(i,myfiles,@tab) root=FileRoot(myjpg) ;extract out first 2 characters of filename x=StrSub(root,1,2) goto THECRUX ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :JUSTONCE ;~~~~~~~~~~~~~~~~~~~~~~~Move through files in dafiles 100 at a time~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;if we have less than 100 to begin with, do 'em all and get out if onetime!=1 then goto BIGFOR ;continue on with the next bit of code if onetime==1 For i=1 to count ;(2) for i=1 to count myjpg=ItemExtract(i,myfiles,@tab) root=FileRoot(myjpg) ;extract out first 2 characters of filename x=StrSub(root,1,2) finaltime=1 goto THECRUX ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :BIGFOR ;~~~~~~~~~~~~~~~~~~~~~~~~~~~Here's where we do the BEEG BEEG For loop~~~~~~~~~~~~~~~~~~~~~~~~~~~ if dacounter==1 then p=1 if dacounter==2 then p=101 if dacounter==3 then p=201 if dacounter==4 then p=301 if dacounter==5 then p=401 if dacounter==6 then p=501 if dacounter==7 then p=601 if dacounter==8 then p=701 if dacounter==9 then p=801 if dacounter==10 then p=901 For i=p to p+99 myjpg=ItemExtract(i,myfiles,@tab) root=FileRoot(myjpg) ;extract out first 2 characters of filename x=StrSub(root,1,2) ;~~~~~~~~THE CRUX THE CRUX THE CRUX THE CRUX THE CRUX THE CRUX THE CRUX THE CRUX THE CRUX~~~~~~~~~~ ;~~~~~And here's where we'll rerun this subroutine for this and subsequent cleanup runs~~~~~~~~~~~~ :THECRUX ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Adobe Window Title~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;Temporarily change the title of the Adobe Photoshop window if !Winexist("ChopChop") WinTitle("~Adobe Photoshop", "ChopChop") endif ;now start dealing with the Adobe window by it's unique window identifier adobewin=WinIDGet("ChopChop") ;WinActivate("") ; see if this brings the box to the foreground again BoxTitle("Image File Processing...") IntControl(54,"Image File Processing...",1,0,0) ;keep the Winbatch window on top if pass==2 BoxText("SECOND PASS!!!%@crlf%Current Image #%j% of %n% Total Images%@crlf%%@crlf%Current JPG File Name=%myjpg%") else BoxText("Current Image #%i% of %count% Total Images%@crlf%%@crlf%Current JPG File Name=%myjpg%") endif Timedelay(1) if endoffile!=1 ;don't copy the file unless we're not at the end of the Unprocessed_files.txt ;below we're copying the original jpg to the workingdir FileCopy(myjpg,drafthorse,@false);<=Directory#2 endif TimeDelay(1) IntControl(54,"Image File Processing...",0,0,0) ;let the Winbatch window drop behind here ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Now let 'er rock~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WinActivate("~Excel") TimeDelay(0.5) Sendkeysto("~Excel", "^+P") TimeDelay(3) WinActivate(adobewin) TimeDelay(0.5) MouseMove(500,500,"","") Mouseclick(@LCLICK,0) TimeDelay(1) if jpg==1 Sendkeysto(adobewin, "{F5}") ;F5 - uses OPEN c:\working\drafthorse.JPG action file endif if bmp==1 Sendkeysto(adobewin, "{F6}") ;F6 - uses OPEN c:\working\drafthorse.BMP action file endif if tif==1 Sendkeysto(adobewin, "{F7}") ;F7 - uses OPEN c:\working\drafthorse.TIF action file endif TimeDelay(2) Sendkeysto(adobewin, "{F8}") ;F8 - Paste, clear and move action file TimeDelay(4) Sendkeysto(adobewin, "{F9}") ;F9 - Flatten, purge and close action file TimeDelay(3) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;The following part commented out 01/14/00 - since it was looping for 1-1/2 hrs on image #214 ;Put back in 01/26/00 to use with the 100 files approach. while @true if WinExist("~Adobe Photoshop") Sendkeysto("~Adobe Photoshop", "!y") ;<== this is where it saves the image break else TimeDelay(0.5) endif endwhile ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ IntControl(54,"Image File Processing...",1,0,0) ;keep the Winbatch window on top for now TimeDelay(3) ;<== add the box back in here ;~~~~~~~~Add some testing here to make sure Adobe doesn't still have it's paws on the file~~~~~~~~~ while @true if FileSize(drafthorse)==0 TimeDelay(1) else break endif endwhile while @true if FileExist(drafthorse)==2 TimeDelay(1) else ;Now copy the file we just worked on to destination directory (Directory #3) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~And a leetle beet of magick~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If !DirExist("%dir3%%x%%name%") then DirMake("%dir3%%x%%name%") FileCopy("%dir2%drafthorse.%ext%", "%dir3%%x%%name%\%root%.%ext%",@false) break endif endwhile if pass!=2 ;this means we're still in the first pass FileWrite(handle,strcat(i,@tab,myjpg)) else ;otherwise we're in the 2nd pass FileWrite(handle2,strcat(j,@tab,myjpg)) ;write the counter "n" into logfile2.txt j=j+1 endif BoxText("%myjpg% copied to:%@crlf%%dir3%%x%%name% directory") ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TimeDelay(1) FileDelete(drafthorse) TimeDelay(1) if pass==2 FileClose(handle2) ;this corresponds to the FileOpen on line ~76 endif ;~~~~~~Now RETURN RETURN RETURN to the calling part of the CLEANUP script if we're in PASS 2+~~~~~~ if pass==2 then return ;return to the calling CLEANUP gosub and do the next file if xyz==1 && finaltime==1 && i==count then goto ALMOSTTHERE next ;goes w/ the "for i=1 to count" loop, OR the For i=nextcount to count, OR the For i=p to p+99 ;Message("Syrinx", "murky wurky lurky") dacounter=dacounter+1 ;counter for the timesthru to be used by strcat("logfile",pass,"_",dacounter,".txt") :ALMOSTTHERE gosub CLOSEEM ;if finaltime==1 then gosub CLOSEEM if finaltime==1 then goto GETOUT if xyz==1 && lastrun==1 then goto HOMELESS ;this is kind of a kludge next ; this is the partner for the "for xyz=timesthru to 1 by -1" loop ;Message("After Big Next", xyz) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~NOW we handle the last few files in the SOURCE directory~~~~~~~~~~~~ ;THE HOMELESS CODE :HOMELESS if xyz==1 && lastrun==1 ;If we've gotten this far, we've processed all the timesthru lots. ;Now we want to set it to run the final lot through the processor. lastrun=0 ;reset lastrun back to zero so this loop doesn't get executed again finaltime=1 endif ;OK, we're ready for the final lots of files to be processed through KERCHUNK if finaltime==1 && onetime!=1 then goto KERCHUNK ;do the final processing if not a "onetime" only run ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ while @false :CLOSEEM FileClose(handle) winclose(adobewin) timedelay(1) if winexist("~Adobe Photoshop") sendkeysto("~Adobe Photoshop","{enter}") endif timedelay(30) ;give Adobe some extra time to shut down Sendkeysto("~Microsoft Excel", "!fx") ;close Excel TimeDelay(2) Sendkeysto("~Microsoft Excel", "!n") ;don't save it TimeDelay(10) ;give excel some extra time to shut down RETURN ;return to after gosub CLOSEM endwhile ;;;;gosub CLEANUP ;let's not do the cleanup for now. ;~~~~~~~~CLEANUP CLEANUP CLEANUP CLEANUP CLEANUP CLEANUP CLEANUP CLEANUP CLEANUP CLEANUP~~~~~~~~~~~ ; ; This section has been moved to the top of the file ; ;~~~~~~~~~~END CLEANUP END CLEANUP END CLEANUP END CLEANUP END CLEANUP END CLEANUP END ~~~~~~~~~~~~ :GETOUT ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Final Messages~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DirRemove("C:\WORKING") timeend=TimeYmdHms() if pass==2 secondtime=timeend else firsttime=timeend endif ;script to close photoshop and MS excel at the end of all runs.................... if WinExist(adobewin) then winclose(adobewin) timedelay(1) if winexist("~Adobe Photoshop") sendkeysto("~Adobe Photoshop","{enter}") endif timedelay(20) ;give Adobe some extra time to shut down if WinExist("~Microsoft Excel") then winclose("~Microsoft Excel") timedelay(2) if winexist("~Microsoft Excel") sendkeysto("~Microsoft Excel","!n") endif timedelay(10) ;give excel some extra time to shut down ;end of script to close photoshop and MS Excel at the run end................... if pass==2 tottime=TimeDiff(secondtime,timebeg) hours=ItemExtract(4,tottime,":") minutes=ItemExtract(5,tottime,":") seconds=ItemExtract(6,tottime,":") else tottime=TimeDiff(firsttime,timebeg) hours=ItemExtract(4,tottime,":") minutes=ItemExtract(5,tottime,":") seconds=ItemExtract(6,tottime,":") endif Message("Dot Processing Complete.", "Total job time =%@crlf% %hours% hours%@crlf% %minutes% minutes%@crlf% %seconds% seconds")