Back to basic script puzzles

Corel Paint Shop Pro

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

Back to basic script puzzles

Post by terrypin »

I've just returned to my spasmodic attempts to master the basics of scripting (in PSP8 in my case) and within minutes became stumped by the following puzzle.

I recorded a very simple script. (Although I admit I wasn't 100% sure that it was recording - how do you tell for sure?) Anyway, I just chose the brush tool and selected size 50 and the square shape. I then saved it as Elevation-Cream brush 50 and it duly appeared in the drop-down list of scripts. I ran it and realised I'd not specified the correct colour, so I tried to use Edit Selected Script. But that displayed only this very sparse window:

Image

Also, why is it 'uneditable'. I'd understood from LeviFiction's helpful explanation a month ago that any script involving a dialog window could be edited directly at this stage?

And it's just as uninformative when opened in my text editor:

Code: Select all

from JascApp import *

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

def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
            
            })
That doesn't contain any information about the operations. (Nor even the script's name for that matter.)

Can someone explain please? How would I proceed to edit it if I wanted, rather than starting again as I'm about to?


--
Terry, East Grinstead, UK
--
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: Back to basic script puzzles

Post by LeviFiction »

It's uneditable because the only command listed is "Optimized Undo" which is not editiable as it is a command that doesn't have a dialog box.

Editing brush settings also do not have a dialog box those are done in the tool options palette. You'll notice, however, that editing the tool options is also not listed.

------------

If you want to save brush settings you save them as a brush preset, not as a script.

Scripts only record actions, and unfortunately changing values in the options palette is not an action scripts record. If you had started to paint with the paint brush, the painting action with those settings would have been recorded and saved. However, running the script would cause the paint brush to always paint the exact same way at the exact same place every time.

So if all you're wanting to do is save the settings for a particular type of brush, what you're looking for is presets, not scripts.

------------

To save a preset, if you don't know, with the paint brush tool selected go to the tool options palette.

Edit the options that you want until the brush is exactly what you want it to be.

The very first button on the palette is the presets button. It should show the paint brush icon with a down arrow next to it. Click on this button to open the presets dialog.

In the presets dialog you'll see a "Save Presets" button that looks like a diskette. Click this and it'll ask you to give your new brush a name.

It will save the brush to your My PSP Files folder and make it available in this presets drop-down. Now all you have to do to select it is grab it from the presets.
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: Back to basic script puzzles

Post by terrypin »

Thanks a bunch, that's very helpful. I'll experiment with a preset approach along those lines.

I'll also try using Macro Express Pro with a mouse clicking approach to see if that proves easier.

But it seems a pity that scripts can't handle such a key operation as the selection of materials.


--
Terry, East Grinstead, UK
--
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: Back to basic script puzzles

Post by LeviFiction »

Scripts can select materials. There is a command for that. But Brush size and shape, no. Only Presets can do that. However, I don't think scripts record changing materials.

I think they enter the material settings directly into the various editing commands.

If you want a script to select the color you will have to enter that command manually.

Code: Select all

App.Do(Environment, 'SetMaterial',{'IsPrimary':True, 'NewMaterial':{'Art': None, 'Color': (119, 247, 124), 'Pattern': None, 'Texture': None, 'Gradient': None}})
Color is defined with Red Green and Blue.

And of course Pattern, Texture, and Gradient all have their own settings.
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: Back to basic script puzzles

Post by terrypin »

@LeviFiction,

I tried your Brush Presets suggestion but that too doesn't seem to save the materials!

I also tried presets for the Selection and Pen tools and got the same problem. Loading any preset delivers all the settings except the materials.

Do colours get saved in the presets for you? If so I need to isolate what's causing the issue here.

--
Terry, East Grinstead, UK
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
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: Back to basic script puzzles

Post by terrypin »

LeviFiction wrote:Scripts can select materials. There is a command for that. But Brush size and shape, no. Only Presets can do that. However, I don't think scripts record changing materials.

I think they enter the material settings directly into the various editing commands.

If you want a script to select the color you will have to enter that command manually.

Code: Select all

App.Do(Environment, 'SetMaterial',{'IsPrimary':True, 'NewMaterial':{'Art': None, 'Color': (119, 247, 124), 'Pattern': None, 'Texture': None, 'Gradient': None}})
Color is defined with Red Green and Blue.

And of course Pattern, Texture, and Gradient all have their own settings.
Thanks, greatly appreciate your help. But I'm having no joy incorporating that into my existing script. I'm attempting to get it into the strict syntax that I gather is crucial. Most attempts gave me 'The script could not be loaded'. However one try did let it run but the Script Output finished with this error> NameError: global name 'True' is not defined

That was with the script starting like this:

Code: Select all

from JascApp import *

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

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

    # LeviFiction addition
    App.Do(Environment, 'SetMaterial',{
            'IsPrimary':True, 'NewMaterial':{
            'Art': None, 'Color': (119, 247, 124), 'Pattern': None, 'Texture': None, 'Gradient': None
                }
            })

    # NewDrawingObject
    App.Do( Environment, 'NewDrawingObject', {
            'Antialias': App.Constants.Boolean.true, 
            'MiterLimit': 15, 
            'Join': App.Constants.JointStyle.Miter, 
            'CreateAsVector': App.Constants.Boolean.false, 
            'Fill': None, 
            'LineStyle': {
                'Name': u'', 
                'FirstCap': (u'Butt',7.21,7.21), 
                'LastCap': (u'Butt',1,1), 
                'FirstSegCap': None, 
                'LastSegCap': None, 
                'UseSegmentCaps': App.Constants.Boolean.false, 
                'Segments': None
                }, 
            'LineWidth': 6, 
            'Stroke': None, 
            'Path': None, 
            'ObjectName': u'New Shape', 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Interactive, 
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

    # NodeEditOffset
I'll now record an ultra simple script and try adding your code to that.

--------------------

Edit: Here's my simpler script after adding your code by copying the syntax of the rest. It failed with that same error about True not being defined.

Code: Select all

from JascApp import *

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

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


    App.Do(Environment, 'SetMaterial',{
            'IsPrimary':True, 
            'NewMaterial':{
            'Art': None, 
            'Color': (255, 255, 219), 
            'Pattern': None, 
            'Texture': None, 
            'Gradient': None
                }
            })

    # Selection
    App.Do( Environment, 'Selection', {
            'General': {
                'Mode': App.Constants.SelectionOperation.Replace, 
                'Antialias': App.Constants.Boolean.false, 
                'Feather': 0
                }, 
            'SelectionShape': App.Constants.SelectionShape.Rectangle, 
            'Start': (49,18), 
            'End': (1442,41), 
            '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
                }
            })

--
Terry, East Grinstead, UK
Last edited by terrypin on Wed Oct 30, 2013 10:44 pm, edited 1 time in total.
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
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: Back to basic script puzzles

Post by terrypin »

I thought it might be useful to provide more information on what I'm trying to achieve.

I want my script to remove specific areas from this sort of image:

https://dl.dropboxusercontent.com/u/401 ... gState.jpg

So that it ends up like this:

https://dl.dropboxusercontent.com/u/401 ... dState.jpg

(Note: I also made another script enlarging the canvas, which was run successfully before that second screenshot.)

I decided that the selection tool was a better choice than the brush, so the steps I recorded in my latest script were as follows:

1. Selected the text tool.

2. Clicked the background colour in the Materials window to open the Material dialogue in which I entered the RGB values for the colour required. So that the fixed background colour (255, 255, 219) will be preserved.

3. With the rectangular selection tool made a series of selections, using delete after each.

But as described earlier, when I subsequently ran the script it did not use the background colour I'd set. So my deletions resulted in rectangles of another colour.

This problem remained even if I used the 'Save materials' option when saving the script.

And on en examining the script in my text editor I found that the material selection was not included, for reasons you've explained.

--
Terry, East Grinstead, UK
--
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: Back to basic script puzzles

Post by LeviFiction »

Try replacing "True" with 1. SInce you're using PSP 8 it uses an older version of Python and of course it was also the first time Jasc had added scripting to PSP. So there will be differences between what I make and what you'll need from time to time.
https://levifiction.wordpress.com/
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: Back to basic script puzzles

Post by LeviFiction »

Actually, replace True with 0. IF you're deleting a background layer it'll replace the selected areas with the background color not the primary foreground color. So you want 'IsPrimary' set to false.

You might also try App.Constants.Boolean.False If you prefer reading it as True or False.
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: Back to basic script puzzles

Post by terrypin »

LeviFiction wrote:Actually, replace True with 0. IF you're deleting a background layer it'll replace the selected areas with the background color not the primary foreground color. So you want 'IsPrimary' set to false.

You might also try App.Constants.Boolean.False If you prefer reading it as True or False.
Got this just after my last edit.

This works!

Code: Select all

    App.Do(Environment, 'SetMaterial',{
            'IsPrimary':0, 
            'NewMaterial':{
            'Art': None, 
            'Color': (255, 255, 219), 
            'Pattern': None, 
            'Texture': None, 
            'Gradient': None
                }
            })
That was with a very simplified script but I'm quite optimistic I can get the full script working now that I've got the basic command structure established.

Thanks so much for your help. :)

--
Terry, East Grinstead, UK
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
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: Back to basic script puzzles

Post by terrypin »

I'm pleased to report that the scripts incorporating your 'materials code' are working OK, thanks.

But there's one consequence I don't properly understand. The scripts don't include any Text operations, only Selections. Yet after they've run the background text colour is changed to the colour specified in the code, instead of my usual black. Is that to be expected? Other tools such as Brush or Pen are not changed.

Is there any way I can adapt your code to confine it to Selections?

Alternatively, can I insert code that will restore whatever previous values were in place before the script was run?

I'll include below the shortest of the finished scripts:

Code: Select all

from JascApp import *

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

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

    # Material
    App.Do(Environment, 'SetMaterial',{
            'IsPrimary':0, 
            'NewMaterial':{
            'Art': None, 
            'Color': (255, 255, 219), 
            'Pattern': None, 
            'Texture': None, 
            'Gradient': None
                }
            })

    # Selection
    App.Do( Environment, 'Selection', {
            'General': {
                'Mode': App.Constants.SelectionOperation.Replace, 
                'Antialias': App.Constants.Boolean.false, 
                'Feather': 0
                }, 
            'SelectionShape': App.Constants.SelectionShape.Rectangle, 
            'Start': (85,190), 
            'End': (63,38), 
            '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
--
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: Back to basic script puzzles

Post by LeviFiction »

Well, I don't know why the text would be connected to the background color like that.

If you wanted to give it a try: You first use GetMaterial to get the current background color. You use SetMaterial to set the cream color. And finally you use SetMaterial again to reset the background material.

Code: Select all

BackgroundMaterial = App.Do( Environment, 'GetMaterial', {'IsPrimary':0} )

//... Your code here

App.Do( Environment, 'SetMaterial', BackgroundMaterial )
If that doesn't work try setting the material before you use "SelectNone."

-------------
The last thing you might try is using the Fill command instead of the ClearSelection command. In which case you need to set IsPrimary to 1 again.
https://levifiction.wordpress.com/
lennoxrandall
Posts: 1
Joined: Wed Oct 16, 2013 11:18 am
operating_system: Vista Home Basic
System_Drive: B
32bit or 64bit: 32 Bit
Location: USA
Contact:

Re: Back to basic script puzzles

Post by lennoxrandall »

I have the same problem with you buddy and I tried to have some tutorials on the web and I got the solution.
User avatar
lata
Site Admin
Posts: 14280
Joined: Thu Jan 19, 2012 6:21 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: ASUSTeK COMPUTER INC A88XM-A USB 3 1 Rev X 0x
processor: 4 10 gigahertz AMD A10-7890K Radeon R7
ram: 16 gb
Video Card: on board
sound_card: Realtek High Definition Audio
Hard_Drive_Capacity: 500 SSD
Monitor/Display Make & Model: LG W2242 [Monitor]
Corel programs: CVSX, 19, 20, 22 PSP2023, PI, MS3D
Location: UK
Contact:

Re: Back to basic script puzzles

Post by lata »

Hi lennoxrandall

and can you share your secret with us so others may benefit?
New forum for PSP and VS users, register if you need help

https://psp-vs-forums.freeforums.net
Post Reply