Sunday, November 29, 2015

adobe photoshop - New Smart Object via Copy inside a Layer Group


Is it possible to duplicate a layer group that contains multiple smart objects with relationships to each other, so the duplicate group is separated from the original?


I need the duplicate to be editable without changing the original. This can be achieved by the context menu when interacting with a single smart object, but not for a group containing multiple smart objects.


Any ideas?




Answer



Below is a script that should do what you want.


The script is pretty much identical to the native Duplicate function. The key difference is that Embedded Smart objects within the selection are unlinked from other Embedded Smart objects that sit outside the selection.


This means that if the selected layers are Embedded Smart objects that are direct duplicates of each other, those links won't break.


There is a slight difference in how the layers are named, but I didn't see that as any sort of issue, so I left it like that.




While using a script might feel a bit cumbersome, remember that you can always set a shortcut keys to run scripts:


1. Put the script in the scripts folder.


2. Restart photoshop.


3. Edit > Keyboard shortcuts and menus.



4. In the scrollable area click File and scroll way down to find Scripts> and below that you should find the script name. All that is left is to add the shortcut to it.


enter image description here


The script ( Only tested in PS cc 2014 ):


// https://gist.github.com/joonaspaakko/898394cf2b46ae7b6ad7

#target photoshop

// If there are any documents open, run the code...
// =================================================
if ( app.documents.length > 0 ) {


// Used later on when the layers are duplicated back to the original document.
// ===========================================================================
var docName = app.activeDocument.name;

// Script listener code - Duplicate active group to a new document.
// =================================================================
var idMk = charIDToTypeID( "Mk " );
var desc14 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );

var ref10 = new ActionReference();
var idDcmn = charIDToTypeID( "Dcmn" );
ref10.putClass( idDcmn );
desc14.putReference( idnull, ref10 );
var idUsng = charIDToTypeID( "Usng" );
var ref11 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref11.putEnumerated( idLyr, idOrdn, idTrgt );

desc14.putReference( idUsng, ref11 );
var idVrsn = charIDToTypeID( "Vrsn" );
desc14.putInteger( idVrsn, 5 );
executeAction( idMk, desc14, DialogModes.NO );


// Script listener code - Duplicate active group to the prior document.
// =====================================================================
var idDplc = charIDToTypeID( "Dplc" );
var desc16 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );
var ref13 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref13.putEnumerated( idLyr, idOrdn, idTrgt );
desc16.putReference( idnull, ref13 );
var idT = charIDToTypeID( "T " );
var ref14 = new ActionReference();
var idDcmn = charIDToTypeID( "Dcmn" );

ref14.putName( idDcmn, docName );
desc16.putReference( idT, ref14 );
var idVrsn = charIDToTypeID( "Vrsn" );
desc16.putInteger( idVrsn, 5 );
executeAction( idDplc, desc16, DialogModes.NO );

// Closes the new document.
// =======================================================
app.activeDocument.close( SaveOptions.DONOTSAVECHANGES );


}

No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...