Skip to main content
Alphavader
Participating Frequently
February 10, 2015
Answered

open as linked smart object

  • February 10, 2015
  • 3 replies
  • 1350 views

Hello,

iam looking for a solution to open files in a folder

and copy then into a document.

Its working good, but i need the files to be linked smart object.

Anyone knows a solution ?

Here my Code so far:

See in line 33. Convert to smart object: ?

var file = new File('C:/User_MY PATH.PSD'),

docRef = open(file);

// Use the path to the application and append the samples folder

var samplesFolder = Folder('C:/USERS_MY FOLDER');

//Get all the files in the folder

var fileList = samplesFolder.getFiles()

  // open each file

  for (var i = 0; i < fileList.length; i++)

  {

  // The fileList is folders and files so open only files

  if (fileListinstanceof File)

  {

  open(fileList)

  // use the document name for the layer name in the merged document

  var activeDocName = app.activeDocument.name;

  var targetDocName = activeDocName.substring(0, activeDocName.lastIndexOf("."));

  // Copy the Document

  app.activeDocument.selection.selectAll()

  //convertToSmartObject(); THIS ISNT WORKING - CONVERT IT ?

  app.activeDocument.selection.copy()

  // don’t save anything we did

  app.activeDocument.close(SaveOptions.DONOTSAVECHANGES)

  //Select specific layer to paste the copy, this is to make sure the layers are in a specific position

  var doc = app.activeDocument;

  doc.activeLayer = doc.artLayers.getByName("bgr");

  //Paste Document

  app.activeDocument.paste()

  app.activeDocument.activeLayer.name = targetDocName

  }

  };

This topic has been closed for replies.
Correct answer Chuck Uebele

Use scriptlistener:

var idPlc = charIDToTypeID( "Plc " );

    var desc2 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc2.putPath( idnull, new File( "C:\\Photos\\myPhoto.psd" ) );

    var idLnkd = charIDToTypeID( "Lnkd" );

    desc2.putBoolean( idLnkd, true );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc2.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc3 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc3.putUnitDouble( idHrzn, idPxl, 0.000000 );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc3.putUnitDouble( idVrtc, idPxl, 0.000000 );

    var idOfst = charIDToTypeID( "Ofst" );

    desc2.putObject( idOfst, idOfst, desc3 );

executeAction( idPlc, desc2, DialogModes.NO );

3 replies

Participant
November 18, 2015

Hi there,

It but it would be very useful to me too.

As I'm not familiar with scripting in photoshop, I have hard time to read the code, especially the one Chuck Uebele posted, as it looks less beginner friendly than the Alphavader posted in the first place.

My question is : Is there anyone that finalize the script ? (preferably with comments in the code...)

Thanks for reading  !

matias.kiviniemi
Legend
February 11, 2015

Also you should be able to use application.open(file, OpenDocumentType.PHOTOSHOP, true) to open a file as a smart object and the duplicate it to your target doc. If you do the same in UI, it should create a linked smart object.

Alphavader
Participating Frequently
February 11, 2015

Its working for Smart Object - but it didnt convert it to LINKED one.

Also therre is a small Problem, that i copy the selection - i have to copy/duplicate the layer.

Thanks,

Alpha

matias.kiviniemi
Legend
February 12, 2015

You are right, it's not linked even if you use "File->Open as Smart Object".. Doesn't seem to be a way in API to create linked ones

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
February 11, 2015

Use scriptlistener:

var idPlc = charIDToTypeID( "Plc " );

    var desc2 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc2.putPath( idnull, new File( "C:\\Photos\\myPhoto.psd" ) );

    var idLnkd = charIDToTypeID( "Lnkd" );

    desc2.putBoolean( idLnkd, true );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc2.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc3 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc3.putUnitDouble( idHrzn, idPxl, 0.000000 );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc3.putUnitDouble( idVrtc, idPxl, 0.000000 );

    var idOfst = charIDToTypeID( "Ofst" );

    desc2.putObject( idOfst, idOfst, desc3 );

executeAction( idPlc, desc2, DialogModes.NO );

Alphavader
Participating Frequently
February 12, 2015

This is working, but i want to read in a whole folder

not a specific file. I have to look into it - thanks again!