This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > PainShop Pro Scripting > June 2007 > Detecting presence of selection
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Detecting presence of selection
|
|
|
| If a script requires a selection when it starts, and no selection exists, I
get a popup that says "Command could not complete because there is no
selection", which I noticed with the Color Changer script.
That's well and good, but is there a more elegant way to do this? In other
words, it would be nice, with that script as an example, to have the popup
say something like: "You must create a selection around the item you wish
to re-color before running the script. Click OK, make your selection, and
then run the script again."
It seems to me that, in the past, I have seen scripts that do this by
detecting whether a selection exists. But when I checked the Scripting for
Authors the only script for detecting a selection was to remove a selection
that was detected, which obviously didn't help. Google didn't help either.
And, of course, if there is a script or snippet that will detect whether a
selection exists and allow me to customize the message box, once the user
clicks OK the script has to terminate/complete so that, after the user
makes the selection, running the script again will be a fresh start on the
image.
All help, as usual, much appreciated.
Regards,
JoeB
| |
| BWPanda 2007-06-22, 6:19 am |
| underprocessable | |
| Fred Hiltz 2007-06-22, 6:19 am |
| JoeB wrote:
[snip]
> if there is a script or snippet that will detect whether a
> selection exists ...
Page 24 of your PSP 9 Scripting for Script Authors describes
"Checking for a selection."
--
Fred Hiltz, fhiltz at yahoo dot com
| |
| SuzShook 2007-06-22, 6:27 pm |
| JoeB wrote:
> If a script requires a selection when it starts, and no selection
> exists, I get a popup that says "Command could not complete because
> there is no selection", which I noticed with the Color Changer script.
>
> That's well and good, but is there a more elegant way to do this? In
> other words, it would be nice, with that script as an example, to
> have the popup say something like: "You must create a selection
> around the item you wish to re-color before running the script.
> Click OK, make your selection, and then run the script again."
>
> It seems to me that, in the past, I have seen scripts that do this by
> detecting whether a selection exists. But when I checked the
> Scripting for Authors the only script for detecting a selection was
> to remove a selection that was detected, which obviously didn't help.
> Google didn't help either.
>
> And, of course, if there is a script or snippet that will detect
> whether a selection exists and allow me to customize the message box,
> once the user clicks OK the script has to terminate/complete so that,
> after the user makes the selection, running the script again will be
> a fresh start on the image.
>
> All help, as usual, much appreciated.
>
> Regards,
>
> JoeB
You can use the ReturnImageInfo command to determine if there is a
selection, JoeB - if 0 (or False in non-PSP 8 versions) is returned in the
Selection parameter, there is no selection, and if 1 (or True) is returned,
there is a selection. Here's some sample code:
ImageInfo = App.Do(Environment, 'ReturnImageInfo',)
print ImageInfo['Selection']
if ImageInfo['Selection'] == 0:
App.Do(Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': 'There is no selection - make a selection and restart
script.',
})
print "\n There is no selection - make a selection and restart
script."
return
else:
print "\n There is a selection - we can continue!\n"
Suz
| |
| BWPanda 2007-06-22, 6:27 pm |
| Forgot to mention, best to set the steps to silent, that way the real PSP
error window doesn't popup, just your custom one.
--
Kind regards,
Peter Anderson.
(Fujifilm FinePix S9500)
See where on earth my photos were taken:
http://people.aapt.net.au/~joian/bwpanda_photos.kmz
| |
|
| "BWPanda" <panda@aapt.net.au> wrote in news:467a67a2_2@cnews:
> Forgot to mention, best to set the steps to silent, that way the real
> PSP error window doesn't popup, just your custom one.
>
Thanks for the reply and snippet. I downloaded your script to study and
compare. I mostly record with minor editing so am not that knowledgable,
but if I understand correctly what your script does is attempt to feather
an existing selection and, if there is no selection to feather, you get the
prompt. If that is correct, then what happens if a selection is found -
does that selection get feathered?
In the interim, I found that Suz's Image Info snipped does the job so have
used that in the script, but do appreciate your input.
Regards,
JoeB
| |
|
| "Fred Hiltz" <not@home.ca> wrote in news:467a4b4d_3@cnews:
> JoeB wrote:
> [snip]
>
> Page 24 of your PSP 9 Scripting for Script Authors describes
> "Checking for a selection."
Thanks Fred, but I had already checked that out. I'm afraid it does the
opposite of what I want - i.e., the pdf script detects a selection and then
prompts to delete it, whereas I want to detect to a selection and have the
script run if there is a selection and prompt to create one if none exists.
But I appreciate your reply.
Regards,
JoeB
| |
|
| "SuzShook" <suzshook@roadrunner.com> wrote in news:467a5ccc$1_2@cnews:
> JoeB wrote:
>
> You can use the ReturnImageInfo command to determine if there is a
> selection, JoeB - if 0 (or False in non-PSP 8 versions) is returned in
> the Selection parameter, there is no selection, and if 1 (or True) is
> returned, there is a selection. Here's some sample code:
>
> ImageInfo = App.Do(Environment, 'ReturnImageInfo',)
> print ImageInfo['Selection']
> if ImageInfo['Selection'] == 0:
> App.Do(Environment, 'MsgBox', {
> 'Buttons': App.Constants.MsgButtons.OK,
> 'Icon': App.Constants.MsgIcons.Stop,
> 'Text': 'There is no selection - make a selection and
> restart
> script.',
> })
> print "\n There is no selection - make a selection and
> restart
> script."
> return
>
> else:
> print "\n There is a selection - we can continue!\n"
>
> Suz
>
Thanks Suz. That code did the trick. I had searched through a bunch of
scripts I have looking for code to prompt for a selection, couldn't find
one, so gave up in frustration and figured I'd ask. Thanks again.
Regards,
JoeB
| |
|
| JoeB <mymail@myserver.com> wrote in news:Xns99578F72CD860JoeB@
207.107.16.194:
> "SuzShook" <suzshook@roadrunner.com> wrote in news:467a5ccc$1_2@cnews:
in[color=darkred]
>
> Thanks Suz. That code did the trick. I had searched through a bunch
of
> scripts I have looking for code to prompt for a selection, couldn't
find
> one, so gave up in frustration and figured I'd ask. Thanks again.
>
> Regards,
>
> JoeB
>
As a P.S., the only way I could ensure that, in PSP9, the first and last
messages in my SOP would display (i.e., if the SOP was full already the
first message would only display the first line at the bottom of the SOP
and the rest of the message wasn't visible until after the user used the
tool) was to insert a command to get the Pan tool. That is, it seemed
as if some other action was required to force the SOP to scroll up
properly sometimes, and by inserting the Pan tool in appropriate spots
the proper scrolling would occur. I chose the Pan tool because it
doesn't hurt anything :-) However, didn't you once mention a more
elegant workaround for the PSP9 SOP problem?
Regards,
JoeB
| |
| Spandex Rutabaga 2007-06-22, 6:27 pm |
| JoeB wrote:
>
> JoeB <mymail@myserver.com> wrote in news:Xns99578F72CD860JoeB@
> 207.107.16.194:
>
> in
> of
> find
>
> As a P.S., the only way I could ensure that, in PSP9, the first and last
> messages in my SOP would display (i.e., if the SOP was full already the
> first message would only display the first line at the bottom of the SOP
> and the rest of the message wasn't visible until after the user used the
> tool) was to insert a command to get the Pan tool. That is, it seemed
> as if some other action was required to force the SOP to scroll up
> properly sometimes, and by inserting the Pan tool in appropriate spots
> the proper scrolling would occur. I chose the Pan tool because it
> doesn't hurt anything :-) However, didn't you once mention a more
> elegant workaround for the PSP9 SOP problem?
Try doing this at the start of the script to clear the palette.
App.Do( Environment, 'ScriptWndClear' )
| |
| SuzShook 2007-06-22, 10:21 pm |
| JoeB wrote:
> JoeB <mymail@myserver.com> wrote in news:Xns99578F72CD860JoeB@
> 207.107.16.194:
>
>
> As a P.S., the only way I could ensure that, in PSP9, the first and
> last messages in my SOP would display (i.e., if the SOP was full
> already the first message would only display the first line at the
> bottom of the SOP and the rest of the message wasn't visible until
> after the user used the tool) was to insert a command to get the Pan
> tool. That is, it seemed as if some other action was required to
> force the SOP to scroll up properly sometimes, and by inserting the
> Pan tool in appropriate spots the proper scrolling would occur. I
> chose the Pan tool because it doesn't hurt anything :-) However,
> didn't you once mention a more elegant workaround for the PSP9 SOP
> problem?
>
> Regards,
>
> JoeB
You are correct, JoeB - in PSP 9, there is a scrolling problem which you ran
into. I can't remember why, but in several of my scripts, I ran a
GetVersionInfo command to cause the SOP to scroll - not more elegant, for
sure, but similar to what you did. I can't remember why I didn't just
activate the Pan tool - I think there was a reason, but it escapes me right
now.
I never recommend clearing the SOP, as Spandex suggests, because there are
times when that previous information might be needed. And it does not solve
the problem of the SOP filling up during the current execution of the
script, and some information not showing at the bottom of the SOP until
after some other command is executed, too late for that information to be
useful.
You did good, JoeB! Suz
| |
|
| "SuzShook" <suzshook@roadrunner.com> wrote in news:467afe2d$1_1@cnews:
> JoeB wrote:
>
> You are correct, JoeB - in PSP 9, there is a scrolling problem which
> you ran into. I can't remember why, but in several of my scripts, I
> ran a GetVersionInfo command to cause the SOP to scroll - not more
> elegant, for sure, but similar to what you did. I can't remember why
> I didn't just activate the Pan tool - I think there was a reason, but
> it escapes me right now.
>
> I never recommend clearing the SOP, as Spandex suggests, because there
> are times when that previous information might be needed. And it does
> not solve the problem of the SOP filling up during the current
> execution of the script, and some information not showing at the
> bottom of the SOP until after some other command is executed, too late
> for that information to be useful.
>
> You did good, JoeB! Suz
>
Thanks Suz, these challenges are sent to try us! And you are correct
about it not solving the problem in v.9 when the SOP fills up and you
don't have something further down the script to force a scroll. In the
Color Changer script the instructions/tips for saving to the Alpha
Channel (which is the dialogue to appear in the script) wouldn't show up
until after you had saved the selection, even though there was a final
comment to select the bottom layer in the stack. So even clearing the
SOP window at the beginning didn't help at the end, and so I had to
activate the pan tool down there also to make that work properly.
I've used the command to activate the pan tool before to "reset" a
script partway through so that I can get it to do something else, which
is why I used it this time. I can't think of a situation offhand where
it would hurt anything, but if I run across one I'll use your method and
use GetVersionInfo. Thanks for the tip.
Regards,
JoeB
| |
|
| Spandex Rutabaga <SpRu@agabatur.xednaps> wrote in
news:467C336B.A292663A@agabatur.xednaps:
> JoeB wrote:
>
> Try doing this at the start of the script to clear the palette.
>
> App.Do( Environment, 'ScriptWndClear' )
Thanks for the tip on how to clear the window, SR. However, with PSP9 for
sure (and perhaps later versions, I don't know) when the SOP fills up you
can still run into situations where a further script step (in my case the
final one) also won't display until it's too late to instruct the user,
unless something else occurs to force the scroll. And of course I wouldn't
want to clear the window at that stage when it has all the steps relevant
to that script that someone might want to review or use for debugging if
they have a problem.
But it's nice to know the command that will clear the window if there is a
situation where one might wish to do so.
Regards,
JoeB
| |
| Fred Hiltz 2007-06-23, 3:18 am |
| JoeB wrote:
> "Fred Hiltz" <not@home.ca> wrote in news:467a4b4d_3@cnews:
>
>
> Thanks Fred, but I had already checked that out. I'm afraid
> it does the opposite of what I want - i.e., the pdf script
> detects a selection and then prompts to delete it, whereas I
> want to detect to a selection and have the script run if there
> is a selection and prompt to create one if none exists. But I
> appreciate your reply.
Understood. I hoped that you would progress beyond rote copying of
others' work without understanding it to applying the information in
the documentation to your own needs, that is, beginning to learn to
program. It is fun and rather rewarding.
--
Fred Hiltz, fhiltz at yahoo dot com
| |
|
| "Fred Hiltz" <not@home.ca> wrote in news:467b3494_2@cnews:
> JoeB wrote:
>
> Understood. I hoped that you would progress beyond rote copying of
> others' work without understanding it to applying the information in
> the documentation to your own needs, that is, beginning to learn to
> program. It is fun and rather rewarding.
Yes, I definitely understand where you're coming from, Fred, and don't
mind the nudge.
It's just that the amount of scripting I do is quite minor in my scheme
of things and, with time being as limited as it is as the years progress
I have to confine the learning (e.g., something like learning Python) to
stuff that I really have to learn for things like keeping the income
coming in. Script stuff is only for convenience for the most part, and
just for a break when I take a break from actual work (which is pretty
full time and mostly done on the computer/internet).
And actually, I do learn from things like looking at p.24 (as I did) and
comparing to stuff others help me with (like Suz's snippet and Panda's
effort also), as well as experimenting prior to asking for snippets
(which is how I figured out a way to deal with the PSP9 SOP scrolling
issue). So it's not that I'm a total loss in the learning area :-)
Regards,
JoeB
| |
| BWPanda 2007-06-23, 3:18 am |
| "JoeB" <mymail@myserver.com> wrote in message
news:Xns99578EBDD6714JoeB@207.107.16.194...
>
> Thanks for the reply and snippet. I downloaded your script to study and
> compare. I mostly record with minor editing so am not that knowledgable,
> but if I understand correctly what your script does is attempt to feather
> an existing selection and, if there is no selection to feather, you get
> the
> prompt. If that is correct, then what happens if a selection is found -
> does that selection get feathered?
Correct.
No selection = prompt and exit.
Selection = feather.
> In the interim, I found that Suz's Image Info snipped does the job so have
> used that in the script, but do appreciate your input.
No problem. Glad I could be of some assistance :)
--
Kind regards,
Peter Anderson.
(Fujifilm FinePix S9500)
See where on earth my photos were taken:
http://people.aapt.net.au/~joian/bwpanda_photos.kmz
|
|
|
| | Copyright 2003 - 2009 forum4designers.com Software forum Computer Hardware reviews |
|