Using "GetNumber"

Moderator: Kathy_9

Post Reply
Promethiusn
Posts: 4
Joined: Thu Mar 05, 2020 6:16 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
Corel programs: X8, X9, 2019

Using "GetNumber"

Post by Promethiusn »

I am writing a script where I need to get user input for a resize photo function. I would prefer radio boxes, but "GetNumber" looks like it will work (a list box might also). I have ran into an issue using an example script for GetNumber, and never having written in Python before it has thrown me. It appears that the script, upon compile outputs the a test value that is assigned at the top of the script and activated with a print statement at the bottom. I am assuming that this is the reason for the undefined error message I am getting upon compile when I use print Result['EnteredNumber'] . The code I am using is below. I am using Win10 for my OS and have PaintShop Pro X9 on this machine, and 2019 on my other.

Code: Select all

from PSPApp import *
import string
import PSPUtils

#tResult = '1'   ------ just for the purpose of testing 

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

def Do(Environment):
       Result = App.Do( Environment, 'GetNumber', {
       'DefaultValue': 13,             # values for test purposes only
       'MinValue': 10,
       'MaxValue': 16,
       'DialogTitle': 'Resize Options',
       'Prompt': 'Enter a width value to resize to',
       'GeneralSettings': {
       'ExecutionMode': App.Constants.ExecutionMode.Interactive,
      }
    })

#print tResult       ---- If this line is active, it outputs to the window on compile before the Getnumber box opens
print Result['EnteredNumber']    # script crashes if not commented out
The error text is:

NameError: name 'Result' is not defined
------- Command Execution Failed -----------
Command Name: RunScript
Error Text: The script could not be loaded.
Traceback (most recent call last):
File "<string>", line 29, in <module>
NameError: name 'Result' is not defined
------- Command Execution Failed -----------
Command Name: RunScript
Error Text: The script could not be loaded.

Any help is greatly appreciated. I did see the sticky note for this forum on resources and will be checking into those also.
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 "GetNumber"

Post by LeviFiction »

Short answer: Indent the print command so it's inside the Do() function.

Long answer:
Python uses whitespace to define the beginning and ends of codeblocks. Anything with a different level of indentation (tabs instead of spaces, 2 spaces instead of 4, etc) are considered to be different code blocks.

All PSP commands run inside the Do() function identified by the "def Do(Envornment):" line. You have the "print" command executing outside of the Do() function as it is not indented under the Do function. When PSP first interprets the file it'll try running any non-function code immediately. So the first thing it tries to run is:

Code: Select all

print Result['EnteredNumber']
But because this is the first piece of code that's run, you haven't defined "Result" yet. After it loads PSP will call the Do() function and execute the script. And just to be clear 'GetNumber' cannot run outside of the Do() function because it requires the Environment variable that PSP passes in.

So just making sure that Result = App.Do(.... and print Result['EnteredNumber'] are indented the same amount will put them both under the Do() command and should fix your problem.

Just as a small aside, as you get used to Python, you will find you can use the TKInter GUI library to create more advanced UIs. Including the use of radio buttons.
https://levifiction.wordpress.com/
Promethiusn
Posts: 4
Joined: Thu Mar 05, 2020 6:16 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
Corel programs: X8, X9, 2019

Re: Using "GetNumber"

Post by Promethiusn »

Thank you for the information and quick reply - that did take care of the issue. Being new to Python, I just thought the indentions were for readability. I spent several hours trying to figure out why the script wouldn't work, but it wasn't wasted as I did learn a few things - just not what I needed to learn.
Post Reply