Script: Copy and merge visible layers into a new layer

Moderator: Kathy_9

Post Reply
photodrawken
Posts: 684
Joined: Wed Sep 26, 2012 8:40 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
ram: 16Gb
Hard_Drive_Capacity: 324Gb
Location: USA

Script: Copy and merge visible layers into a new layer

Post by photodrawken »

If you've ever created an image having multiple assorted layers, and want to apply a modification to the final image while keeping those original layers intact, here's the script to do that:

Code: Select all

from PSPApp import *

def ScriptProperties():
    return {
        'Author': u'Ken Arway',
        'Copyright': u'2013',
        'Description': u'Copies all visible layers to a newly created ra'\
            u'ster layer.',
        'Host': u'PaintShop Pro',
        'Host Version': u'15.00'
        }



def Do(Environment):

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

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

    # New Raster Layer
    App.Do( Environment, 'NewRasterLayer', {
            'General': {
                'Opacity': 100, 
                'Name': u'Copy Merged 1', 
                'IsVisible': True, 
                'IsTransparencyLocked': False, 
                'LinkSet': 0, 
                'UseHighlight': False, 
                'PaletteHighlightColor': (255,255,64), 
                'GroupLink': True, 
                'BlendMode': App.Constants.BlendMode.Normal
                }, 
            'BlendRanges': {
                'BlendRangeGreen': (0,0,255,255,0,0,255,255), 
                'BlendRangeRed': (0,0,255,255,0,0,255,255), 
                'BlendRangeBlue': (0,0,255,255,0,0,255,255), 
                'BlendRangeGrey': (0,0,255,255,0,0,255,255)
                }, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((15,0,0),1)
                }
            })

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

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

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

Just use your favourite text editor to copy that code into a text file, and save the file as "CopyVisibleMergedToNewLayer.pspscript" in your user scripts directory. Doesn't matter if it's the "Restricted" or "Trusted" directory.

As the name implies, all the visible layers will be copied and merged, so it's easy to first "hide" the layers you don't want merged before running the script.

Yes, it's just a series of recorded actions; but the key is its use of the "Select All" and "Paste Into Selection" actions -- that ensures that the resulting merged layer maintains the same positioning as the individual layers. In other words, if your original layers have a transparent background and opaque areas that are off-center, simply using Edit...Paste As New Layer will center those opaque areas in the canvas, which is not what you want....

Enjoy!
Ken
Yes, I think it can be eeeeeasily done...
Just take everything out on Highway 61.
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: Script: Copy and merge visible layers into a new layer

Post by LeviFiction »

EDITED: Never mind, I understand now.
https://levifiction.wordpress.com/
photodrawken
Posts: 684
Joined: Wed Sep 26, 2012 8:40 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
ram: 16Gb
Hard_Drive_Capacity: 324Gb
Location: USA

Re: Script: Copy and merge visible layers into a new layer

Post by photodrawken »

Yes, I have noticed a (unwelcome) different behavior:

1. Create an image with a transparent background.
2. Add a new layer (also having a transparent background).
3. Paint a few strokes on that new layer, keeping the strokes in the lower left corner (for example).
4. Copy Merged, then Paste As New Layer.

Those merged and copied strokes will be centered in the canvas, and not in their original position.

Edit:
Yeah, I responded with this before you edited your message, but I'll leave this response in case others wonder what the fuss is about....
Last edited by photodrawken on Mon Mar 11, 2013 6:21 pm, edited 1 time in total.
Ken
Yes, I think it can be eeeeeasily done...
Just take everything out on Highway 61.
User avatar
hartpaul
Advisor
Posts: 2893
Joined: Tue Mar 20, 2012 3:38 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: ASUSTeK P7P55D STRIX B240F GAMING
processor: IntelCore i7 7700 3.60 Ghz
ram: 8 Gb
Video Card: Nvidia GeForce GTX 1050
sound_card: Nvidia High Definition Audio
Hard_Drive_Capacity: 1000 Gb
Monitor/Display Make & Model: AOC
Corel programs: PSP8,X2 to X9,2018,2019,2020
Location: Australia

Re: Script: Copy and merge visible layers into a new layer

Post by hartpaul »

Another way is to save the image as a psp.
In windows rename the file.
With the image still in memory delete the unwanted layers .
Merge the result.

If the mountain won't come to M, then M must go to the mountain.
Systems available Win7, Win 8.1,Win 10 Version 1607 Build 14393.2007 & version 20H2 Build 19042.867
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: Script: Copy and merge visible layers into a new layer

Post by LeviFiction »

Umm....why don't you just duplicate the image? Shift + D is all it takes. Then merge the full result. No point in going to all of the trouble of renaming the file while PSP is still editing it. Admittedly it temporarily takes up more memory but that's not a huge issue. And if you didn't need the canvas to be the same size, you just copy merged then paste as a whole new image avoiding the issue entirely.

Actually, if all you're doing is renaming the original, then just hit "Save Copy As?" You could also just use a straight "Save As" and give a new name to file before merging?
This is, especially for a script, probably the easiest of methods for maintaining the original canvas size as well position.
https://levifiction.wordpress.com/
Post Reply