Running another script from the present one?

Moderator: Kathy_9

Post Reply
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Running another script from the present one?

Post by terrypin »

I raised this a couple of years ago
http://forum.corel.com/EN/viewtopic.php?f=104&t=57994
but never did sort it. I now really need to do so, as I want to string together three scripts (call them A, B and C) which I've recorded and which work. And I think that 'one chunk at a time' approach is how I'll tackle things in future. So would very much appreciate some help please.

I recently discovered the command RunScript which I'm sure must be the way to go. I tried to do that with the code below, but no joy. I started with script A in my editor and near the start added one line to name a variable for later use in script C (as LeviFiction showed me a week ago). Then I added the RunScript code, copying from a macro I downloaded way back. PSP 8 successfully runs the 'A' part but then just ends, with an error, instead of running 'B' (actually called called 'Elev-GPSU-ChangeColours').

Here is the code of the RunScript section:

Code: Select all

    # RunScript
    App.Do( Environment, 'RunScript', {
                    'FileName': Elev-GPSU-ChangeColours, 
                    'ScriptExecutionMode': App.Constants.ExecutionMode.Default, 
                    'CheckVersion': App.Constants.Boolean.false, 
                    'GeneralSettings': {
                        'ExecutionMode': App.Constants.ExecutionMode.Silent, 
                        'AutoActionMode': App.Constants.AutoActionMode.Match
                        }
                    })
And the error reported is:
Traceback (most recent call last):
File "C:\Users\terry\My PSP8 Files\Scripts-Trusted\Elev-GPSU-All.PspScript", line 452, in Do
App.Do( Environment, 'RunScript', {
NameError: global name 'Elev' is not defined


Line 452 is:
App.Do( Environment, 'RunScript', {
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
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: Running another script from the present one?

Post by LeviFiction »

If that is the script name it must be between quotation marks as a string.

If it is a variable, you need to replace dashes with underscores. Dashes are not valid in a variable name as it is the minus sign so it thinks you are performing subtraction.
https://levifiction.wordpress.com/
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Running another script from the present one?

Post by terrypin »

Thanks, appreciate your response.

That's the name of the script (excluding the extension).

I added quotes, giving this:

Code: Select all

    # RunScript
    App.Do( Environment, 'RunScript', {
            'FileName': "Elev-GPSU-ChangeColours",
            'ScriptExecutionMode': App.Constants.ExecutionMode.Default,
            'CheckVersion': App.Constants.Boolean.false,
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent,
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })
But that gives error:
Traceback (most recent call last):
File "C:\Users\terry\My PSP8 Files\Scripts-Trusted\Elev-GPSU-All.PspScript", line 452, in Do
App.Do( Environment, 'RunScript', {
RuntimeError: Unable to open the file.


Meanwhile, in parallel, I'm pursuing JoeB's suggestion from that previous thread and making good progress. But I'm sure RunScript must potentially offer a more elegant and less error-prone method?
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
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: Running another script from the present one?

Post by LeviFiction »

Change the command to RunSelectedScript. RunScript requires the full filename including the path to get there. If that doesn't work then you'll just have to enter the full path to the script. Because in python the "\" is known as the "escape" character meant to be used for special characters (i.e. "\t" = tab, "\n" = newline, "\r" = carriage return), etc.) you need to escape the escape character like this "\\" so your path will look something like this. "C:\\users\\username\\documents\\my psp files\\scripts-trusted\\scripttorun.pspscript"
https://levifiction.wordpress.com/
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Running another script from the present one?

Post by terrypin »

Using this code (with or without the extension PspScript):

Code: Select all

    # RunSelectedScript
    App.Do( Environment, 'RunSelectedScript', {
            'FileName': "Elev-GPSU-ChangeColours.PspScript",
            'ScriptExecutionMode': App.Constants.ExecutionMode.Default,
            'CheckVersion': App.Constants.Boolean.false,
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent,
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })
the script runs without stopping! After using Esc to stop it cycling, no errors are shown.



But using this rather cumbersome code :

Code: Select all

    # RunScript
    App.Do( Environment, 'RunScript', {
            'FileName': "C:\\Users\\terry\\My PSP8 Files\\Scripts-Trusted\\Elev-GPSU-ChangeColours.PspScript",
            'ScriptExecutionMode': App.Constants.ExecutionMode.Default,
            'CheckVersion': App.Constants.Boolean.false,
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent,
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })
it works - thank you!

I 'll now proceed to do the same with a further two 'sub' scripts. I had last night successfully consolidated all four using JoeB's 'careful pasting' method, as mentioned, so I have two methods available. Which one do other experienced scripters use?

--------------------

EDIT:
After further consolidation (replacing the detailed first script with a Runscript) I get this error:

"'UndoLastCmd' can not be executed from within a script after
'EnableOptimizedScriptUndo' has been executed."


Most of my recorded scripts use Undo so how can I fix this please?

Here's the code for my script so far:

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'
        }

    # RunScript
    App.Do( Environment, 'RunScript', {
            'FileName': "C:\\Users\\terry\My PSP8 Files\\Scripts-Trusted\\Elev-GPSU-RemoveGrid.PspScript",
            'ScriptExecutionMode': App.Constants.ExecutionMode.Default,
            'CheckVersion': App.Constants.Boolean.false,
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent,
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

    # RunScript
    App.Do( Environment, 'RunScript', {
            'FileName': "C:\\Users\\terry\\My PSP8 Files\\Scripts-Trusted\\Elev-GPSU-ChangeColours.PspScript",
            'ScriptExecutionMode': App.Constants.ExecutionMode.Default,
            'CheckVersion': App.Constants.Boolean.false,
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent,
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
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: Running another script from the present one?

Post by LeviFiction »

Go into the script that has "EnableOptimizedScriptUndo" and that command from the script. That command allows you to undo a script like it was a single command instead of a string of commands. But if your script needs to perform an undo it would break this functionality. So if your script needs to Undo then you can't use EnableOptimizedScriptUndo. Just remove it.
https://levifiction.wordpress.com/
JoeB
Posts: 2778
Joined: Fri Mar 28, 2008 10:04 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: LENOVO 4524PE4 ThinkCentre M91p
processor: 3.10 gigahertz Intel Quad Core i5-2400
ram: 8 GB
Hard_Drive_Capacity: 4.6 TB
Corel programs: PSP 9, X7 to 2019, 32 & 64-bit
Location: Canada

Re: Running another script from the present one?

Post by JoeB »

terrypin wrote:I 'll now proceed to do the same with a further two 'sub' scripts. I had last night successfully consolidated all four using JoeB's 'careful pasting' method, as mentioned, so I have two methods available. Which one do other experienced scripters use?
LeviFiction is the experienced scripter. I'm only an avid script user. :-) But my preference is the method I described where I take the parts of the second, third, etc. scripts that I want to run and place them all in one single script. First, I find it much simpler to do. But more important, if I happen to change, rename or even remove one of the scripts that I'm trying to run from another script then that script will fail. So I want to have one single script that performs the task for which it is created without that script having to rely on another script that I may find myself changing, renaming or deleting for some reason.
Regards,

JoeB
Using PSP 2019 64bit
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Running another script from the present one?

Post by terrypin »

Thanks Levi. I arrived at that (deleting the content of that bit) by experiment and it seem to be working. Script now starts like this:

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):

    # RunScript
    App.Do( Environment, 'RunScript', {
            'FileName': "C:\\Users\\terry\My PSP8 Files\\Scripts-Trusted\\Elev-GPSU-RemoveGrid.PspScript",
            'ScriptExecutionMode': App.Constants.ExecutionMode.Default,
            'CheckVersion': App.Constants.Boolean.false,
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent,
                'AutoActionMode': App.Constants.AutoActionMode.Match
                }
            })

    # RunScript
ETC
ETC
FWIW, most if not all of the 'sub' scripts do however contain the code, so I'm having trouble getting my head around that!

Code: Select all

def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
           
            })
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Running another script from the present one?

Post by terrypin »

Thanks Joe, understood. I'm not yet sure which method I'll adopt - maybe both!
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
JoeB
Posts: 2778
Joined: Fri Mar 28, 2008 10:04 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: LENOVO 4524PE4 ThinkCentre M91p
processor: 3.10 gigahertz Intel Quad Core i5-2400
ram: 8 GB
Hard_Drive_Capacity: 4.6 TB
Corel programs: PSP 9, X7 to 2019, 32 & 64-bit
Location: Canada

Re: Running another script from the present one?

Post by JoeB »

You're welcome, and I guess you've pointed out another reason to incorporate all necessary steps into one script instead of relying on sub scripts. That is, some of those sub scripts might have code that you don't want to use when it's run as a sub script of your main script but that you want the sub script to retain when you are using that sub script by itself for some specific purpose.
Regards,

JoeB
Using PSP 2019 64bit
Post Reply