+ Reply to Thread
Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Paul MR

Thread: Photoshop scripting - how to insert a layer from another PSD

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Photoshop scripting - how to insert a layer from another PSD

    Hi,
    I'm fairly new to PS scripting, and I tried my best to do this on my own or find an existing script, but with no luck.
    I want to insert a layer (or group) from another PSD file, into the current document. I want to provide the layer/group name and PSD filename in the script itself.
    I tried to do this with the script listener plugin, but it just created a script that opens the other PSD.
    Is it possible to script this?
    Can anyone help and provide a script?
    Thanks!

  2. #2
    Administrator
    Join Date
    Jul 2010
    Location
    New Jersey, USA
    Posts
    4,744
    Thanks
    12
    Thanked 160 Times in 150 Posts

    Re: Photoshop scripting - how to insert a layer from another PSD

    Send a PM to Paul MR if he doesn't respond in a day or so.

  3. #3
    The Script Master
    Join Date
    May 2009
    Location
    Bradford,UK
    Posts
    208
    Thanks
    0
    Thanked 39 Times in 34 Posts

    Re: Photoshop scripting - how to insert a layer from another PSD

    I have arrived Steve

    To give any help I would need to have a bit more information.
    You say you want to put some layer(s)/groups(s) from another psd to the active document.
    Where is this other PSD, is it opened, does it need to be selected and opened.
    If opened you would need to know it's name to be able to select it.
    Once the psd has been selected, how do you propose to select the layer(s)/group(s)
    Do you have the names? or do you want to copy all layers/groups to the active document.
    Most things can be done, it's just a matter of working out what needs to be done, before starting to code.

    Hopefully we get a result in the end

  4. #4
    Junior Member
    Join Date
    May 2011
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Photoshop scripting - how to insert a layer from another PSD

    Hi,
    Thank you for responding!

    All the PSD files are located at a specific directory, something similar to "d:\documents\projects\PS"

    I basically, at the moment, have 3 different files that i normally use when i edit my photographs.

    First, i have a PSD called watermark.psd.
    I want to be able to pool the group (just called Group 1, but i can rename if needed for the code) into my active document, because i want to preserve all the layers, adjustment layers, opacity and blending settings etc.

    The same thing goes with a copyright.psd, but it only contains a layer name "Boaz Zemer" (my name). This layer has a layer style applied to it, and also opacity setting.

    And a third file called signature.psd, and it just has a background layer with no special settings.

    Depending on the type of photograph i'm editing, i will use one more of these PSD files. I usually open them manually into a separate window and simply pull the layer or group right into the edited photo's canvas.

    I appreciate your help!
    Thanks...

  5. #5
    The Script Master
    Join Date
    May 2009
    Location
    Bradford,UK
    Posts
    208
    Thanks
    0
    Thanked 39 Times in 34 Posts

    Re: Photoshop scripting - how to insert a layer from another PSD

    Ok here is a bit of code to be going on with.
    This first bit of code assumes you have the document open where you want the layerset "Group 1"
    You could hard code the filename, but this examples lets you pick the file.
    It opens the PSD selects layerset "Group 1" and duplicates it into your original document then closes the PSD, leaving your original document open...
    Code:
    main();
    function main(){
    if(!documents.length) return; //no documents open
    var originalDoc = activeDocument;
    var origName = decodeURI(activeDocument.name);
    var newFile = null;
    //select psd file
    while(newFile == null){ newFile =File.openDialog("Please select PSD.","PSD File:*.psd");}
    open(newFile);
    try{
    activeDocument.activeLayer  = activeDocument.layerSets.getByName("Group 1"); 
    }catch(e){
        alert("Group 1 does not exist in this psd");
    }
    dupLayers(origName);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    function dupLayers(aDoc) {
      function cTID(s) { return app.charIDToTypeID(s); };
        var desc153 = new ActionDescriptor();
            var ref61 = new ActionReference();
            ref61.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
        desc153.putReference( cTID('null'), ref61 );
            var ref62 = new ActionReference();
            ref62.putName( cTID('Dcmn'), aDoc );
        desc153.putReference( cTID('T   '), ref62 );
        desc153.putInteger( cTID('Vrsn'), 2 );
        executeAction( cTID('Dplc'), desc153, DialogModes.NO );
    };
    This example is generic again you can hard code your file but this code lets you select the required psd and "Place the selected document" into your open document.
    (Same as File - Place).
    This is handy for Watermarks etc...

    Code:
    main();
    function main(){
    if(!documents.length) return; //no documents open
    var newFile = null;
    //select psd file
    while(newFile == null){ newFile =File.openDialog("Please select PSD.","PSD File:*.psd");}
    //place psd file
    placeFile(newFile);
    }
    function placeFile( file) {
        var desc = new ActionDescriptor();
        desc.putPath( charIDToTypeID('null'), file );
        desc.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') );
            var offsetDesc = new ActionDescriptor();
            offsetDesc.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), 0.000000 );
            offsetDesc.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), 0.000000 );
        desc.putObject( charIDToTypeID('Ofst'), charIDToTypeID('Ofst'), offsetDesc );
        executeAction( charIDToTypeID('Plc '), desc, DialogModes.NO );
    };
    Please let me know if you have any questions.

  6. #6
    Administrator
    Join Date
    Jul 2010
    Location
    New Jersey, USA
    Posts
    4,744
    Thanks
    12
    Thanked 160 Times in 150 Posts

    Re: Photoshop scripting - how to insert a layer from another PSD

    Quote Originally Posted by Paul MR View Post
    I have arrived Steve
    The Script Master has arrived!!

  7. #7
    Junior Member
    Join Date
    May 2011
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Photoshop scripting - how to insert a layer from another PSD

    Brilliant! Thank you so much!!!

  8. #8
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Photoshop scripting - how to insert a layer from another PSD

    Thank you so much!!!

 

 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Powered by vBulletin® Version 4.1.9
Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.
Content Relevant URLs by vBSEO 3.6.0
Copyright 2011 Photoshop Gurus Forum. All rights reserved.
All times are GMT -5. The time now is 09:14 AM.
vBulletin Skins