Use ScriptingListener.plugin to get the code for opening a SO (check the Help or »Photoshop CS5 Scripting Guide.pdf« for instructions for how to use the plug-in).
Then you can use that in a Script if the activeLayer is a SO.
Copy/Pasting would not be a good idea, you could instead use a function or a for-clause to duplicate the Layers to the target document.
From the Big List:
var id567 = charIDToTypeID( "slct" ); var desc110 = new ActionDescriptor(); var id568 = charIDToTypeID( "null" ); var ref79 = new ActionReference(); var id569 = charIDToTypeID( "Mn " ); var id570 = charIDToTypeID( "MnIt" ); var id571 = stringIDToTypeID( "placedLayerEditContents" ); ref79.putEnumerated( id569, id570, id571 ); desc110.putReference( id568, ref79 ); executeAction( id567, desc110, DialogModes.ALL );
I think you may be better off just copying the smart object layer from the source document into the target document. There may be several different resolutions involved and other complexities. Within a smart object layer there is a copy of the original object. So how the smart object layer was created determines what the imbedded object is. A smart object may be many thing. Could be a copy of a raw file, a copy of a layered file, contain a group of layers created from within the source document. There is a transform associated with smart object layers. When you open a smart layer into Photoshop so you can edit the embedded smart object it opens at the resolution and size of the object which may be different then the document its a layer in. The transform is only associated the layer not the object. Once open into Photoshop you can of course dupe the layers into the target document. It may be a bit complex for some layers may have layer mask and perhaps other layers clipped to it or be within a group then there is the layers visibility state. If you have both the source document and target document open in Photoshop it is easy co copy a layer from the source document to the target document. If the source layer is a smart object the associated transform will also be copied to the target document however it easy re transform the smart object layer in the target document. In the source document target the smart object layer the use menu Layers>Duplicate Layer... in the Duplicate Layer dialog in the destination section use the pull down menu to select the target document You can use the scriptlistener plugin to capture the action manager code to do that.
var idDplc = charIDToTypeID( "Dplc" );
var desc24 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref14 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref14.putEnumerated( idLyr, idOrdn, idTrgt );
desc24.putReference( idnull, ref14 );
var idT = charIDToTypeID( "T " );
var ref15 = new ActionReference();
var idDcmn = charIDToTypeID( "Dcmn" );
ref15.putName( idDcmn, "Untitled-2" ); <====================================== target document
desc24.putReference( idT, ref15 );
var idVrsn = charIDToTypeID( "Vrsn" );
desc24.putInteger( idVrsn, 5 );
executeAction( idDplc, desc24, DialogModes.NO );
You don't need scriptlistner to dupe a layer from one document to another. You can use the artLayer.duplicate() method.
Michael L Hale wrote:
You can use the artLayer.duplicate() method.
Let's say you have two open documents. The first open doc is the one you want to dupe the layer to and the second doc is active and the layer you want to dupe is the activeLayer.
Of course you can change the document and layer references as needed. However the layer to be duped needs to be in the activeDocument.
Thank for you help