Free Basic Start Script

Corel Paint Shop Pro

Moderator: Kathy_9

Locked
Teamouse
Posts: 28
Joined: Mon Feb 05, 2018 2:40 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: HP Pavilion Note Book
processor: Intel Core i3 2.20Ghz
ram: 4GB
Video Card: Not Known
sound_card: Realtek
Hard_Drive_Capacity: 908GB
Monitor/Display Make & Model: Not Known
Corel programs: PS Pro X - 2018

Free Basic Start Script

Post by Teamouse »

Have you ever ran a script, and it looks good on one image but not another that you have recorded. It because
the script is lock in to the way it was recorded. There's no options for making adjustments as it runs.
With Scripting you can create those options and adjustment automatically.

I'm sharing my Basic Starter script for anyone who learning how to edit their scripts for the first time, so they
can get the most out of their work. There just some things that a scripts needs, to make them better.
Here I have done all the basic work for you, collecting the most useful information you'll need to get started
editing your scripts. I use this script to help me get the most out of my ideas.

What does this script do for you....

1. Clear script window out put.
2. Check to see if you have an open image to work with.
3. Display a copy right window.
4. Make sure the open image is on a single layer.
5. Gets image size in Pixels
6. Gets image size in Inches
7. Calculates the center locations for each size of image
8. Has a Paint-shop Pro Version checker

All the basic numbers you'll need to get started.
At the end of the script are Paint Shop Pro Environmental Run commands that return
all information about an open image (EXIF) and the syntax command (the keys) that calls them out. To use them,
just remove the "#" comment syntax from each line and run script. Make sure you have the script
output window open to see what's available to use.

You may use this script freely with any of your script. Do not sell it, but share it as is.
Your welcome to change any of the information to meet your needs including the Copyright on line 63.
And happy scripting :)

Code: Select all

    # Date Created 2017
    # Last updated: 02/13/2018
    # Version 1.1
    # Basic Starter Script for editors.
    # Created by Timothy Gene Vesper.
    #
    # Variable list and usages in this script'
    #
    # TargetedVersion = Paint Shop Pro Version needed for script to run correctly.
    # ImageMainInfo = All of Paint Shop pro possible information of the open image. (EXIF)
    # DotsPerInch = Pixels per inch of Image
    # DocWidthSize = Width of image in Pixels
    # DocHeightSize = Height of image in Pixels
    # PaintShopVersion = Version number of Paint Shop Pro running script.
    # CenterPoint1 = centre point location of Width of image in Pixels
    # CenterPoint2 = centre point location of Height of image in Pixels
    # BaseMaxSize = the longest side of the open image in Pixels
    # BaseMinSize = The shortest side of the open image in Pixels
    # SetInchesW = The Width of the open Image in inches to the tenth of and inch for calculation.
    # SetInchesH = The Height of the open Image in inches to the tenth of and inch for calculation.
    # X = Just a Temp Variable
    #
    # At the end of the script are PaintShop Pro Environmental Run commands that return
    # all information about an open image (EXIF) and the syntax command (the keys) that calls them out. To use them,
    # just remove the "#" comment syntax from each line and run script. Make sure you have the script
    # output window open to see what's available to use.
    #
    # You may use this script freely with any of your script. Do not sell it, but share it as is.
    # Your welcome to change any of the information to meet your needs including the Copyright on line 63.

from PSPApp import *

import random

def ScriptProperties():
    return {
        'Author': u'Your Name Goes here',
        'Copyright': u'Your Name Goes Here and Date',
        'Description': u'Script Name Goes Here',
        'Host': u'Paint Shop Pro Photo',
        'Host Version': u'20.00'
        }

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

    # Clear script window and start script
    App.Do( Environment, 'ScriptWndClear')

    # Copy Right Message
    ButtonTypes = ('OK/Yes' )
    result = App.Do(Environment, 'MsgBox', {
            'Buttons': App.Constants.MsgButtons.OKCancel,
            'Icon': App.Constants.MsgIcons.Info,
            'Text': 'Basic Starter Script #01  \n  Version 1.00a for PSP 2018\n\nScript © By Timothy Gene Vesper',
            })

    if result == 0:
       return

    # Check for a open image to work with
    if App.TargetDocument is None:
     result = App.Do(Environment,  'MsgBox', {
                'Buttons': App.Constants.MsgButtons.OK, 
                'Icon': App.Constants.MsgIcons.Stop, 
                'Text': 'You need to have a open image to work with!      '
                })

    if App.TargetDocument is None:
        return

    # do we have a single layer to work with
    DocInfo = App.Do( Environment, 'ReturnImageInfo' )

    if DocInfo[ 'LayerNum' ] != 1:
            App.Do(Environment,  'MsgBox', {
                'Buttons': App.Constants.MsgButtons.OK, 
                'Icon': App.Constants.MsgIcons.Stop,
                'Text': 'This script requires that your image consist of only a single layer!     '
                })

    if DocInfo[ 'LayerNum' ] != 1:
        return

    # Get all basic image data for calculations
    TargetedVersion = 20
    ImageMainInfo = App.Do( Environment,'ReturnImageInfo')
    ProgramVersion = App.Do(Environment, 'GetVersionInfo')
    DotsPerInch = int (ImageMainInfo['PixelsPerUnit'])
    DocWidthSize = int (ImageMainInfo['Width'])
    DocHeightSize = int (ImageMainInfo['Height'])
    PaintShopVersion = int (ProgramVersion['MajorVersion'])

    # Clear script window and start script
    App.Do( Environment, 'ScriptWndClear')	

    # Get the longest side to base border width with
    CenterPoint1 = int (DocWidthSize) / 2
    CenterPoint2 = int (DocHeightSize) / 2
    BaseMaxSize = max(DocWidthSize, DocHeightSize)
    BaseMinSize = min(DocWidthSize, DocHeightSize)
    SetInchesW = round((float(DocWidthSize) / float(DotsPerInch)),2)
    SetInchesH = round((float(DocHeightSize) / float(DotsPerInch)),2)


    # show information selected to use
    print '\n Gathering information... \n'
    print 'Paint Shop Version', PaintShopVersion
    print '\nImage is: ', SetInchesW, 'inches in width'
    print 'Image is: ', SetInchesH, 'inches in height'
    print '\nWidth total is ', DocWidthSize, 'Pixels'
    print 'Height total is ', DocHeightSize, 'Pixels'
    print 'pixels per inch are set to ', DotsPerInch
    print '\nCenter point width is located at ', CenterPoint1
    print 'Center point Height is located at ', CenterPoint2
    print '\nLongest side of image is:', BaseMaxSize, 'pixels'
    print 'Shortest side of image is:', BaseMinSize, 'Pixels'
    print '\nRandomize options are imported to use' 
    print 'A list of 8 random numbers from 10-100\n'

    # Show random numbers
    x = 1
    while x < 9:
        print(random.randrange(10,101)), ', ',
        x += 1
    print ' '

    RandomNumber1 = (random.randrange(10,101))
    print '\nRandom Number Selected: ', RandomNumber1

    print '\nChecking Version '

    if PaintShopVersion < TargetedVersion:
        print '\nThis script is for PaintShop Pro 2018'
        return
    else:
        print 'Version is meet and Script continues\n'

    #ImageInfo = App.Do( Environment, 'ReturnImageInfo',) 
    #for key in ImageInfo: 
    #    print '%-30s: %s' % (key, ImageInfo[key]) 
	
    #Version = App.Do(Environment, 'GetVersionInfo') 
    #for key in Version: 
    #     print '%s - %s' % (key, Version[key]) 
User avatar
Ken Berry
Site Admin
Posts: 22481
Joined: Fri Dec 10, 2004 9:36 pm
operating_system: Windows 11
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Gigabyte B550M DS3H AC
processor: AMD Ryzen 9 5900X
ram: 32 GB DDR4
Video Card: AMD RX 6600 XT
Hard_Drive_Capacity: 1 TB SSD + 2 TB HDD
Monitor/Display Make & Model: Kogan 32" 4K 3840 x 2160
Corel programs: VS2022; PSP2023; DRAW2021; Painter 2022
Location: Levin, New Zealand

Re: Free Basic Start Script

Post by Ken Berry »

Thanks for that. I've copied your post to the Scripting sub-forum, where I hope any further discussion will take place.
Ken Berry
Locked