Paste in Place script?

Moderator: Kathy_9

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

Paste in Place script?

Post by migf1 »

Hello, not sure if I have asked this before (a forum search suggested I have not) but is there a proper "Paste In Place" script available for PSP? If not, would it be possible for someone (Levi?) make such a script? I've given up hope waiting for Corel to add the functionality as a proper command.

I'm currently using hec-fashion's semi automatic script (she only provides instructions on how to record it) and it works in all cases (rasters, vectors, masks and groups), BUT it does require manually ungrouping and deleting layers from both images after the pasting.

It is better than nothing, but a script that automates the whole thing would be so much better.

EDIT: Following up the discussion in this topic, I recorded 3 scripts which I'm sharing in case they prove useful for other people too. I'm attaching them packed in a zip file. To save me some typing, I am also copying here the included Readme file. Please note that I have not tested them extensively, so if you find any issues, please use this topic for reports, ideas, etc.

Download:
migf1-paste-in-place-scripts.zip
(5.14 KiB) Downloaded 5 times
Mini Video (basic usage): download (imgur degraded the video quality drastically, so you may want to use this direct link to get the crisp original clip).

README.TXT

This is a small set of scripts, to workaround the lack of a proper 'Paste In Place' command in PaintShop Pro. They can handle all types of layers and groups (masks included) and plain raster selections. These scripts have been recorded, not coded.

Limitations:
* source and destination images MUST have the same dimensions
* the scripts do NOT work with multiple layers (Workaround: group them together and apply the scripts to the group)
* mask-groups should NOT include un-promoted background layers (promote them before using the scripts)
* pasting ALWAYS creates a new layer to the destination image (merge it down if you need to)

More info and download links (Corel Users forums):
https://forum.corel.com/viewtopic.php?f=104&t=67887

Mini Video (the scripts have been already bound as context-menu commands)

Inspired by:
1. hec-fashion's video
2. LeviFiction's suggestion for a 2nd script

QUICK HELP

Unpack the included scripts in any of the folders listed in the following dialog:
File -> Preferences -> File Locations [Scripts - Restricted]

You can then use the scripts directly from PSP's Scripts toolbar ("View -> Toolbars -> Script"), but the recommended usage is binding them to icons via the "View -> Customize [Scripts]" dialog, and then place them to existed or custom toolbars/menus. If you are not familiar with that, here's a helpful video.

Included Scripts:

Copy Layer For Paste In Place (source image)
Use this to copy the currently selected layer or layers-group to the clipboard. Mask-groups work too.

Copy Selection For Paste In Place (source image)
Use this to copy the current raster selection (marching ants) to the clipboard. Selections created from vectors via "Selections -> From Vector Object" work too.

Paste As New Layer In Place (destination image)
Use this to paste the clipboard data to the destination image, placing them at the same relative location compared to the source image. This works ONLY when the data have been copied to the clipboard via one of the Copy scripts described above.

For more info/download links/questions/etc, see the Corel Users forum corresponding topic:
https://forum.corel.com/viewtopic.php?f=104&t=67887

Last edited by migf1 on Tue Jan 12, 2021 4:46 pm, edited 8 times in total.
Good Unofficial PaintShop Pro Tutorials: Creation CasselMake Shop ProHEC Image EditingLeviFiction PSP Basics
(plus my own Gimp & Stuff)
LeviFiction
Advisor
Posts: 5901
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: Paste in Place script?

Post by LeviFiction »

You should be able to record the deleting of the group and layers as well without much fuss. As PSP records these actions as relative movements. So you can paste the layers anywhere in the image not just on the top of the layers and still get it to work. I honestly don't know why hec-fashion doesn't do this. They're already recording two separate scripts for each part of the process. Once you've copied the layer you just undo the group on the current layer restoring everything to the way it was.

1) Select the layers you want to group and hit record on the script toolbar
2) Group
3) Select top layer in group
4) Add new layer (if any selections are present deselect them)
5) Fill layer wth color
6) Select group layer
7) Copy (layers are now on clipboard we no longer need the original group
8) Either use Undo (Requires editing the script to allow undos) or select the color layer, delete it, select the group layer top and ungroup the layers. Now your original group is gone, and fully recorded in script.
9) Save Script as Prep-Paste In Place
10) Go to new image
11) Hit record on the script toolbar
12) Paste
13) Select raster layer in group - delete
14) Select group top and ungroup.
15) Save script as "Paste in place"

You now have two scripts that handle the whole process for you.

Could I potentially make a smarter script? Yes, but that would be way more complex.
migf1
Posts: 395
Joined: Fri Apr 03, 2020 3:09 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit

Re: Paste in Place script?

Post by migf1 »

Thanks for the detailed answer Levi.

I asked hec-fashion why she shows the recording of just 1 script for the creation of the temp group and then leaves the clean up after the pasting as a manual process, instead of showing your suggestion about recording 2 scripts: 1 for Copy (for the temp group) and 1 for Paste.

She told me she should had mentioned it, but forgot. She felt the video got already too complex for the average PSP viewer and assumed more advanced viewers would record 2 scripts anyway (frankly I have no idea why I didn't think of it either).

For the record, it works like a charm.

PS. It's a shame that a more advanced script is hard to write (I thought it wouldn't be). I really don't get why Corel don't add this as a proper command. It exits for a long time in all major "competition".
Good Unofficial PaintShop Pro Tutorials: Creation CasselMake Shop ProHEC Image EditingLeviFiction PSP Basics
(plus my own Gimp & Stuff)
LeviFiction
Advisor
Posts: 5901
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: Paste in Place script?

Post by LeviFiction »

The majority of the "complex" part comes from the fact that you need to be able to compare the source image to the destination image. This can be done in two scripts, or as a pause script (a single script you run twice). Just have it record the source image size and the layer rectangle, then either in the second script or the second run of a pause script do the comparison and either paste as normal or paste as normal and then use the move tool. This is fine so long as you start and end the script during the same session or from the same program. There is a slight complexity when it comes to vectors but I don't think that's a huge issue. To make it truly useful I would want the script to paste in place without having to run a prep-script. It would paste in the center any image that isn't in PSPImage format on the clipboard as per normal. But if it was in PSPImage format, I'd then parse the image to determine size and position. This would allow you to paste between versions of PSP, to copy the regular way from any PSP Image and paste like it was natural.
migf1
Posts: 395
Joined: Fri Apr 03, 2020 3:09 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit

Re: Paste in Place script?

Post by migf1 »

I honestly have no clue about the functions provided by PSP's python API (or python itself for that matter), but I assumed (probably wrongly) that if the relative position of a layer inside an image (the source image actually) can be retrieved say compared to the upper left corner, it would then be only a matter of just converting it to the same relative position in the destination image, regardless of absolute coordinates (maybe saving the reltive position specifics in a temp file, if it is not possible to somehow add them to the clipboard along with the layer data themselves).

PS. Btw, personally I wouldn't mind if the "same dimensions" requirement was left as a pre-requesit for the user, or even having both images open before running the scripts.
Good Unofficial PaintShop Pro Tutorials: Creation CasselMake Shop ProHEC Image EditingLeviFiction PSP Basics
(plus my own Gimp & Stuff)
LeviFiction
Advisor
Posts: 5901
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: Paste in Place script?

Post by LeviFiction »

You can do that, the problem is transferring that data between scripts. Again, a pre-prep script would record and do the initial copy, and it would have to check if a selection was active, the type of layer, etc so it would know which rectangle of data for the offset to use (layer, object, or selection) and then it has to get that information over to the other side. Either by creating a global variable that maintains itself across script runs (variables are local to the script running usually) or by saving to a file, Then the second run or final script would grab that data to then make a determination. The only other way would be to parse the PSPImage data on the clipboard before pasting ignoring all pre-prep.
migf1
Posts: 395
Joined: Fri Apr 03, 2020 3:09 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit

Re: Paste in Place script?

Post by migf1 »

We were cross-posting Levi. Actually I was editing my previous post while your were writing yours.. yes, I added the temp-file or the clipboard itself idea, as an intermediate step for saving/retrieving the positional data, as well as that I wouldn't mind at all if the "same dimensions" was left as a requirement for the user (and even having both images open at the same time). A good thing global vars exist btw, but as I said I'm totally unfamiliar with PSP (and python) scripting.

If you say it is hard to do, then I totally believe you.

For now I'm good with hec-fashon's trick, and your additional idea for a 2nd script. I actually recorded her idea as "Copy For Paste In Place", and your idea as 'Paste In Place". The 1st one (run on the source image) creates the temp-group, copies it to clipboard and deletes it from the layers palette. The 2nd one (run on the destination image), Pastes As New Layer the clipboard contents, then ungroups the created group and deletes the 2pixels layer.

I'm about to turn off the PC for today, but tomorrow I'll post the scripts here in case anyone else wants them, and I'll probably send them to hec-fashion too, in case she wants to add them to her video (probably in the description, though I'm pretty sure she already has her own lol).
Good Unofficial PaintShop Pro Tutorials: Creation CasselMake Shop ProHEC Image EditingLeviFiction PSP Basics
(plus my own Gimp & Stuff)
LeviFiction
Advisor
Posts: 5901
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: Paste in Place script?

Post by LeviFiction »

I'm not explaining myself well. It's not hard, complex. You have to know how PSP copies each layer type and then prepare for that. To the point where I don't see the purpose. With the recorded script you made PSP does all of the hard work for you, it just uses a number of steps to jump through the hoop. A smarter script would, at best, look like it's doing less overall work as it won't create groups but would still require clean-up and two scripts. What I'm saying is if I myself were to make the script I would want to work past all of that and make it more usable across versions of the program. Which would take more time, accessing Windows APIs, reading binary data, parsing PSPImage data, etc.

As far the method with two scripts and purely working with PSP's own APIs. The Pseudo code steps would be something like this and uses PSPUtils for faster working with data and selections.

Code: Select all

from PSPApp import *
from PSPUtils import *

#Check if script has been run before by finding the key value in ScriptData
if 'PasteInPlaceScript' in ScriptData.keys():
   #Perform paste and move steps here
   App.Do(Environment, 'PasteAsNewLayer', {})
   width, height, bottomleft, topleft, topright,bottomright = *ScriptData['PasteInPlaceScript']
   #Decide here if you want it to center on different sized images, or to always paste at an exact distance from the top corner
   # Here I am only moving it if source and destination are the same size.
   if App.TargetDocument.Width == width and App.TargetDocument.Height == height:
        App.Do(Environment, 'PickTool', {(bottomleft, topleft, topright, bottomright)}
   del(ScriptData['PasteInPLaceScript']) #delete saved data to prevent re-use
   return #leave script

#If script data didn't already exist create it now.
#Prepare tracking vars - ScriptData is a global variable from PSPUtils which sometimes persists between script runs
ScriptData['PasteInPlaceScript'] = [App.TargetDocument.Width, App.TargetDocument.Height, ]  #Not necessary to pre-populate I just do it for my own memory  

# Grab layer type and rectangle data
result = App.Do( Environment, 'ReturnLayerProperties', {})

if result['LayerType'] == App.Constants.LayerType.Raster:
    selResult = App.Do(Environment, 'ReturnRasterSelection', {})
    #if selection exists promote selection to new layer and track the temporary layer
    if selResult['Selection']: #don't know the actual key values pairs for this
        result = {'LayerRect": selResult['SelectRect"]}
    Rect = result['LayerRect']
elif result['LayerType'] == App.Constants.LayerType.Vector:
   #and perform all the same general steps for each layer type if it needs it.  If not just using the LayerRect should be sufficient
   # Vectors could be the entire layer, or just individual objects on that layer.
   # Determne if you want to grab the entire layer or just an individual object and record the appropriate rectangle and take the appropriate steps.

elif result["LayerType"] == App.Constants.LayerType.Group:
   # A group can still fail, for example with a mask layer the grouped layer can still end up centered.  So you need to take precautions and record the position of all children layers in the group and move them individually.
.... #continue on with other layer types.

ScriptData['PasteInPlaceScript"].append(Rect)
App.Do(Environment, 'Copy', {})
if TempLayer:
    App.Do(Environment, 'SelectLayer", {'Path':TempLayer})
    App.Do(Environment, 'DeleteLayer', {})
    
And even then I'm not entirely certain of all of PSP's idiosyncrasies with copying and pasting different layer types and groups of layers etc.
JoeB
Posts: 2633
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: Paste in Place script?

Post by JoeB »

I would suggest that using both scripts in a Pause script, as mentioned by LeviFiction, would be a bit more convenient than having to run to scripts. Running one script then running it again is, of course, less cumbersome than having to select the second script after running the first. And if it's something you do a lot then you could bind the Pause script to a button and only need one button to click on twice.
Regards,

JoeB
Using PSP 2019 64bit
migf1
Posts: 395
Joined: Fri Apr 03, 2020 3:09 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit

Re: Paste in Place script?

Post by migf1 »

Hello guys,

I edited the 1st post of the topic, attaching the scripts I recorded along with their accompanying Readme.txt file and a very short video for basic usage (which for some reason came out with low quality visuals... no idea why, I may re-do it at some point).

I ended up with 3 scripts, meant to be used as bound icons in existed or custom toolbars/menus:
1. Copy Layer for Paste In Place
2. Copy Selection for Paste In Place
3. Paste As New Layer In Place

For a more "natural" look, the first 2 can be added to the Edit -> Copy Special menu, and the 3rd one to the Edit menu (tho I am not using them like that, I rather added them into the main context menu). I hope they will help other people too, but I have not tested them extensively tbh. For any issues/extra ideas, please use this topic.

Levi & Joe thank you both your suggestions (Joe, 3 separate scripts bound as icon commands serve me better... ideally I would like 2, but copying layers is slightly different compared to copying selections, hence the 2 copy scripts).
Good Unofficial PaintShop Pro Tutorials: Creation CasselMake Shop ProHEC Image EditingLeviFiction PSP Basics
(plus my own Gimp & Stuff)
Post Reply