Edit/Rename SmartObject File Reference (Embedded PSB File)

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

User avatar
AntonioGomez
Posts: 8
Joined: Fri Jul 29, 2016 7:05 am
Location: San Jose, CA

Edit/Rename SmartObject File Reference (Embedded PSB File)

Post by AntonioGomez »

Hi,

I'm able to get the File Reference of an embedded Smart Object Layer but I was wondering how to execute the corresponding ActionDescriptor to modify that specific string.

I know that Photoshop changes the name of the temporary PSB file appending numbers every time it's contents gets edited (if there are repeated files sharing the same name at the temp folder). I need more descriptive SmartObject filenames for PSDs already created.

Here my function that returns that string stored at the key4 (fileReference) of desc2 (smartObject)

Still learning how ActionDescriptors / Action Manager Code / Kevlar API works.

Code: Select all


function getFileReference() {  
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc1 = executeActionGet(ref);
var desc2 = desc1.getObjectValue(stringIDToTypeID('smartObject'));

return desc2.getString(desc2.getKey(4));
}
Thanks! :D
User avatar
DavideBarranca
Posts: 16
Joined: Tue Jul 26, 2016 2:12 pm

Re: Edit/Rename SmartObject File Reference (Embedded PSB File)

Post by DavideBarranca »

Hi Antonio,
this should theoretically work, but it doesn't. ARGH.

Code: Select all

function setSmartObjectLinkedPath(pathString) {

var cTID = function(key) { return charIDToTypeID(key); }
var sTID = function(key) { return stringIDToTypeID(key); }

// Getting the Layer descriptor
var ref = new ActionReference();
ref.putEnumerated(sTID("layer"), sTID("ordinal"), sTID("targetEnum"));
var layerDesc = executeActionGet(ref);
// Getting the SmartObjet Descriptor
var soDesc = layerDesc.getObjectValue(sTID('smartObject'));
// Putting a new Path in it
soDesc.putPath(sTID('link'), File(pathString));

// Creating a new Smart Object Descriptor
soRef = new ActionReference();
soRef.putEnumerated( sTID('smartObject'), sTID('ordinal'), sTID('targetEnum'));
setSoDesc = new ActionDescriptor();
setSoDesc.putReference(sTID('target'), soRef);
// Filling it with the modified soDesc
setSoDesc.putObject(sTID('to'), sTID('smartObject'), soDesc);

// Setting
executeAction(sTID('set'), setSoDesc, DialogModes.NO);

}
Davide
User avatar
DavideBarranca
Posts: 16
Joined: Tue Jul 26, 2016 2:12 pm

Re: Edit/Rename SmartObject File Reference (Embedded PSB File)

Post by DavideBarranca »

Wouldn't this suffice?

Code: Select all

var d = new ActionDescriptor();
d.putPath( stringIDToTypeID( "target" ), new File( "/Users/davidebarranca/Desktop/Elena.jpg" ) );
executeAction( stringIDToTypeID( "placedLayerReplaceContents" ), d, DialogModes.NO );
Davide
User avatar
AntonioGomez
Posts: 8
Joined: Fri Jul 29, 2016 7:05 am
Location: San Jose, CA

Re: Edit/Rename SmartObject File Reference (Embedded PSB File)

Post by AntonioGomez »

Davide,

Thanks for the help, 'placedLayerReplaceContent's it's a possible solution but what I was trying to achieve is to change the String that represents the embedded PSB file, something like 'Layer 1.psb' instead of the path that links to an external file.

We all know that PH uses the selected layer name as a way to name the embedded SO file name, so if it gets created and stored, I'm sure that there is a way to modify that String without re-embedding or replacing that SO contents with a physically renamed PSB file.

I don't know if this makes sense.

Thanks again for the help! :D

-Antonio