Meaning of LayerSelectPoint, in scripting?

Moderator: Kathy_9

crawford
Posts: 11
Joined: Mon Jun 27, 2016 2:42 pm
operating_system: Windows 7 Professional
System_Drive: C
32bit or 64bit: 64 Bit
ram: 4GB
Corel programs: PSP X7
Location: East coast USA

Meaning of LayerSelectPoint, in scripting?

Post by crawford »

So the API docs at [Mover][http://product.corel.com/help/PaintShop ... Mover.html], say that the Layer Select Point:
Determines which layer will be selected by specifying the starting click point of the move
but with no indication of what that actually means.

So if I have two layers, one a background, one a raster-layer that's about half the size of the background, and I use a script to paste a new layer - I then want to move that new layer to, say, cover the raster-layer, so I want to use the Mover. I can move it around, all right - but sometimes the background-layer moves instead, depending on the Select-Point I pick. So it's not clear how I can programmatically pick that Select Point, to move the newly-pasted layer only, to where I want it to go.

Thanks for any help. Would also appreciate pointers to any more detailed API documentation, if it exists.
LeviFiction
Advisor
Posts: 6734
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: Meaning of LayerSelectPoint, in scripting?

Post by LeviFiction »

Points in PSP are tuples written in (x,y) format. The point being how far from the left (x) and how far from the top (y) you click. So exactly as the API documentation says. This setting is the point of the mouse click. And whatever layer has the first visible pixel in that location is the layer that's selected.

There isn't a great way to determine a safe location on a layer to select because some layers will have pockets of transparent areas. There is a way, but it's not built-in to the API. So it's best to use a trick of the move tool. When using the move tool if you hold SHIFT it'll ignore where you click and just move the currently selected layer. So holding SHIFT does something to the command.
If you want to see how different hotkeys like SHIFT and CTRL affect the command you can use the History Palette.

In PSP show the history palette (View -> Palettes -> History). Then perform an action, right-click on the action in the history palette and hit "Copy". Then in notepad or whatever editor you're using. Paste it in, you'll see the command that reflects that action and all of it's parameters.

If you hold SHIFT while using the Move tool and then copy the result you'll notice something interesting LayerSelectPoint is set to None. So we can assume that setting LayerSelectPoint to None will ignore where you click.

EDIT: I would like to add there are several methods for moving a recently pasted layer into position. Mover is the easiest, and probably the fastest in most cases but there are others. Two for general movement, and then the align objects commands if you want to use another layer to align to.

1) Pick tool - this command lets you identify the location of the 4 corners of the layer and where you want them placed. This can result in the image being rotated, skewed, stretched, or just moved. Since this is a transformation command, however, it can be slower on large layers than on smaller ones.

Set all parameters above the "Handle" parameters to None and then just set the (x,y) location of the handles. Note that the handles start in the bottom-left corner of the layer and go clockwise.

2) PasteAsNewSelection - This creates a floating selection, and drops the middle of the layer at the offset you decide. I believe the Offset parameter is measured fromm the center of the canvas. So if you grab the layer properties of the bottom layer you want to align it with, and the center point of the canvas, you can calculate where you want to drop the layer. THen you just need to call "SelectPromote" command to promote it to a full layer. If you unfloat the selection it'll merge into the layer below it.

3) Align commands - These are the VectorAlign commands found in the API. They are called "VectorAlign" because once upon a time they were only available while editing vector objects. Now you can use them on all layers. The big thing is you have to have two layers selected to use them. Which means also using the "VectorSelectionUpdate" command. The Path command is a relative path for getting to the layer you want from the layer you're currently on. Here's an example where I select the layer beneath my current layer, then align their top and left values so they start at the same location on the canvas.

Code: Select all

    # Vector Selection Update
    App.Do( Environment, 'VectorSelectionUpdate', {
            'Path': (0,-1,[],False), 
            'Type': App.Constants.ObjectSelection.AddToSelection, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent, 
                'AutoActionMode': App.Constants.AutoActionMode.Default, 
                'Version': ((25,0,0),1)
                }
            })

    # Vector Align Top
    App.Do( Environment, 'VectorAlignTop', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((25,0,0),1)
                }
            })

    # Vector Align Left
    App.Do( Environment, 'VectorAlignLeft', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((25,0,0),1)
                }
            })
crawford
Posts: 11
Joined: Mon Jun 27, 2016 2:42 pm
operating_system: Windows 7 Professional
System_Drive: C
32bit or 64bit: 64 Bit
ram: 4GB
Corel programs: PSP X7
Location: East coast USA

Re: Meaning of LayerSelectPoint, in scripting?

Post by crawford »

LeviFiction wrote: Sun Apr 30, 2023 8:37 pm There isn't a great way to determine a safe location on a layer to select because some layers will have pockets of transparent areas. There is a way, but it's not built-in to the API. So it's best to use a trick of the move tool. When using the move tool if you hold SHIFT it'll ignore where you click and just move the currently selected layer. So holding SHIFT does something to the command.
Many thanks for this, and the other options. I won't be actually trying this until tomorrow or later, but it definitely has the ring of Truth. :)

It's interesting to see that the Mover command is, IMHO, just a manual operation converted into code. I'm glad to see the other operations, which appear to be more code-oriented, and not simply replicating a GUI.

Oh, I forgot to mention that my version of PSP is X7 - hopefully all this applies. :) The limited docs I've found, are terrible at version-numbering.
LeviFiction
Advisor
Posts: 6734
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: Meaning of LayerSelectPoint, in scripting?

Post by LeviFiction »

I fully believe they are still the same. I have several scripts that work equally well between PSP8 and PSP 2023 without needing to check which version it's being run in. Doesn't mean that's always the case. Scripters like Cassel create very complex scripts that utilize a ton of tools in PSP who do need to take differences into account. For example deforming a layer. There was once a separate tool called the deformation tool, now it's built into the pick tool. So knowing which version the script is running tells her script how to behave and which commands to call. Which is important as she makes her scripts for sale to people using all versions of PSP.

But, big changes that aren't just adding functionality are rare. Though on occasion there will be discrepancies. I don't think those are properly documented. I vaguely recall an issue where the GUI for a command was updated to a new algorithm for the effect, but the script continued to use the original algorithm creating an odd disconnect. Don't remember which command though, and I don't know if it was ever corrected.
Cassel
Posts: 1581
Joined: Fri Oct 29, 2010 6:49 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
ram: 16Gb
Corel programs: PSP 8 (JASC) to PSP 2023
Location: Canada

Re: Meaning of LayerSelectPoint, in scripting?

Post by Cassel »

LeviFiction wrote: Sun Apr 30, 2023 8:37 pm If you hold SHIFT while using the Move tool and then copy the result you'll notice something interesting LayerSelectPoint is set to None. So we can assume that setting LayerSelectPoint to None will ignore where you click.
Whenever I have to move an element on a layer, I always use None as LayerSelectPoint. In a script, there is actually no reason to have a set point as the None will have the same effect and if you end up with a layer that has "holes", you are still safe to move it.
Cassel
https://creationcassel.com/store
Specializing in PSP specific products: scripts and tubes

https://scrapbookcampus.com
for beginner and seasoned scrappers and designers and other PSP users