Using script in Batch

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

Using script in Batch

Post by terrypin »

Anyone around with some scripting know-how please?

I recorded a simple script that operates on a PNG file using the PNG Optimizer to make the black background transparent and overwrites the original.

But how do I get this to work in Batch > Process so that I can convert the whole folder?

At present, with Batch > Process using the Obey Script option, it just repeatedly writes the same specific filename used for the recording.

There seems no way to invoke the Optimizer when just wanting to use plain Save. I can only access it if I first use File > Save As, or Copy As, or Export. And that codes the current name into the script.

If it's not possible to record it directly, then is there perhaps a term for 'current file' I can use in my text editor 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: Using script in Batch

Post by LeviFiction »

You're still using PSP 8 correct?

Wish I knew more about that version. Upgrade man, it's easier for me to help that way. xD I'm sorry I'm just kidding...sort of.

Doesn't your version of PSP include a "Save as new type" option? Usually when you choose a type that includes options like PNG you can access the options that the batch processor uses. No need to use a script.

----------
If you want to use a script this is not hard but it's a bit annoying.

If all the files you currently have are already PNGs, then you just need to replace the FileName parameter with the variable App.TargetDocument.Name

Code: Select all

'FileName': App.TargetDocument.Name, 
If, however, you are using files of different types like BMPs, GIFs, or JPGs then you need to change the file extension of the image name before using it. The instructions for that are below.

I'm sure there's another way to do this using python basics but I'm going to have you use a library. So the first thing to do, if you haven't already, is to move your script into the scripts-trusted folder. I'm assuming you already did this because you're able to save. Or PSP8 works differently...I don't know.

At the top of the script add

Code: Select all

Import os
Then just before the "FileSaveAS" or "PNGOPtimizer" command (whichever one you used) add the following

Code: Select all

NewFilename = os.path.splitext(App.TargetDocument.Name)[0] + '.png'
Finally replace the Filename parameter with the variable NewFilename

Code: Select all

'FileName': NewFileName,
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: Using script in Batch

Post by terrypin »

Many thanks. I'll get onto that in the morning.

They are all PNG files and, yes, I'm still using PSP8.

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: Using script in Batch

Post by terrypin »

LeviFiction wrote:
Doesn't your version of PSP include a "Save as new type" option? Usually when you choose a type that includes options like PNG you can access the options that the batch processor uses. No need to use a script.
Yes, it does indeed, and that seems to be the obvious method. But it does not appear to let me access the PNG options! :cry:

Image

--
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: Using script in Batch

Post by terrypin »

So next I tried your 'generic filename' solution which looked very promising. But I'm afraid that failed too, giving me the 'Script could not be loaded' message when I tried it on a single file.

ORIGINAL RECORDED SCRIPT (Works OK)

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', {

})

# PNG Optimizer
App.Do( Environment, 'PNGOptimizer', {
'TypeOfTransparency': App.Constants.TransparencyType.SingleTransparency,
'Tolerance': 0,
'BoostAmount': 1,
'IncludeWindowsColors': App.Constants.Boolean.false,
'TypeOfImage': App.Constants.ImageType.TrueColor,
'NumberOfColors': 256,
'DitherPercent': 100,
'PaletteType': App.Constants.ColorSelection.StandardPalette,
'FileSubFormat': App.Constants.SubFormat.Interlaced,
'BoostSelectedColors': App.Constants.Boolean.false,
'TransparentArea': App.Constants.Transparency.OutsideSelection,
'TransparentColor': (0,0,0),
'FileName': u'C:\\Program Files\\MAGIX\\Movie Edit Pro 2014 Premium\\GeoModule\\Anima'\
u'tions\\Test conversion\\New Type Output\\Copy of Boots-DkBrownRight_99.png',
'Gamma': 45455,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})

REVISED BY EDITING only the Filename (FAIL with 'Script could not be loaded')
-----------------------------------------------------------------------------

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', {

})

# PNG Optimizer
App.Do( Environment, 'PNGOptimizer', {
'TypeOfTransparency': App.Constants.TransparencyType.SingleTransparency,
'Tolerance': 0,
'BoostAmount': 1,
'IncludeWindowsColors': App.Constants.Boolean.false,
'TypeOfImage': App.Constants.ImageType.TrueColor,
'NumberOfColors': 256,
'DitherPercent': 100,
'PaletteType': App.Constants.ColorSelection.StandardPalette,
'FileSubFormat': App.Constants.SubFormat.Interlaced,
'BoostSelectedColors': App.Constants.Boolean.false,
'TransparentArea': App.Constants.Transparency.OutsideSelection,
'TransparentColor': (0,0,0),
'FileName': App.TargetDocument.Name,
'Gamma': 45455,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})

P.S: What are all those 'u's which appear in all my scripts?

--
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: Using script in Batch

Post by LeviFiction »

The "u" prefix is used in python to define a unicode string object.

If you run the script on a regular image, not a batch image, it should give a more specific error in the Script Output palette. Can you tell us what that is?
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: Using script in Batch

Post by terrypin »

LeviFiction wrote:The "u" prefix is used in python to define a unicode string object.
Thanks, understood. (I'll ignore it!)
If you run the script on a regular image, not a batch image, it should give a more specific error in the Script Output palette. Can you tell us what that is?
Running my recorded script
Executing RunScript
Executing EnableOptimizedScriptUndo
Executing PNG Optimizer

Running the edited script
Executing RunScript
File "<string>", line 1
from JascApp import *
^
SyntaxError: invalid syntax

That makes no sense to me, as most of the scripts I use contain that first line, but hopefully it will mean something to you!

Any thoughts on why your first (script-free) idea didn't cut the mustard please?

--
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: Using script in Batch

Post by terrypin »

Script failure solved!

Turned out to down to an obscure problem with my text editor, the 'Write Unicode...' setting in my text editor. I vaguely recalled some problem with this years ago, when editing an INI file mysteriously hadn't worked. So I tried pasting the recorded script into Notepad instead and it worked. Back in TextPad I removed the checkmark from the Unicode thing - and that then also worked!

Image

And the original problem has also now been identified, as in latest posts here:
http://forum.corel.com/EN/viewtopic.php?f=56&t=52898

Thanks again for your help.

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