Scripts FileSave Fails Only In Batch Process

Moderator: Kathy_9

BIBLEfreak
Posts: 10
Joined: Thu Sep 08, 2011 8:21 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: ASUS ROG STRIX Z490-H GAMING
processor: Intel i9 10900K 3_70GHz OC 5_2GHz
ram: 64GB
Video Card: NVIDIA GeForce GTX 1660 Super 6GB GDDR6
sound_card: Realtek High Definition Audio
Hard_Drive_Capacity: 1TB
Monitor/Display Make & Model: ViewSonic VX2452 24" HD

Scripts FileSave Fails Only In Batch Process

Post by BIBLEfreak »

Greetings,

I have scripts which worked in x9 - 2019 of PSP. I purchased 2021 and the scripts work individually, but when I attempt to run a stack in batch, I receive the following errors:

BATCH ERROR OUTPUT
Executing FileSave
------- Command Execution Failed -----------
Command Name: FileSave
Error Text: Command could not complete because the document type is unsupported.
Traceback (most recent call last):
File "<string>", line 53, in Do
JascApp.DocumentTypeNotSupported: command does not support target document type

Script 'Resize2000width' has completed with an error.

Traceback (most recent call last):
File "<string>", line 168, in Do
JascApp.DocumentTypeNotSupported: command does not support target document type

Script '000CurrentShoot' has completed with an error.

Now the stacked script (script incorporating various saved scripts) works fine when run on an individual file:

Code: Select all

from PSPApp import *

def ScriptProperties():
    return {
        'Author': u'',
        'Copyright': u'',
        'Description': u'',
        'Host': u'PaintShop Pro',
        'Host Version': u'24.00'
        }



def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })

    # High Pass Sharpen
    App.Do( Environment, 'HighPassSharpen', {
            'BlendMode': App.Constants.BlendMode.HardLight, 
            'Strength': 70, 
            'Radius': 4, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })

    # FillLight
    App.Do( Environment, 'ColorAdjustFillLightClarity', {
            'FillLightClarity': {
                'FillLight': 0, 
                'Clarity': 32, 
                'Sharpen': 0
                }, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })

    # ColorAdjustCurves
    App.Do( Environment, 'ColorAdjustCurves', {
            'CurveParams': {
                'RGB': [(0,0),(42,46),(135,128),(202,197),(255,255)], 
                'Red': [(0,0),(255,255)], 
                'Green': [(0,0),(255,255)], 
                'Blue': [(0,0),(255,255)], 
                'Clipping': 0
                }, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })

    # ColorVibrancy
    App.Do( Environment, 'ColorVibrancy', {
            'Vibrancy': {
                'Vibrancy': 12
                }, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })

    # Selection
    App.Do( Environment, 'Selection', {
            'General': {
                'Mode': App.Constants.SelectionOperation.Add, 
                'Antialias': False, 
                'Feather': 0
                }, 
            'SelectionShape': App.Constants.SelectionShape.Rectangle, 
            'Start': (936,-156), 
            'End': (4291,3531), 
            'SelectionStyle': App.Constants.SelectionStyle.Normal, 
            'SelectionFixedSize': (128,128), 
            'SelectionFixedRatio': (1,1), 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })

    # Selection
    App.Do( Environment, 'Selection', {
            'General': {
                'Mode': App.Constants.SelectionOperation.Add, 
                'Antialias': False, 
                'Feather': 0
                }, 
            'SelectionShape': App.Constants.SelectionShape.Rectangle, 
            'Start': (4290,3516), 
            'End': (923,-30), 
            'SelectionStyle': App.Constants.SelectionStyle.Normal, 
            'SelectionFixedSize': (128,128), 
            'SelectionFixedRatio': (1,1), 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })

    # CropToSelection
    App.Do( Environment, 'CropToSelection', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })

    # Color Adjust Levels
    App.Do( Environment, 'ColorAdjustLevels', {
            'Levels': {
                'RGB': (0,241,0.947105,0,255), 
                'Red': (0,255,1,0,255), 
                'Green': (0,255,1,0,255), 
                'Blue': (0,255,1,0,255), 
                'Clipping': 0
                }, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })

    # RunSelectedScript
    App.Do( Environment, 'RunSelectedScript', {
            'ScriptName': u'4 CornersWaterMarking', 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })

    # RunSelectedScript
    App.Do( Environment, 'RunSelectedScript', {
            'ScriptName': u'4 CornersWaterMarking', 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })

    # RunSelectedScript
    App.Do( Environment, 'RunSelectedScript', {
            'ScriptName': u'Resize2000width', 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })


The resize script incorporated in the above stacked script also works fine alone:

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):
    App.Do( Environment, 'Resize', {
            'AspectRatio': None, 
            'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels, 
            'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn, 
            'Height': None, 
            'MaintainAspectRatio': True, 
            'Resample': True, 
            'ResampleType': App.Constants.ResampleType.SmartSize, 
            'ResizeAllLayers': True, 
            'Resolution': 600, 
            'Width': 2000, 
            'SharpnessValue': 50, 
            'AdvancedMode': False, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((14,0,0),1)
                }
            })

    App.Do( Environment, 'FileSave', {
            'Encoding': {
                'BMP': {
                    'Compressed': False, 
                    'Format': App.Constants.BmpFormat.Windows
                    }, 
                'DIB': {
                    'Compressed': False, 
                    'Format': App.Constants.BmpFormat.Windows
                    }, 
                'EMF': {
                    'VectorData': True
                    }, 
                'EPS': {
                    'Monochrome': True, 
                    'Preview': True
                    }, 
                'FPX': {
                    'Compressed': True, 
                    'CompressionFactor': 15
                    }, 
                'GIF': {
                    'Interlaced': False, 
                    'Version': App.Constants.GifVersion.Gif89a
                    }, 
                'IFF': {
                    'Compressed': True
                    }, 
                'JP2': {
                    'Variant': App.Constants.Jp2Variant.Lossy, 
                    'QualityMethod': App.Constants.Jp2Quality.Rate, 
                    'CompressionFactor': 75, 
                    'CompressionSize': 100000, 
                    'CodeStream': False
                    }, 
                'JPG': {
                    'Variant': App.Constants.JpegFormat.Standard, 
                    'CompressionFactor': 25, 
                    'ChromaSubSampling': App.Constants.ChromaSubSampling.YCC_2x2_1x1_1x1
                        , 
                    'EXIF': True, 
                    'EmbedJPGICC': True
                    }, 
                'LBM': {
                    'Compressed': True
                    }, 
                'MAC': {
                    'Header': False
                    }, 
                'PBM': {
                    'Variant': App.Constants.DataEncoding.Ascii
                    }, 
                'PCX': {
                    'Version': App.Constants.PcxVersion.PCX5
                    }, 
                'PGM': {
                    'Variant': App.Constants.DataEncoding.Ascii
                    }, 
                'PNG': {
                    'Interlaced': False, 
                    'OptimizedPalette': True, 
                    'AlphaChannel': True
                    }, 
                'PPM': {
                    'Variant': App.Constants.DataEncoding.Ascii
                    }, 
                'PSP': {
                    'Compression': App.Constants.PspCompression.LZ77, 
                    'Version': App.Constants.PspVersion.PSP8, 
                    'EmbedICC': False
                    }, 
                'PSPAS': {
                    'Compression': App.Constants.PspCompression.LZ77
                    }, 
                'RAW': {
                    'HeaderSize': 0, 
                    'Invert': False, 
                    'Interleave': True, 
                    'ColorOrder': App.Constants.ColorOrder.RGB
                    }, 
                'RLE': {
                    'Format': App.Constants.RleFormat.CompuServe
                    }, 
                'SCT': {
                    'Channels': App.Constants.SctChannels.CMYK
                    }, 
                'SGI': {
                    'Compressed': True
                    }, 
                'TGA': {
                    'Compressed': True, 
                    'BitDepth': App.Constants.TgaColors.TGA24
                    }, 
                'TIF': {
                    'Compression': App.Constants.TiffCompression.LZW, 
                    'Channels': App.Constants.ColorChannels.RGB, 
                    'EmbedTIFICC': True
                    }, 
                'WMF': {
                    'VectorData': True
                    }, 
                'WPG': {
                    'Version': App.Constants.WpgVersion.WPG50
                    }, 
                'CAMERARAW': {
                    'ExposureComp': 0, 
                    'SharpenMode': 0, 
                    'WhiteBalance': 0, 
                    'Prompt': True, 
                    'UseThumb': True
                    }, 
                'HDP': {
                    'Variant': App.Constants.HDPVariant.Lossy, 
                    'CompressionFactor': 10
                    }, 
                'WEBP': {
                    'CompressionFactor': 20, 
                    'ChromaSubSampling': App.Constants.ChromaSubSampling.YCC_4x4_2x2_2x2
                        
                    }, 
                'MPO': {
                    'Variant': App.Constants.JpegFormat.Standard, 
                    'CompressionFactor': 20, 
                    'ChromaSubSampling': App.Constants.ChromaSubSampling.YCC_1x1_1x1_1x1
                        , 
                    'EXIF': True, 
                    'EmbedMPOICC': True
                    }, 
                'JPS': {
                    'Variant': App.Constants.JpegFormat.Standard, 
                    'CompressionFactor': 20, 
                    'ChromaSubSampling': App.Constants.ChromaSubSampling.YCC_1x1_1x1_1x1
                        , 
                    'EXIF': True, 
                    'EmbedJPSICC': True
                    }, 
                'PNS': {
                    'Interlaced': False, 
                    'OptimizedPalette': True, 
                    'AlphaChannel': False
                    }
                }, 
            'FileName': u'', 
            'FileFormat': App.Constants.FileFormat.Unknown, 
            'PluginFormat': 0, 
            'WorkingMode': 0, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent, 
                'AutoActionMode': App.Constants.AutoActionMode.AllAlways, 
                'Version': ((24,0,0),1)
                }, 
            'Plugin': {
                
                }, 
            'DefaultProperties': []
            })

I have disabled the 'FileSave' line in the resize script above by commenting out the offending lines, and also in many others which are identical except for the size.
This allows the process to save in a batch, but forces me to save the file manually when I am working with individual files. As I do both frequently, this is an issue as I don't want to be forced to toggle and untoggle and or save manually.

This looks like a bug in PSP 2021, these scripts work in x9-2019, as the individual script run fine alone in 2021, but error only in batch when the save feature 'filesave' is enabled.
I tried creating a new 'filesave' script and replacing the lines one of the older script but the same issue occur, works fine alone but same exact errors in batch.

Code: Select all


from PSPApp import *

def ScriptProperties():
    return {
        'Author': u'',
        'Copyright': u'',
        'Description': u'',
        'Host': u'PaintShop Pro',
        'Host Version': u'24.00'
        }

def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((24,0,0),1)
                }
            })

    # FileSave
    App.Do( Environment, 'FileSave', {
            'WorkingMode': 0, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.AllAlways, 
                'Version': ((24,0,0),1)
                }, 
            'DefaultProperties': []
            })

Any assistance would be appreciated.
LeviFiction
Advisor
Posts: 6472
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 FileSave Fails Only In Batch Process

Post by LeviFiction »

Well, first you could avoid toggling the lines on and off by just making batch specific versions of the scripts that don't use SaveAs. The downside there, of course, is clutter.

What I'm most confused by is the error you're getting. It says on line 53, but looking at the script in question that's right in the middle of the command. I'm far more used to the error pointing to the last line of the last parameter of a command. Usually the ending bracket of the 'GeneralPreferences' dictionary.

I have been unable to replicate your issue in 2021. I first tried running a script that saves the current image, then I tried calling the save script from another script. And finally I tried copying your scripts from above into PSP 2021. I still could not recreate the issue. It always succeeds. I've also never seen an error complaining about the document type come up when saving. Which is peculiar.

Some quick clarifying questions:

1) 2021 or 2022? Your scripts all list version 24 as the version of PSP they were made with. Which is 2022. 2021 is version 23.

2) When you say it works when you run it individually, are you testing it on the exact same image(s) your tried in your Batch Process?

3) Does it fail immediately or does it get through a few images first?

5) Does it make a difference if FileSave is in the main script instead of a called script?

4) What settings are you using when you run Batch Process?
BIBLEfreak
Posts: 10
Joined: Thu Sep 08, 2011 8:21 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: ASUS ROG STRIX Z490-H GAMING
processor: Intel i9 10900K 3_70GHz OC 5_2GHz
ram: 64GB
Video Card: NVIDIA GeForce GTX 1660 Super 6GB GDDR6
sound_card: Realtek High Definition Audio
Hard_Drive_Capacity: 1TB
Monitor/Display Make & Model: ViewSonic VX2452 24" HD

Re: Scripts FileSave Fails Only In Batch Process

Post by BIBLEfreak »

LeviFiction:
1) 2021 or 2022? Your scripts all list version 24 as the version of PSP they were made with. Which is 2022. 2021 is version 23.
I am so sorry, the version I just installed is 2022. Thank you for catching that...
2) When you say it works when you run it individually, are you testing it on the exact same image(s) your tried in your Batch Process?
The scripts were tested on several batches of JPG files, I also verified the files were indeed JPG since there was some question as to the unsupported format raised in the initial script error output.
I did initially test the various scripts against the same files I was working with, both the combined working script which I often overwrite, and using the incorporated individual scripts.
The same error occurred in the output file, with different lines noted of course, this was how I came to comment out the effected sections and continue working.
3) Does it fail immediately or does it get through a few images first?
The output indicates the process succeeds until the error occurs, then continues to the next file, and no changes are saved to the original files.
5) Does it make a difference if FileSave is in the main script instead of a called script?
No, the script I shared to resize to 2000, is the same for all my resize scripts, the only difference is the output size. They all receive this error when applied to a batch of 1 or many files.
4) What settings are you using when you run Batch Process?
Files selected from organizer > Select Batch Process from tool menu > Select Batch Actions > Script . check selected script > Next >Output Settings > Destination Folder > Original > Filename > Original > Naming conflicts > Overwrite, without warning > File format > Jpg...
Image

I tested in both the 64 and 32 bit engines, with the same results.
The stacked script created in 2022, was ran in 2019 and I get the "Created in newer version..." message, but the script runs as expected without errors.
LeviFiction
Advisor
Posts: 6472
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 FileSave Fails Only In Batch Process

Post by LeviFiction »

Okay, I had removed 2022 earlier after it claimed the app had been illegally modified and never got around to re-installing. After re-install 2022 I can indeed recreate the issue. I'm gonna have to do some more testing but it'll have to be reported to Corel to see what they say.

Until then I might have a workaround for you. It will require that you add code to every script that you think you'll run in Batch mode. And it requires a setup script. But it's pretty straight forward. The library "JascUtils" for older versions of PSP and "PSPUtils" for all of Corel's versions contains a variable called "ScriptData" that once set remains set until you close PSP. Using this you can set a check if a Batch Process has been started and then you can change how the script reacts based on this information. This is only one possible work around, but I find it has other uses than just telling a script not to save data. I have also used it to make batch scrips interactive the first time only, and all subsequent runs work silently using the settings I gave the first time.

First we have to make a script that runs the Batch Process command. This script will setup the variable to be True before the batch process starts. And then sets it to False after the batch process is over.

Code: Select all

from PSPApp import *
from JascUtils import *

def ScriptProperties():
    return {
        'Author': u'',
        'Copyright': u'',
        'Description': u'',
        'Host': u'PaintShop Pro',
        'Host Version': u'23.00'
        }

def Do(Environment):
    ScriptData['BatchProcess'] = True

    # BatchProcess
    App.Do( Environment, 'BatchProcessV2', {
            'WorkingMode': 0, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Interactive, 
                'AutoActionMode': App.Constants.AutoActionMode.AllAlways, 
                'Version': ((23,0,0),1)
                }, 
            })
    ScriptData['BatchProcess'] = False
Next we need a reset script that can be used if something goes wrong and we need to manually clear out the variable. If we don't have this we have to restart PSP or successfully run the Batch Process script to get it to reset. So it's a nice to have.

Code: Select all

from PSPApp import *
from JascUtils import *

def ScriptProperties():
    return {
        'Author': u'','Copyright': u'','Description': u'','Host': u'PaintShop Pro',
        'Host Version': u'24.00'
        }

def Do(Environment):
    if 'BatchProcess' in ScriptData:
        del ScriptData['BatchProcess']
And finally, in whatever script you want to not run a command you need to add the following lines
At the top of the scrupt underneath "from PSPApp import *" add

Code: Select all

from PSPUtils import *
At the top of the Do function, before everything else add

Code: Select all

    BatchProcess = False
    if 'BatchProcess' in ScriptData:
        BatchProcess = ScriptData['BatchProcess']
Those lines make sure that the variable exists, if it doesn't it creates it, if it does it uses the saved value.

Then just put a conditional before the command you want to work differently. Like preventing the Save command from running

Code: Select all

if not BatchProcess: # you can also use BatchProcess == False
    # FileSave
    App.Do( Environment, 'FileSave',{
                 WorkingMode: 0,
                 GeneralProperties: {
                            'ExecutionMode': App.Constants.ExecutionMode.Default,
                            'AutoActionMode': App.Constants.AutoActionMode.Match,
                            'Version': ((23, 0, 0,), 1)
                            }
                 })
Finally, replace the normal Batch Process command in the file Menu with the bound script for our Batch Process script. Then any time you run BatchProcess it'll set the variable to True. And you can respond to it. It's self-toggling.
BIBLEfreak
Posts: 10
Joined: Thu Sep 08, 2011 8:21 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: ASUS ROG STRIX Z490-H GAMING
processor: Intel i9 10900K 3_70GHz OC 5_2GHz
ram: 64GB
Video Card: NVIDIA GeForce GTX 1660 Super 6GB GDDR6
sound_card: Realtek High Definition Audio
Hard_Drive_Capacity: 1TB
Monitor/Display Make & Model: ViewSonic VX2452 24" HD

Re: Scripts FileSave Fails Only In Batch Process

Post by BIBLEfreak »

WOW... You are amazing.

I will give this a try and let you know.
BIBLEfreak
Posts: 10
Joined: Thu Sep 08, 2011 8:21 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: ASUS ROG STRIX Z490-H GAMING
processor: Intel i9 10900K 3_70GHz OC 5_2GHz
ram: 64GB
Video Card: NVIDIA GeForce GTX 1660 Super 6GB GDDR6
sound_card: Realtek High Definition Audio
Hard_Drive_Capacity: 1TB
Monitor/Display Make & Model: ViewSonic VX2452 24" HD

Re: Scripts FileSave Fails Only In Batch Process

Post by BIBLEfreak »

LeviFiction

So after several attempts to implement your suggestions I could not get them to work.
Various indent errors reported, even using notpad++ guides.
Then after all the indents worked, the script ran, and apparently the FileSave part worked, but the file did not resize.
At one point I decided to hit the Preview Button on the Output Settings in Batch Processing, and wouldn't you know the preview worked fine.

I need to work, so Its going to be easier for me to just recreate the two files and live with the clutter, as you first suggested.

Where would I report this to Corel, since this issues occurs with both older and new scripts which incorporate FileSave strings.

Thank you also for your time...