Unable to get IF statment to work

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
TimTom
Newbie
Posts: 18
Joined: Mon Oct 10, 2005 3:05 pm

Unable to get IF statment to work

Post by TimTom » Mon Sep 10, 2007 8:35 pm

Hi,

This is a followup on an earlier post for which I got some expert help. I have been working on my macro to process photos in which I have to capture the height and width of a photo, then resize it so the longest side (whichever that is) will be resized to 130 pixels.

Right now, my IF statement just doesn't work. Here is my entire macro. I would greatly appreciate any help I can get. Thanks, TimTom

============================================

//Process ABE Photos

//open resize window
press alt
send>i
release alt
press down*5
press right
press enter

//compare height & width
press ctrl
send>c
release ctrl
getclipboard>width
waitclipboard
press tab*2
press ctrl
send>c
release ctrl
getclipboard>height
waitclipboard

IF>%height%>%width%
send>130
wait>1
ELSE
press shift
press tab*2
release shift
send>130
wait>1
ENDIF

press enter

//Select All
press alt
send>s
release alt
press down
press enter

//Stroke/Outline
press alt
send>e
release alt
press down*11
press enter
press enter

//Deselect
press alt
send>s
release alt
press down*2
press enter

//Sharpen
press alt
send>t
release alt
press down*11
press right
press down*3
press enter
press enter

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Sep 10, 2007 8:44 pm

I expect height and width are not the values you are expecting them to be. Step through with the debugger to find out or put this line just before your If statement:

MessageModal>%height%-%width%

This will pop up a message showing you the values of these variables. If they are not what you think they should be then there is probably a problem with the preceeding code. Perhaps you need to allow more time between keystrokes.

I notice also that you have no SetFocus commands and no WaitWindowOpen lines. So your script does not ensure the correct window has the focus. The keystrokes will land on whatever window has the focus when you run the script - most likely Macro Scheduler itself.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon Sep 10, 2007 8:47 pm

If you add

MDL>%height% %width%

before the IF does it display the values you expect?

Beat me to it :lol:

(Maybe one day phpbb will warn about new posts...)

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Sep 10, 2007 8:50 pm

It seems I need to learn to type faster... :) I agree with what Marcus and Me_Again just said.
(Maybe one day phpbb will warn about new posts...)
If you use my handy dandy forum view script, you'll see that someone posted while you were typing... like I just did.

TimTom
Newbie
Posts: 18
Joined: Mon Oct 10, 2005 3:05 pm

Post by TimTom » Mon Sep 10, 2007 9:21 pm

Hi,

I tried inserting

MDL>%height% %width%

before the IF statement and Macro Scheduler froze up.

To be honest, I have never had any luck using the debug mode. But I am going to try that again.

But, what is happening with the IF statement is that the first statement is never evaluated as being true (when actually is most always is) causing the macro to skip to the ELSE statement. So the likely problem is in capturing the correct values for height and width of the photos in the first place. Just don't know where I am going wrong.

TimTom

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Sep 10, 2007 9:35 pm

I tried inserting MDL>%height% %width% before the IF statement and Macro Scheduler froze up.
Perhaps PhotoShop doesn't like the competion.

Try writing the values to a file and then view the file using notepad: For example, replace the MDL> line with:
WriteLn>c:\drawingsizevalues.txt,result,%height% %width%
then look at c:\drawingsizevalues.txt using notepad to see if there are two numbers.

Or enable logging and look at the logfile results.

One question, can you see that the size values are highlighted? If they are not highlighted, ctrl+c will not capture them. maybe try to insert the lines:
Press home
Press shift
Press end
Release shift

just ahead of the ctrl+c lines as an possible way to get the field values highlighted.

Good Luck,
Dick

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon Sep 10, 2007 9:42 pm

Sorry to toss a red herring in here (well, not really :lol: ), but if you want to do automated image manipulation then I would suggest that automating the command line mode of ImageMagick is likely to be a more robust solution than sending keystrokes to PhotoShop windows.

TimTom
Newbie
Posts: 18
Joined: Mon Oct 10, 2005 3:05 pm

Post by TimTom » Mon Sep 10, 2007 10:01 pm

Hi, Everyone--

Thank you all for your help.

I just enabled the logger in debug and stepped through the macro. It appears that I am not capturing the height and width afterall. Both show no values, making them equal and explaining why the ELSE statement is always executed.

I do believe that the height and width are properly highlighted. That happens automatically in Photoshop. Which, by the way, I can't do without.

Also, the photo window is always in focus when I use it. Perhaps what I need to do is to wait until the resize window is open. Hmmm. I think that's what mtettmar suggested. I'll try that.

TimTom

TimTom
Newbie
Posts: 18
Joined: Mon Oct 10, 2005 3:05 pm

Post by TimTom » Mon Sep 10, 2007 10:33 pm

Tried the WaitWindowOpen command and it still doesn't help. Just don't think I'm actually capturing the height and width data.

Here's the macro as it now is. If anyone can help, I'd sure appreciate it. The problem is probably in the Compare Height & Width section.

Thanks,

TimTom

=========================

//Process ABE Photos

//open Image Size window
press alt
send>i
release alt
press down*5
press right
press enter
waitwindowopen>Image Size

//compare height & width
press ctrl
send>c
release ctrl
getclipboard>width
waitclipboard
press tab*2
press ctrl
send>c
release ctrl
getclipboard>height
waitclipboard

IF>%height%>%width%
send>130
wait>1
ELSE
press shift
press tab*2
release shift
send>130
wait>1
ENDIF

press enter

//Select All
press alt
send>s
release alt
press down
press enter

//Stroke/Outline
press alt
send>e
release alt
press down*11
press enter
press enter

//Deselect
press alt
send>s
release alt
press down*2
press enter

//Sharpen
press alt
send>t
release alt
press down*11
press right
press down*3
press enter
press enter

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Sep 10, 2007 10:39 pm

You still have no SetFocus line. There is nothing to ensure the correct window is focused.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

TimTom
Newbie
Posts: 18
Joined: Mon Oct 10, 2005 3:05 pm

Post by TimTom » Mon Sep 10, 2007 11:06 pm

Hi,

I truly don't believe that setting the window focus is the issue. What happens is that I will have a number of these photos open in Photoshop and I manually select the ones I want to process. So I am manually setting the focus.

Or, are you saying that I need to set the focus on the Image Size window? Sorry if I'm a little ignorant, here.

I have confirmed that I am getting the numbers captured to the clipboard. When I do a CTRL V in Note Pad the correct number pops up.
However, I saved the values in %height% and %width% using:

WriteLn>c:\drawingsizevalues.txt,result,%height% %width%

Then I went to Note Pad and opened the file and the results were:

%height% %width%

So, it seems to me that the getclipboard command isn't doing the job, here. I'm capturing the number to the clipboard, but it isn't getting into the variable.

Thanks,

TimTom

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Sep 11, 2007 6:26 am

When you start the macro manually you are setting the focus alright - you are setting the focus to Macro Scheduler. So those first keystrokes are landing on Macro Scheduler.

USE SETFOCUS!
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

TimTom
Newbie
Posts: 18
Joined: Mon Oct 10, 2005 3:05 pm

Post by TimTom » Wed Sep 12, 2007 3:00 pm

Hi,

Just wanted to let you know that I seem to have solved the problem, but first:

I did try using set focus and that didn't help. When I said I was manually selecting focus, I was trying to explain that Photoshop was open with the pictures I was processing on the "desk top." Macro Scheduler is always in the background (no window to focus on).

Here is the "winning" code:

//open Image Size window
press alt
send>i
release alt
press down*5
press right
press enter
waitwindowopen>Image Size
wait>1

//compare height & width
setfocus>Image Size
press ctrl
send>c
release ctrl
getclipboard>%width%
waitclipboard
press tab*2
press ctrl
send>c
release ctrl
getclipboard>%height%
waitclipboard

IF>%height%>%width%
send>130
wait>1
ELSE
press shift
press tab*2
release shift
send>130
wait>1
ENDIF

press enter

What made it work was the wait>1 following the waitwindowopen>Image Size. This is something you, Marcus, told me to do for another problem I was having with a Photoshop macro about a year ago. You explained that sometimes, even when the window is open, the computer still isn't quite ready. Worked then and it works now.

When I take the wait>1 out and leave the setfocus>Image Size in, the macro does not work. Perhaps this is a problem stemming from the fact that Photoshop is a memory hog.

So anyway, thanks to for helping me with this problem. I do, however, have one small gripe: I have never been able to use the debug tools effectively. Sure, I can step through the macro but I can't see what is going on in the program I am trying to automate.

Thanks again for your help.

TimTom

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts