How to set a Preset ?

Moderator: Kathy_9

Post Reply
ilgk48
Posts: 60
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

How to set a Preset ?

Post by ilgk48 »

Good evening to all,
I'm struggling and loosing my time with Preset.
I have this preset for the pen tool:

Code: Select all

from PSPApp import *

def ScriptProperties():
    return { .......
       

def Preset_PenTool():
    return {
        'Contiguous Mode': False,
        'LineWidth': 10,
        'Antialias': False
        }

def Do(Environment):
    App.Do( Environment, 'PenTool', Preset_PenTool() )
I call it via RunScript from another Script but nothing happens. So I have copied the above instructions directly in the calling Script but the result is the same: nothing at all haapens.
Please can anyone tell ne where I'm wrong?
Thank you.
LeviFiction
Advisor
Posts: 5985
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, 9, X, XI, X2, X8,X9, 2018, 2019
Location: USA

Re: How to set a Preset ?

Post by LeviFiction »

I need to be careful with my language here, which often means I'm going to screw up the explanation so I do apologize for that.

Scripts cannot change the UI or apply a preset to the tool options palette. When you select a preset from the Tool Options Palette or from a dialog box it calls the "Preset_CommandNameHere()" function which just returns a dictionary of settings. Then PSP itself updates the UI. But if you call the Script using RunScript or call the command PSP executes the command using the settings you specified. It never touches the UI.

In the case of your script above there, it's calling PenTool but not telling it to draw anything. So it executes but does nothing, and since the script can't change the UI it also doesn't change the Tool Options. The only way that I know of to set a preset is by doing it manually. You can, however, use a preset to inform your script what settings should be used when you execute a command.
ilgk48
Posts: 60
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: How to set a Preset ?

Post by ilgk48 »

Thank you ...
Let me say: after your explanation I understand that Preset is totally useless/impossible for my purposes.
I think that often, in PSP, a cent is missing to make a dollar.
ilgk48
Posts: 60
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: How to set a Preset: I continue here but should better in PSP

Post by ilgk48 »

A little experiment (PSP 2019):
I choose the PenTool;
I set it to DrawLines, ConnectSegments to unchecked, Width = 5;
I save it say as P1.
(euphemism: the interface for managing the presets is not comfortable).

I create and save a second preset, say P2, setting:
Point to point, ConnectSegments checked, Width = 10.

Well: switching from P1 to P2 and viceversa, Drawlines, Point to point and Width change as for preset, but ConnectSegments does not change!;
Its value remains the one set in the Palette.

Maybe this occurs for others options? Or in other tools?
migf1
Posts: 485
Joined: Fri Apr 03, 2020 3:09 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit

Re: How to set a Preset ?

Post by migf1 »

I'm afraid I can't help you there ilgk48, since my PSP scripting (and python) skills are close to none, but I have a question related to this topic.

If I got it right, we cannot set tool values from a script? I recently got a script from here (in the description):

where they actually do some GUI changes, like Resetting the materials, swapping them, and then setting the Paint Brush as the active tool.

However, they do not set values for the brush. I thought I could add those to the script (hardness, step, thickness, density, rotation, opacity) so I came here to look for a related topic, like this one. If I got it right, it is not possible, right?

PS. I do have a programming background, from a long time ago, and I think it may be time for me to slowly start fiddling with PSP scripts too.

EDIT:

I forgot to post the code related to GUI changes in their script. I'm quoting it below:

Code: Select all

...

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

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

    # SelectTool PaintBrush
    App.Do( Environment, 'SelectTool', {
            'Tool': 'PaintBrush',
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((17,0,0),1)
                }
            })
Good Unofficial PaintShop Pro Tutorials: Creation CasselMake Shop ProHEC Image EditingLeviFiction PSP Basics
(plus my own Gimp & Stuff)
LeviFiction
Advisor
Posts: 5985
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, 9, X, XI, X2, X8,X9, 2018, 2019
Location: USA

Re: How to set a Preset ?

Post by LeviFiction »

@migf1 - Swapping Materials, Choosing a tool, and resetting materials are direct commands. "SwapMaterials", "ResetMaterials", and "SelectTool" are the commands that would be used for those. These same commands can be found in the "Unused Commands" section of the customize dialog. Loosely speaking these aren't actually GUI commands, though. PSP updates the GUI to match the changes made by these commands. There is another instance in which a script can technically adjust the GUI and that's when you run a command with a dialog-box interactively.

But PSP is ultimately the one updating the GUI and not directly. It's always as a result of running a different command that requires it. And in some cases, like with "SelectDocument" even running the command won't change GUI.

It's also rarely necessary for a script to change the tool settings for the user. If a script is going to use a tool it'll either have a preset tool set-up already, or it'll grab the Last Used data from the "CommandInfo" command to use the settings that the user wants to use.

I would like to correct something I said, though. I just learned we can technically trick PSP into updating the tool options palette for a tool, It requires running the command so you'll need to run the command without actually drawing anything or adding vector objects. This is doable you just have to make sure you're getting the settings correct.

Here are the steps
1) Select a different tool (e.g. if you're updating the PenTool settings, select the Pick tool or Eye Dropper)
2) Run the tool command but make sure you don't actually change the image if possible
3) If you did change the image, undo the image change
4) Select the tool you actually wanted to use.

How this works is, when PSP loads a tool it grabs the "Last Used" settings and loads them into the GUI. These last used settings can be changed in one of two ways: 1) If you move away from a tool PSP takes the current settings and saves them as the "Last Used" ones. 2) If you run a command the settings you use become the "Last Used" settings...usually.

So, if we have a different tool selected when we run the tool command our settings become the Last Used ones, and then when we select the tool we want, PSP loads those settings in.
migf1
Posts: 485
Joined: Fri Apr 03, 2020 3:09 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit

Re: How to set a Preset ?

Post by migf1 »

Levi thanks again for the detailed explanation, but my limited PSP scripting knowledge gets in the way. It's not clear to me what "run the command" means. You mean like calling PaintBrush omitting any of its parameters?

Code: Select all

    App.Do( Environment, 'PaintBrush', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((17,0,0),1)
                }
            })
If so, how can I ensure it won't change the image? I think they use the EnableOptimizedUndo thing, so doesn't that mean I shouldn't try to Undo from withing the script?

When you get the chance, could you show me an example of your suggestion with code, preferably filling up the code I posted above? Their script ends with those 3 commands, with the mask layer selected (so the user can start immediately painting on the mask layer).
Good Unofficial PaintShop Pro Tutorials: Creation CasselMake Shop ProHEC Image EditingLeviFiction PSP Basics
(plus my own Gimp & Stuff)
LeviFiction
Advisor
Posts: 5985
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, 9, X, XI, X2, X8,X9, 2018, 2019
Location: USA

Re: How to set a Preset ?

Post by LeviFiction »

You don't omit the paremters of the paint brush tool, you simply use a blank Strokes list. If there are no strokes to make the paintbrush won't draw anything. This means you have to approach each tool differently. The PenTool command, for example, doesn't actually draw anything. If you ever record using the pen tool it uses other commands like "CreateDrawingObject" and "NodeOffset" to actually draw with the command. So let's start with ilgk48's question. They called a preset using the RunScript command. But the script they posted was the preset itself. SoHere is how I would do what they wanted.

Code: Select all

from PSPApp import *

def ScriptProperties():
    return {}

def Do(Environment):
    # .... Default code here

    # SelectTool
    App.Do( Environment, 'SelectTool', {'Tool':'Pick'})

    # RunScript
    App.Do( Environment, 'RunScript', {
            'FileName': u'C:\\pathtopresets'\
                u's\\Preset_PenTool_MyDefault.PspScript', 
            'ScriptExecutionMode': App.Constants.ExecutionMode.Silent, 
            'CheckVersion': True, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((22,0,0),1)
                }
            })

    # SelectTool
    App.Do( Environment, 'SelectTool', {'Tool':'PenTool'})
There does seem to be an odd bug there where I had to run that script twice to get all of the settings to update properly. Not sure why. But it still worked.

Now, for your code.

Code: Select all

def Do(Environment):
    #... Other code

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

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

    # SelectTool - We're selecting the PIck tool in case the PaintBrush tool is already selected
    App.Do( Environment, 'SelectTool', {
            'Tool': "Pick",
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((17,0,0),1)
                }
            })    

    # PaintBrush - Run to set the Last Used settings
    App.Do( Environment, 'PaintBrush', {
            'BrushTip': {
                'Shape': App.Constants.BrushShape.Custom, 
                'CustomBrush': u'Snow', 
                'Size': 100, 
                'Hardness': 100, 
                'Step': 27, 
                'Density': 100, 
                'Thickness': 100, 
                'Rotation': 0, 
                'BrushVariance': {
                    'SizeVariance': App.Constants.VarianceMethod.Pressure, 
                    'SizeJitter': 5, 
                    'OpacityVariance': App.Constants.VarianceMethod.None, 
                    'OpacityJitter': 48, 
                    'DensityVariance': App.Constants.VarianceMethod.None, 
                    'DensityJitter': 0, 
                    'ThicknessVariance': App.Constants.VarianceMethod.None, 
                    'ThicknessJitter': 0, 
                    'RotationVariance': App.Constants.VarianceMethod.None, 
                    'RotationJitter': 32, 
                    'ColorBlendVariance': App.Constants.VarianceMethod.None, 
                    'ColorBlendJitter': 0, 
                    'HueVariance': App.Constants.VarianceMethod.None, 
                    'HueJitter': 0, 
                    'SaturationVariance': App.Constants.VarianceMethod.None, 
                    'SaturationJitter': 0, 
                    'LightnessVariance': App.Constants.VarianceMethod.None, 
                    'LightnessJitter': 34, 
                    'PositionJitter': 11, 
                    'UseScaledPositionJitter': False, 
                    'ImpressionsPerStep': 1, 
                    'FadeRate': 100
                    }, 
                'BrushTrayShow': False
                }, 
            'Brush': {
                'Opacity': 50, 
                'ContinuousPaint': False, 
                'WetLookPaint': False, 
                'BlendMode': App.Constants.BlendMode.Normal, 
                'CAMG': None
                }, 
            'PrimaryMaterial': App.Constants.MaterialRef.Foreground, 
            'ForegroundMaterial': None, 
            'BackgroundMaterial': None, 
            'Stroke': [],   #EMPTY STROKE TO PREVENT DRAWING
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'RandomSeed': 40873126, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((17,0,0),1)
                }
            })

    # SelectTool PaintBrush - Paint brush should now be selected with the settings you wanted.
    App.Do( Environment, 'SelectTool', {
            'Tool': 'PaintBrush',
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((17,0,0),1)
                }
            })

migf1
Posts: 485
Joined: Fri Apr 03, 2020 3:09 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit

Re: How to set a Preset ?

Post by migf1 »

This was super helpful! I'll play with it tomorrow. Thank you very much!
Good Unofficial PaintShop Pro Tutorials: Creation CasselMake Shop ProHEC Image EditingLeviFiction PSP Basics
(plus my own Gimp & Stuff)
migf1
Posts: 485
Joined: Fri Apr 03, 2020 3:09 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit

Re: How to set a Preset ?

Post by migf1 »

I couldn't wait, just tried and it works beautifully! :)
Thanks again!
Good Unofficial PaintShop Pro Tutorials: Creation CasselMake Shop ProHEC Image EditingLeviFiction PSP Basics
(plus my own Gimp & Stuff)
ilgk48
Posts: 60
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: How to set a Preset ?

Post by ilgk48 »

migf1 wrote:
Tue Mar 09, 2021 4:10 pm
I'm afraid I can't help you there ilgk48, since my PSP scripting (and python) skills are close to none, but I have a question related to this topic.
...

PS. I do have a programming background, from a long time ago, and I think it may be time for me to slowly start fiddling with PSP scripts too.

Hi migf1, I think that LeviFiction has given to us the solution we need :) :) :)
Moreover, his solution explains a problem (not serious but annoying) that sometimes occurs after the execution of a my script. Now, thanks to LeviFiction, I can trap the problem!

Regarding Python, I too have a very long programming background and very often PSP makes me crazy for his insufficient capability of being used by a programmer - like me - who wants control it without restrictions :-).
Maybe it is not supposed to be used like a server :D :D ???
In any case I too am playing with Python only a short time.
migf1
Posts: 485
Joined: Fri Apr 03, 2020 3:09 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit

Re: How to set a Preset ?

Post by migf1 »

Nice to know ilgj48 :)

And yes, Levi is a great... um... "asset" for this forum (especially when it comes to scripting, but not only).
Good Unofficial PaintShop Pro Tutorials: Creation CasselMake Shop ProHEC Image EditingLeviFiction PSP Basics
(plus my own Gimp & Stuff)
Post Reply