Scripting help

Moderator: Kathy_9

Post Reply
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:

Scripting help

Post by df »

I wrote a script that uses some 8 bit tools. If the image is 16 bits the script freezes. If I try adding a Decrease to 8 Bits command and the image is already 8 bits it freezes the script.

How would I go about having the script automatically determine the bits and decreasing (or increasing) as needed? I'm not opposed to learning Python but have no experience with it as of yet.

Thanks in advance.
Regards, Dan

"Smoke me a kipper, I'll be back for breakfast."
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: Scripting help

Post by Trev Bowden »

You might Be better writing to the PSP scripting News group where I expect Suz Shook will be only too willing to help
[url]news://cnews.corel.com/corel.PaintShopPro_Scripting[/url]
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: Scripting help

Post by LeviFiction »

That is an excellent idea as they will have a whole lot better idea than the rest of us. However my NewsReader claimed it couldn't connect to the news group. Sad day. Maybe you'll have better luck, df, but if you don't here is what I know of the subject.

And some Python is necessary as you'll be doing conditional statements. First you need to get the Image Info from PSP

Code: Select all

Variable = App.Do(Environment, 'ReturnImageInfo', {'GeneralSettings' : {'Version' : ((9,0,0),1) }} )
You can use any variable name you want. This returns a dictionary that you can look through to get what it is you want.

Then you look at either the BitDepth or PixelFormat. Of course PixelFormat has multiple 8-bit image formats so BitDepth would be what I'd look at. But the scripting group will better be able to answer that question. However, since 16-bit format has a BitDepth of 48 you compare it like this.

Code: Select all

if Variable['BitDepth'] == 48:
    #Not 8 bit image, perform conversion

#the rest of your commands here.
Python relies very heavily on indentation spaces to determine what code belongs to which parts of the script. For example the code to do conversion needs to be indented properly under the "if statement" to let Python know that it belongs to that if statement. And you can't mix indent styles. You can't use Tab on one line and 4 spaces on the next. They have to be the same indentation type.

Since that wasn't very clear or helpful go talk to the people who know what they're doing. :D
https://levifiction.wordpress.com/
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: Scripting help

Post by df »

Trev
I've never used a newsgroup before and don't know how to sign up or post or anything else that I don't know how to do. I tried it but got a Windows Mail error.
"This message could not be sent.

No sender was specified. Please check your News Account configuration."
I'm pretty certain that my newsgroup program is Outlook 2003 if that's any help.


Levi:
I tried adding your text to a copy of my script, then copying the decrease color depth text as well but I still keep getting error after error. Most were indentation errors that I was able to stumble through (thanks for the heads up on that one) and after a bit of noodling around with it I think I have it working properly.
Here's the code that I have so far

Code: Select all

from PSPApp import *

def ScriptProperties():
    return {
        'Author': u'',
        'Copyright': u'',
        'Description': u'',
        'Host': u'PaintShop Photo Pro',
        'Host Version': u'13.00 Alpha 00000000.0000000000.00'
        }

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

    # Decreasecolordepth
    Variable = App.Do(Environment, 'ReturnImageInfo', {
            'GeneralSettings' : {
                'Version' : ((13,0,0),1)
                }
            })
    if Variable['BitDepth'] == 48:
    #Not 8 bit image, perform conversion 
        App.Do( Environment, 'DecreaseColorsTo16Million', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((13,0,0),1)
                }
            })
and the script goes on from there but you get the idea.

Thanks
Dan

PS is there a way to edit further in script editor rather than Notepad? I'd like to change one variable in a different part of the script and can't open the script to edit it like it used too. :(
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: Scripting help

Post by LeviFiction »

No, once it's edited with python code PSP no longer knows when where what and why things are the way they are. But the value you want to change should be properly labeled in the corresponding command and you can edit it that way. Or is it a slider of some form?

As for newsgroups I found a PDF that helps you figure out how to set it up for a very specific news group but the instructions are almost identical for Corel's newsgroups.

http://www.fhcrc.org/about/pubs/center_ ... ks2003.pdf

When it tells you to enter "news.fhcrc.org" replace that with Cnews.Corel.com.

When you're given the newsgroups you can subscribe to select the Paint Shop Pro Scripting one from that list and subscribe to it. You can then send and recieve updates from there.

It's a little different for Thunderbird but I finally got it working so with these instructions, which look really easy, you should be fine.
https://levifiction.wordpress.com/
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: Scripting help

Post by df »

No, once it's edited with python code PSP no longer knows when where what and why things are the way they are. But the value you want to change should be properly labeled in the corresponding command and you can edit it that way. Or is it a slider of some form?
Yeah, it's a slider. Knowing I can't edit it the way I'm used too is good to know. So my work around was using the original script I was working off of (I used a copy to screw with, always a good habit) adjusted what I wanted, saved, then copied and pasted the appropriate text into the proper spot. Worked like a charm.

I've yet to join the newsgroup but I probably will. Thanks
Regards, Dan

"Smoke me a kipper, I'll be back for breakfast."
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: Scripting help

Post by Trev Bowden »

You might want to try Context for script editing. It understands Python indents and uses colour codes to differentiate between variables cod and comments
http://www.contexteditor.org
oh Did i mention that its free
Post Reply