Jumping to a document in the GUI via Script

Moderator: Kathy_9

Post Reply
ilgk48
Posts: 63
Joined: Sun Apr 28, 2019 12:26 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
Corel programs: PaintShop PRO 2019 32bit

Jumping to a document in the GUI via Script

Post by ilgk48 »

Good morning to all,
is there a way for jumping to another document in the GUI using a Script?

In my case, first I need a Script for jumping to the first document (50 are opened) and zooming in it.
Then, with only one click on an icon-script, select the second document, zoom it and do something; an so on for all documents.
What I'm not able to do is the automatic jump in the GUI.
Maybe it's no possible?
Thank you.
Paolo.
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: Jumping to a document in the GUI via Script

Post by LeviFiction »

I don't believe it's possible. While the GUI will update in response to things we do in scripts, we don't have direct control of the GUI. Not only will the UI not update to match a newly selected image. But the zoom features will only work on the currently active image in the UI.

If that's all you wanted to know. There you are. However, if you want to understand document selection in scripting keep reading.

In PSP scripting there are two types of documents. 1) The TargetDocument and 2) The ActiveDocument.

The TargetDocument is the one that the script is acting on at this moment. So all commands you run will be run on the target document. The ActiveDocument is the one that is currently active and visible in the UI.

When you first start out the ActiveDocument and the TargetDocument are one and the same. While the script is running you can change the target document.

In Scripting the command to switch between Target documents is 'SelectDocument'

Code: Select all

App.Do(Environment, 'SelectDocument',{
    'SelectedImage': 0,
    'Strict': False
    })
This does not update the UI though. The ActiveDocument only changes when commands like FileOpen and FileClose cause PSP to change the active document.

The SelectedImage parameter is a "relative index" meaning that you move around relative to the current TargetDocument. For example, let's say we have images A, B, C, and D open in PSP. We started the script on Image C. Right now TargetDocument and ActiveDocument both point to image C. To get the TargetDocument to point to image A I have to move backward 2. So I would use 'SelectedImage':-2.

If you use SelectDocument with a selectedImage of 0 then the ActiveDocument becomes the TargetDocument.

PSP's App.Do() command also has an optional parameter. The very last parameter of the command lets you target a specific document without actually changing the target document. This optional parameter defaults to the TargetDocument but you can point it wherever you want.

The App object also has a list of all opened documents. This variable is called App.Documents. Using this we can use indexes on the list to grab a specific document.

So, for example. Let's say we have images A, B, C, and D open in PSP again. We run the script on image C but we need to copy image B. We know that in the list Image B is at index 1.

Code: Select all

    # Copy
    App.Do( Environment, 'Copy', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((9,0,0),1)
                }
            }, App.Documents[1])
You'll notice the last parameter is calling the Documents list and selecting Image B from the list by calling index 1.

Now that we have that image in the clipboard we can paste it into the current target image by excluding that last parameter and letting PSP pick the document.

Code: Select all

    # PasteAsNewLayer
    App.Do( Environment, 'PasteAsNewLayer', {
            'CreateFromDropData': False, 
            'InsertPos': -1, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((9,0,0),1)
                }
            })
And those are the basics of selecting documents to perform actions on. But, zooming is a GUI effect and only works on the currently active image. We cannot change the active image from a script.
https://levifiction.wordpress.com/
ilgk48
Posts: 63
Joined: Sun Apr 28, 2019 12:26 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
Corel programs: PaintShop PRO 2019 32bit

Re: Jumping to a document in the GUI via Script

Post by ilgk48 »

Thank you very much,
I had a useful, interesting and good time in reading and studying your reply.
So the conclusion is that it is not possible to navigate in the GUI via Script.
I have another - surely impossible :-) - question, but for it I'll open a new Topic.
My best regards.
Paolo
Post Reply