Help w/ script error?

Moderator: Kathy_9

Post Reply
boznian2
Posts: 11
Joined: Wed Aug 25, 2010 11:10 pm
operating_system: Windows XP Pro
System_Drive: C
32bit or 64bit: 32 Bit
motherboard: Intel
processor: Intel
ram: 4GB
Video Card: ATI Rage
sound_card: Boomer
Hard_Drive_Capacity: 2TB

Help w/ script error?

Post by boznian2 »

Hi

Sure am hoping someone here can help with this - I have been trying to get this resolved for months. This script gives me an error each iteration that it is "from a newer version or the version could not be determined". But of course it works fine and does exactly what I need. It is a real pain to have to hit "OK" every image, THOUSANDS of times. As listed in the script, I am using PSP X, 10.03. Please help me get rid of this stupied error!

Here is a small part of the script, but it is the part that causes the error:

from PSPApp import *

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

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

###### Resize Start ###

# Resize an image, keeping the aspect ratio equal to orig.

# Note: this uses Height and Width settings below
#############
HeightSize = 768
WidthSize = 1024
#############

def ScriptProperties():
return {
'Description': 'Resize to the defined height, preserving the aspect ratio.',
}

def Do(Environment):
# compute the width and the height of image, preserving the aspect ratio
ImageInfo = App.Do( Environment, 'ReturnImageInfo' )
Width = ImageInfo['Width']
Height = ImageInfo['Height']
Title = ImageInfo['Title']
print Title, ImageInfo['Title']

NewHeight = HeightSize
NewWidth = Width * float(NewHeight) / float(Height)

if NewWidth > WidthSize:
NewWidth = WidthSize
NewHeight = Height * float(NewWidth) / float(Width)

print 'Document ', Title, ' resized to %d x %d' % ( NewWidth, NewHeight )

App.Do( Environment, 'Resize', {
'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels,
'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'MaintainAspectRatio': App.Constants.Boolean.true,
'OriginalDimensionUnits': App.Constants.UnitsOfMeasure.Pixels,
'OriginalResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'Resample': App.Constants.Boolean.true,
'ResampleType': App.Constants.ResampleType.SmartSize,
'ResizeAllLayers': App.Constants.Boolean.true,
'Resolution': 300.000,
'Width': NewWidth,
'Height': NewHeight,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
})

####### Resize End ###
Trev Bowden
Posts: 174
Joined: Mon Mar 01, 2010 5:30 pm
operating_system: Windows 7 Home Premium
System_Drive: C
32bit or 64bit: 32 Bit
motherboard: ASUSTeK. M3A78-EM
processor: 2.80 gigahertz AMD Athlon 7850 Dual-Core
ram: 4gb
Video Card: ATI Radeon HD 5450
sound_card: ATI HDMI Audio.Realtek High Definition
Hard_Drive_Capacity: 2TB
Location: Bradford West Yorks UK

Re: Help w/ script error?

Post by Trev Bowden »

Im no expert but
Hi

Sure am hoping someone here can help with this - I have been trying to get this resolved for months. This script gives me an error each iteration that it is "from a newer version or the version could not be determined". But of course it works fine and does exactly what I need. It is a real pain to have to hit "OK" every image, THOUSANDS of times. As listed in the script, I am using PSP X, 10.03. Please help me get rid of this stupied error!

Here is a small part of the script, but it is the part that causes the error:

from PSPApp import *

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

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

###### Resize Start ###

# Resize an image, keeping the aspect ratio equal to orig.

# Note: this uses Height and Width settings below
#############
HeightSize = 768
WidthSize = 1024
#############

def ScriptProperties():
return {
'Description': 'Resize to the defined height, preserving the aspect ratio.',
}

def Do(Environment):
# compute the width and the height of image, preserving the aspect ratio
ImageInfo = App.Do( Environment, 'ReturnImageInfo' )
Width = ImageInfo['Width']
Height = ImageInfo['Height']
Title = ImageInfo['Title']
print Title, ImageInfo['Title']

NewHeight = HeightSize
NewWidth = Width * float(NewHeight) / float(Height)

if NewWidth > WidthSize:
NewWidth = WidthSize
NewHeight = Height * float(NewWidth) / float(Width)

print 'Document ', Title, ' resized to %d x %d' % ( NewWidth, NewHeight )

App.Do( Environment, 'Resize', {
'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels,
'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'MaintainAspectRatio': App.Constants.Boolean.true,
'OriginalDimensionUnits': App.Constants.UnitsOfMeasure.Pixels,
'OriginalResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'Resample': App.Constants.Boolean.true,
'ResampleType': App.Constants.ResampleType.SmartSize,
'ResizeAllLayers': App.Constants.Boolean.true,
'Resolution': 300.000,
'Width': NewWidth,
'Height': NewHeight,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match
}
At this point no verstion is shown try adding 'Version': ((10,0,3),1)
}
})
boznian2
Posts: 11
Joined: Wed Aug 25, 2010 11:10 pm
operating_system: Windows XP Pro
System_Drive: C
32bit or 64bit: 32 Bit
motherboard: Intel
processor: Intel
ram: 4GB
Video Card: ATI Rage
sound_card: Boomer
Hard_Drive_Capacity: 2TB

Re: Help w/ script error?

Post by boznian2 »

Thanks for the reply - aren't lines 9 and 18 already doing that? I don't see how your entry does anything different. (It didn't make any difference in the script.)
boznian2
Posts: 11
Joined: Wed Aug 25, 2010 11:10 pm
operating_system: Windows XP Pro
System_Drive: C
32bit or 64bit: 32 Bit
motherboard: Intel
processor: Intel
ram: 4GB
Video Card: ATI Rage
sound_card: Boomer
Hard_Drive_Capacity: 2TB

Re: Help w/ script error?

Post by boznian2 »

Is there no hope for me on this? Does anyone know of a different script that would accomplish the same (image re-size) thing for me without giving this stupid error?
df
Posts: 1224
Joined: Mon Feb 08, 2010 11:21 pm
operating_system: Windows 11
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: GIGABYTE Z690 AERO G DDR4
processor: 13th Gen Intel Core i7-13700K
ram: 64gb
Video Card: RTX 3060 Ti 8gb GDRR6
Hard_Drive_Capacity: 1 Tb
Location: Washington State
Contact:

Re: Help w/ script error?

Post by df »

I'm by far an expert, in fact I don't even like messing with these things yet (but I will once I understand them more :D ). But it seems to me like you have something conflicting here. You specify that you'll maintain the original aspect ratio but then you provide both height and width. It would seem to me that you can't have it both ways. Here's a sample of the resize part of a script I have.

Code: Select all

    # Resize
    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': 300, 
            'Width': 800, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((13,0,0),1)
                }
            })
You'll notice that you have resolution and width, but not height. I'm also confused that you specify that the image will be 1024 x 768, but then you ask for the height and make that the new height. But now I'm trying to read this thing like I know what I'm looking at. If you know that you want the file to be 1024 wide, why not just specify that in the script?

Dan
Regards, Dan

"Smoke me a kipper, I'll be back for breakfast."
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: Help w/ script error?

Post by LeviFiction »

EDIT: Edited the whole message correcting myself.

Boznian2, since Python uses indentation instead of symbols to determine code blocks could I ask that you use a code tag when posting code from now on? It should preserve the code format quite nicely allowing us to simply copy and paste to test it out. As it stands we have to re-indent the code carefully.

My question to you would be, why do you have two of these?

Code: Select all

def Do(Environment):
You only need one per script. This function is where all of your commands and programs are supposed to be located. This could be the problem.

Okay, so, when I removed the second "def Do(Environment):" portion of your script it seems to function properly with no errors on my side. But I don't trust that. So test it for yourself.

Code: Select all

from PSPApp import *

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

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

    ###### Resize Start ###

    # Resize an image, keeping the aspect ratio equal to orig.

    # Note: this uses Height and Width settings below
    #############
    HeightSize = 768
    WidthSize = 1024
    #############

    def ScriptProperties():
        return {
            'Description': 'Resize to the defined height, preserving the aspect ratio.',
            }

    # compute the width and the height of image, preserving the aspect ratio
    ImageInfo = App.Do( Environment, 'ReturnImageInfo' )
    Width = ImageInfo['Width']
    Height = ImageInfo['Height']
    Title = ImageInfo['Title']
    print Title, ImageInfo['Title']

    NewHeight = HeightSize
    NewWidth = Width * float(NewHeight) / float(Height)

    if NewWidth > WidthSize:
        NewWidth = WidthSize
    NewHeight = Height * float(NewWidth) / float(Width)

    print 'Document ', Title, ' resized to %d x %d' % ( NewWidth, NewHeight )

    App.Do( Environment, 'Resize', {
            'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels,
            'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
            'MaintainAspectRatio': App.Constants.Boolean.true,
            'OriginalDimensionUnits': App.Constants.UnitsOfMeasure.Pixels,
            'OriginalResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
            'Resample': App.Constants.Boolean.true,
            'ResampleType': App.Constants.ResampleType.SmartSize,
            'ResizeAllLayers': App.Constants.Boolean.true,
            'Resolution': 300.000,
            'Width': NewWidth,
            'Height': NewHeight,
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent,
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
             })

DF, since they want to use the original aspect ratio they can't simply specify 1024x768 they want it to get as close to that value as the image can.

HeightSize and HeightWidth as well as the original Height and Width are used in a funky equation for NewWidth and NewHeight which explains the confusion you're seeing, df.

This equation make sure that the maximum resize is 1024x768. It also maintains the original aspect ratio while getting as close to 1024x768 as possible.

Say I had an image 889x717 pixels. The first equation would result in a width of 952. The second equation would result in a value of 768 when rounded up.

The original aspect ratio matches these values perfectly.

The resize command inside of a script will automatically resize your image to any given width and height regardless of the aspect ratio.

Settings such as "Aspect Ratio" and "Maintain Aspect Ratio" only apply to when the dialog box actually pops up. Otherwise they don't come into effect. So handling the math in the script saves time and effort.

This is really nice as I can use this code to handle the resizing of custom brush images that I'm importing from Photoshop. Paint Shop Pro has a maximum size of 999x999 for custom brush heads. So using this code will severely shrink the amount of code in my current script.
https://levifiction.wordpress.com/
boznian2
Posts: 11
Joined: Wed Aug 25, 2010 11:10 pm
operating_system: Windows XP Pro
System_Drive: C
32bit or 64bit: 32 Bit
motherboard: Intel
processor: Intel
ram: 4GB
Video Card: ATI Rage
sound_card: Boomer
Hard_Drive_Capacity: 2TB

Re: Help w/ script error?

Post by boznian2 »

LeviFiction - thanks for your response. I was able to test this today but unfortunately it does not work for me. If I remove the 2nd "def Do(Environment):" it first gives me the same error message, then the script just ends, with

"Executing RunScript
Executing EnableOptimizedScriptUndo"
...in the output box.

If I remove the first one and leave the 2nd, I still get the same error message but the sript completes normally, just like it always has.

And I apologize, but I don't know what code tags are or how to use them. :oops:
df
Posts: 1224
Joined: Mon Feb 08, 2010 11:21 pm
operating_system: Windows 11
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: GIGABYTE Z690 AERO G DDR4
processor: 13th Gen Intel Core i7-13700K
ram: 64gb
Video Card: RTX 3060 Ti 8gb GDRR6
Hard_Drive_Capacity: 1 Tb
Location: Washington State
Contact:

Re: Help w/ script error?

Post by df »

When composing a message here on the message board if you click Full Editor you'll get buttons above the text box. The one that says Code will give you what Levi is talking about. Copy and paste your code into the box as you have been doing, highlight the code, click the code button and you'll see the html added to your code to make it look right.

[code] something like this[/code]

Type outside the code boxes there and you have regular text.
Regards, Dan

"Smoke me a kipper, I'll be back for breakfast."
df
Posts: 1224
Joined: Mon Feb 08, 2010 11:21 pm
operating_system: Windows 11
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: GIGABYTE Z690 AERO G DDR4
processor: 13th Gen Intel Core i7-13700K
ram: 64gb
Video Card: RTX 3060 Ti 8gb GDRR6
Hard_Drive_Capacity: 1 Tb
Location: Washington State
Contact:

Re: Help w/ script error?

Post by df »

And this is what something like this should look like

Code: Select all

     something like this
You'll notice that the spacing is retained
Regards, Dan

"Smoke me a kipper, I'll be back for breakfast."
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: Help w/ script error?

Post by LeviFiction »

Boznian2, did you make sure the spacing was correct? Did you try the code I posted? The code I posted works perfectly for me. And it removed the def Do(Environment). Again you only need one so removing it shouldn't be causing you problems.

Paint Shop Pro interacts with your script by calling special functions that should exist inside the script. Do(Environment) is one of these. If you have two of them it causes problems so even if that's not the specific problem it will cause problems in the future.
https://levifiction.wordpress.com/
boznian2
Posts: 11
Joined: Wed Aug 25, 2010 11:10 pm
operating_system: Windows XP Pro
System_Drive: C
32bit or 64bit: 32 Bit
motherboard: Intel
processor: Intel
ram: 4GB
Video Card: ATI Rage
sound_card: Boomer
Hard_Drive_Capacity: 2TB

Re: Help w/ script error?

Post by boznian2 »

OK, first let me apologize for the long delay in responding - bit of a family emergency has occupied all of my time for while. :(

Second, this DOES work. I was actually posting just a small part of my overall script to save space and not bore you with a lot of superfluous image work contained in my overall script. There was also an issue in another part of my script which I had to be corrected.

So, a big THANKS to LeviFiction for solving my incredibly frustrating issue! :D This is a HUGE timesaver to not have to interact with this script anymore!

THANK YOU
Post Reply