Script does not select colour?

Moderator: Kathy_9

Post Reply
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Script does not select colour?

Post by terrypin »

On an image with black text on a white background I recorded a script that:

1. Selects the Select > Rectangle tool .
2. Clicks the Backround/Fill square in the Materials palette and chooses White, replacing whatever was already set.
3. Selects a rectangle around text I want to remove.
4. Presses the Delete key.

But the script doesn't record the selected colour. So if it was say green, then the script results in a green rectangle replacing the text.

Here's an example script. (I'm still using PSP 8.)

Code: Select all

from JascApp import *

def ScriptProperties():
    return {
        'Author': u'',
        'Copyright': u'',
        'Description': u'',
        'Host': u'Paint Shop Pro',
        'Host Version': u'8.10'
        }

def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
            
            })

    # Selection
    App.Do( Environment, 'Selection', {
            'General': {
                'Mode': App.Constants.SelectionOperation.Replace, 
                'Antialias': App.Constants.Boolean.false, 
                'Feather': 0
                }, 
            'SelectionShape': App.Constants.SelectionShape.Rectangle, 
            'Start': (436,0), 
            'End': (912,27), 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

    # ClearSelection
    App.Do( Environment, 'ClearSelection', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

    # SelectNone
    App.Do( Environment, 'SelectNone', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })


--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Script does not select colour?

Post by LeviFiction »

Script recording has never included selecting colors it instead saves selected colors directly into the commands that rely specifically on them. When script authors absolutely need to use a specific color and in a place where PSP doesn't record the color we have two choices: 1) Find a way to use a command that does record the color (such as using Fill instead of Clear) or 2) adding in the SetMaterial command ourselves.

This excerpt is taken from the Scripting For Script Authors PDF provided by Corel
Command: SetMaterial

Parameters:
• IsPrimary - Boolean that determines if we are setting the foreground/stroke material, or the background/fill material. 1= True 0 = False
• NewMaterial - Material to be used

Sample Script

Code: Select all

    App.Do( Environment, 'SetMaterial', {
        'IsPrimary': 1,
            'NewMaterial': {
            'Color': (0,0,0),
            'Pattern': None,
            'Gradient': None,
            'Texture': None
            }
        })
Description

Set the specified material into the material palette. In the above example, the foreground/stroke material would get set to solid black.
So in your example code you want to add the above command before the "ClearSelection" command, you want to set IsPrimary to 0 for the background color, and you want to set Color equal to the RGB of the color you want. A solid Green might look like (0, 255,0)

There are several such commands that are never recorded in the script recorder so familiarizing yourself with the API is always handy.
https://levifiction.wordpress.com/
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Script does not select colour?

Post by terrypin »

Thanks Levi, that fixed it nicely.

While I'm here, can you tell me if there's a command I can insert at any point to stop the script, i.e. ignore the remaining commands?
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Script does not select colour?

Post by LeviFiction »

Yes it is a python command called "return"

So what you do, is where you want the script to end prematurely is simply place this single word "return" and the script will end early skipping everything after the word.
https://levifiction.wordpress.com/
JoeB
Posts: 2778
Joined: Fri Mar 28, 2008 10:04 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: LENOVO 4524PE4 ThinkCentre M91p
processor: 3.10 gigahertz Intel Quad Core i5-2400
ram: 8 GB
Hard_Drive_Capacity: 4.6 TB
Corel programs: PSP 9, X7 to 2019, 32 & 64-bit
Location: Canada

Re: Script does not select colour?

Post by JoeB »

I'd be interested in knowing why anyone would want to place the word return in a script rather than just delete the remaining portion of the script.
Regards,

JoeB
Using PSP 2019 64bit
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Script does not select colour?

Post by LeviFiction »

It can be useful for several reasons. For example while Single Step is the usual method people will use to find out exactly when a script breaks down, sometimes adding your own break point with something like return is a very way to end a script early without those annoying "Do you want to continue" dialogs popping up. You can also quickly edit a script to do something slightly different temporarily with a single additional keyword.

Another possible reason is to add or change the functionality of a script using conditionals. Add a msgbox "Do you want to add a border?" and if the answer is no, just end the script, if yes, continue. Or if there is no document, open and you need one open, just end the script no muss no fuss.
https://levifiction.wordpress.com/
Post Reply