Iterating documents not working

Moderator: Kathy_9

Post Reply
mreinsmith
Posts: 25
Joined: Sat Mar 15, 2008 12:03 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
processor: Intel Core i7-4930K 3-4 Ghz
ram: 32M
Video Card: AMD Radeon R9 270
Corel programs: VideoStudio 2022
Location: Southeast, PA
Contact:

Iterating documents not working

Post by mreinsmith »

I am trying to get a simple test script to work

This is the test script and it works

Code: Select all

from PSPApp import *

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

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

    # RotateClockWise
    App.Do( Environment, 'RotateClockWise', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((25,0,0),1)
                }
            })
Now I want to iterate the open documents and do the same function

The guide says the following:
PaintShop Pro maintains a collection of all the open documents, called App.Documents. This is a Python list object, and can be iterated like any list. To do something to all open documents is as simple as:

for Doc in App.Documents:
App.Do( Environment, 'Flip', {}, Doc )

This makes use of the fact that the fourth parameter to App.Do is the target document to use for the command.
So I change it to the following:

Code: Select all

from PSPApp import *

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

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

    # RotateClockWise
    for Doc in App.Documents:
        App.Do( Environment, 'RotateClockWise', {
                'GeneralSettings': {
                    'ExecutionMode': App.Constants.ExecutionMode.Default, 
                    'AutoActionMode': App.Constants.AutoActionMode.Match, 
                    'Version': ((25,0,0),1)
                    }, Doc )
I get the error

Executing RunScript
File "<string>", line 29
}, Doc )
^
SyntaxError: invalid syntax

Any Suggestions?

Thank You
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: Iterating documents not working

Post by LeviFiction »

Yes, you're missing a closing curly brace at the point the error shows you. Just add another one and it should work. In the version below I moved the second closing curly brace in line with the start of the 'GeneralSettings' dictionary key so you can see where it fits in.

Code: Select all

    # RotateClockWise
    for Doc in App.Documents:
        App.Do( Environment, 'RotateClockWise', {
                'GeneralSettings': {
                    'ExecutionMode': App.Constants.ExecutionMode.Default, 
                    'AutoActionMode': App.Constants.AutoActionMode.Match, 
                    'Version': ((25,0,0),1)
                    }
                }, Doc )
Which code editor are you using? Notepad++, VSCode, pycharm, regular Notepad?
https://levifiction.wordpress.com/
mreinsmith
Posts: 25
Joined: Sat Mar 15, 2008 12:03 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
processor: Intel Core i7-4930K 3-4 Ghz
ram: 32M
Video Card: AMD Radeon R9 270
Corel programs: VideoStudio 2022
Location: Southeast, PA
Contact:

Re: Iterating documents not working

Post by mreinsmith »

Thank you, it works

NoteTab Pro

I'm rusty, forgot to try the match brackets function
Post Reply