Scripts: Novice queries

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

Scripts: Novice queries

Post by terrypin »

Not a programmer or techie, I'm tentatively trying to write a simple script for PSP 8. It merely changes the current materials background to a specific colour.

After failing to get anywhere by recording it, I discovered in Help that:
Materials palette operations and Tool Palette selections can be scripted but are not recorded — these actions need to be written via a text editor application.

So, after further reading, I opened the file Scripting HowTo.pdf and found this:

Command: SetMaterial
Parameters

IsPrimary - Boolean that determines if we are setting the foreground/stroke material, or the
background/fill material.
NewMaterial - Material to be used

Sample Script
App.Do( Environment, 'SetMaterial', {
'IsPrimary': App.Constants.Boolean.true,
'NewMaterial': {
'Color': (0,0,0),
'Pattern': None,
'Gradient': None,
'Texture': None
}
})


Description
Sets the specified material into the material palette. In the above example, the
foreground/stroke material would get set to solid black.


I pasted that into my text editor and changed the 'Color' and the 'IsPrimary' lines, so that the script was as follows:

App.Do( Environment, 'SetMaterial', {
'IsPrimary': App.Constants.Boolean.false,
'NewMaterial': {
'Color': (255,255,220),
'Pattern': None,
'Gradient': None,
'Texture': None
}
})


When run that gave an error 'The script could not be loaded'. So, guessing that it needed some 'front end' entries, I copy/pasted further lines which seemed common to all the other scripts. The script then looked like this:

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': App.Constants.Boolean.false,
'NewMaterial': {
'Color': (255,255,220),
'Pattern': None,
'Gradient': None,
'Texture': None
}
})


But it still gives that same error message. Can someone tell me where I'm going wrong please?

Also, once I have this working, how would I merge it with another simple script I've recorded (that does run OK!)? Do I just copy the second script below the first in my text editor (removing any duplication of the 'front end') and give it a new name so that the scripts will run successively?

Any advice on this basic stuff would be much appreciated please.

--
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: Scripts: Novice queries

Post by LeviFiction »

I would learn the basics of Python before continuing to script, it'll really help to understand what it is you're doing.

PSP scripts are written in the Python scripting language. For an interactive set of tutorials I recommend the CodeAcademy.com. It's honestly very simple and they get you going quickly.

As for your problem, it has to do with spacing. Python requires all commands that are part of a functional area to be indented the same number of spaces. In this case I believe the number of spaces is 4.

Code: Select all

def Do(Environment):
   ...
Is a function. This function is called by PSP and so every command you write has to be indented under this Do() function.

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': App.Constants.Boolean.false,
        'NewMaterial': {
            'Color': (255,255,220),
            'Pattern': None,
            'Gradient': None,
            'Texture': None
        }
        })
And I just tested it, this works to change the background material color to your off-white just as you would expect.

To add this command to another currently recorded script, just copy and paste the SetMaterial command only into the def Do(Environment): section of your recorded script, making sure the indentation matches.

If this still gives you an error then maybe someone more familiar with PSP8 will be able to help.
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: Scripts: Novice queries

Post by terrypin »

Brilliant, LeviFiction, that works perfectly here too, thank you!

I will certainly take a look at Python, but hesitate about making a major investment to learn it in any depth. I make extensive use of macros written with Macro Express Pro. But that is GUI-based so structure and syntax are largely taken care of. But occasionally I fail to get an apparently simple macro working. This happens particularly often in PSP 8. I'm guessing that its inbuilt scripting is a factor here.

--
Terry, East Grinstead, UK
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
Cassel
Posts: 1587
Joined: Fri Oct 29, 2010 6:49 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
ram: 16Gb
Corel programs: PSP 8 (JASC) to PSP 2023
Location: Canada
Contact:

Re: Scripts: Novice queries

Post by Cassel »

Suz Shook as a great step by step course on scripting. It is so detailed that you wont even have any question!
You can find it here: http://scrapbookcampus.com/paintshop-pr ... ng-course/

Suz is an expert in scripting. Her course is well worth the investment!
Cassel
https://creationcassel.com/store
Specializing in PSP specific products: scripts and tubes

https://scrapbookcampus.com
for beginner and seasoned scrappers and designers and other PSP users
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: Scripts: Novice queries

Post by terrypin »

Thanks Cassel, I'll seriously consider that recommendation. I've used some of Suz's scripts in the past- they're great.


Edit: Duly bought Scripting #1


Terry, East Grinstead, UK
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
Post Reply