Skip to main content
Participating Frequently
November 9, 2011
Answered

How open and copy smart object

  • November 9, 2011
  • 3 replies
  • 3088 views

Hi,

I read topics about smart objects but i not found solution on my problem.

1. I need open smart object layer

2. copy all layers from the smart object to another file

Thanks

This topic has been closed for replies.
Correct answer Michael_L_Hale

Michael L Hale wrote:

You can use the artLayer.duplicate() method.

I beleive what you wrote is correct.  I'm just a hacker don't know javascript and don't have a firm grip on object programming or the javascript language syntext. I see many duplicate method in the Photoshop CS5 Scripting Guide.pdf and in the Photoshop CS5 JavaScript Ref.pdf. I do not see a duplicate method section for a layer or artlayer object the closest duplicate method  I see is for layerset which contain artlayers. Because I do not process much knowledge about javascript programming I can not figure out the proper syntext that would be requited to copy an smart object layers from the current active document into an other open document.  Could you post a sample script that I could use to hack with.


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.

app.activeDocument.activeLayer.duplicate(app.documents[0]);

Of course you can change the document and layer references as needed. However the layer to be duped needs to be in the activeDocument.

3 replies

DomaneniAuthor
Participating Frequently
November 10, 2011

Thank for you help

JJMack
Community Expert
Community Expert
November 9, 2011

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 );

JJMack
Inspiring
November 9, 2011

You don't need scriptlistner to dupe a layer from one document to another. You can use the artLayer.duplicate() method.

JJMack
Community Expert
Community Expert
November 9, 2011

Michael L Hale wrote:

You can use the artLayer.duplicate() method.

I beleive what you wrote is correct.  I'm just a hacker don't know javascript and don't have a firm grip on object programming or the javascript language syntext. I see many duplicate method in the Photoshop CS5 Scripting Guide.pdf and in the Photoshop CS5 JavaScript Ref.pdf. I do not see a duplicate method section for a layer or artlayer object the closest duplicate method  I see is for layerset which contain artlayers. Because I do not process much knowledge about javascript programming I can not figure out the proper syntext that would be requited to copy an smart object layers from the current active document into an other open document.  Could you post a sample script that I could use to hack with.

JJMack
c.pfaffenbichler
Community Expert
Community Expert
November 9, 2011

Ad 1)

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.

Ad 2)

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.

c.pfaffenbichler
Community Expert
Community Expert
November 9, 2011

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 );