Copy link to clipboard
Copied
as title suggest id like to use new smart object via copy but copy a lot of them at the same time. please let me know!
Here is an updated 1.1 version of my previous script which will alert on every layer that is linked (one by one, I couldn't be bothered logging them all at the end in a single alert or log file).
/*
Selected Layers to New Smart Object via Copy.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/is-there-a-way-to-use-quot-new-smart-object-via-copy-quot-in-bulk/td-p/14096358
v1.1, 20th September 2023, Stephen Marsh
*/
#target photoshop
function main() {
// Save the current
...
Copy link to clipboard
Copied
not possible.
Copy link to clipboard
Copied
Please post meaningful screenshots including the pertinent Panels and explain what you actually mean – all SOs in the image, the selected ones, …?
A Script could be used to automate the task.
Copy link to clipboard
Copied
// new smart object via copy for all smart objects;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
var theSmartObjects = collectSmartObjects2017();
for (var m = 0; m < theSmartObjects.length; m++) {
selectLayerByID(theSmartObjects[m][1], false);
newSmartObjectViaCopy ()
}
};
////////////////////////////////////
////// collect smart objects, probably based on code by paul, mike or x //////
function collectSmartObjects2017 () {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
if(layerDesc.hasKey(stringIDToTypeID('smartObject'))) {theLayers.push([theName, theID])}
};
}
catch (e) {};
};
return theLayers
};
// based on code by mike hale, via paul riggott;
function selectLayerByID(id,add){
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), id);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
};
////// new so via copy //////
function newSmartObjectViaCopy () {
// ======================================================= new so via copy;
try {
var idplacedLayerMakeCopy = stringIDToTypeID( "placedLayerMakeCopy" );
executeAction( idplacedLayerMakeCopy, undefined, DialogModes.NO );
return app.activeDocument.activeLayer
} catch (e) {alert (e)}
};
Copy link to clipboard
Copied
del
Copy link to clipboard
Copied
Layer > Smart Objects > New Smart Object Via Copy
creates a new Smart Object, a copy of the selected Smart Object, that can then be edited independently from the original Smart Object.
Copy link to clipboard
Copied
Just in case this is useful to somebody... The following script will only process one or more selected smart object layers (as opposed to every smart object layer).
/*
Selected Layers to New Smart Object via Copy.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/is-there-a-way-to-use-quot-new-smart-object-via-copy-quot-in-bulk/td-p/14096358
v1.0, 20th September 2023, Stephen Marsh
*/
#target photoshop
function main() {
// Save the current dialog display settings
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Get the selected layers: courtesy of jazz-y
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
sel = new ActionReference();
// Loop over the selected layers: courtesy of jazz-y
for (var i = 0; i < lrs.count; i++) {
sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
(r = new ActionReference()).putIdentifier(s2t('layer'), p);
(d = new ActionDescriptor()).putReference(s2t("target"), r);
executeAction(s2t('select'), d, DialogModes.NO);
if (activeDocument.activeLayer.typename === "ArtLayer" && activeDocument.activeLayer.kind == "LayerKind.SMARTOBJECT") {
// Call the new smart object via copy function: courtesy fo c.pfaffenbichler
newSmartObjectViaCopy();
}
}
// Finish the loop
// Restore the dialogs
app.displayDialogs = savedDisplayDialogs;
}
function newSmartObjectViaCopy() {
try {
var idplacedLayerMakeCopy = stringIDToTypeID("placedLayerMakeCopy");
executeAction(idplacedLayerMakeCopy, undefined, DialogModes.NO);
return app.activeDocument.activeLayer
} catch (e) {
alert(e)
}
}
// Single history stage undo
activeDocument.suspendHistory("Selected Layers to New Smart Object via Copy.jsx", "main()");
Copy link to clipboard
Copied
I forgot to filter out Linked Smart Objects anyway …
Copy link to clipboard
Copied
I forgot to filter out Linked Smart Objects anyway …
By @c.pfaffenbichler
Yeah, I was only performing basic testing for SO in general, not differentiating between linked vs. embedded. Apart from the exercise, should I try to do better, will it matter in practice?
Copy link to clipboard
Copied
I wasn’t crticizing your Script, I just noticed the oversight in mine.
If I remember correctly New Smart Object Via Copy does not work on Linked Smart Objects, so the try-clause should avoid an abort anyway, but it seems possible that an alert about Linked SOs (if present) might help prevent possible mistakes for the user.
Copy link to clipboard
Copied
I understood that you were commenting on your own script and even if you were commenting on mine, I'd take it as constructive criticism... You are one of my scripting mentors after all!
Anyway, your comment did make me think.
Copy link to clipboard
Copied
Here is an updated 1.1 version of my previous script which will alert on every layer that is linked (one by one, I couldn't be bothered logging them all at the end in a single alert or log file).
/*
Selected Layers to New Smart Object via Copy.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/is-there-a-way-to-use-quot-new-smart-object-via-copy-quot-in-bulk/td-p/14096358
v1.1, 20th September 2023, Stephen Marsh
*/
#target photoshop
function main() {
// Save the current dialog display settings
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Get the selected layers: courtesy of jazz-y
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
sel = new ActionReference();
// Loop over the selected layers: courtesy of jazz-y
for (var i = 0; i < lrs.count; i++) {
sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
(r = new ActionReference()).putIdentifier(s2t('layer'), p);
(d = new ActionDescriptor()).putReference(s2t("target"), r);
executeAction(s2t('select'), d, DialogModes.NO);
// Linked SO conditional check courtesy of r-bin
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var d = executeActionGet(r);
if (d.hasKey(stringIDToTypeID("smartObject"))) {
d = d.getObjectValue(stringIDToTypeID("smartObject"));
if (d.hasKey(stringIDToTypeID("link"))) {
alert('The smart object layer "' + activeDocument.activeLayer.name + '" is linked, not embedded!');
} else {
var embeddedSOlayer = activeDocument.activeLayer.name;
// Call the new smart object via copy function: courtesy fo c.pfaffenbichler
newSmartObjectViaCopy();
//alert('The embedded smart object layer "' + embeddedSOlayer + '" has been copied!');
}
}
}
// Finish the loop
// Restore the dialogs
app.displayDialogs = savedDisplayDialogs;
}
function newSmartObjectViaCopy() {
try {
var idplacedLayerMakeCopy = stringIDToTypeID("placedLayerMakeCopy");
executeAction(idplacedLayerMakeCopy, undefined, DialogModes.NO);
return app.activeDocument.activeLayer
} catch (e) {
alert(e)
}
}
// Single history stage undo
activeDocument.suspendHistory("Selected Layers to New Smart Object via Copy.jsx", "main()");
EDIT: This version logs the linked layers that were skipped to a text file on the desktop, rather than alerting each layer:
/*
Selected Layers to New Smart Object via Copy.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/is-there-a-way-to-use-quot-new-smart-object-via-copy-quot-in-bulk/td-p/14096358
v1.2, 27th December 2023, Stephen Marsh
*/
#target photoshop
function main() {
// Save the current dialog display settings
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Log file setup
var logFile = new File("~/Desktop/Selected Layers to New Smart Object via Copy LOG.txt");
if (logFile.exists);
logFile.remove();
var os = $.os.toLowerCase().indexOf("mac") >= 0 ? "mac" : "windows";
if (os === "mac") {
logFileLF = "Unix";
} else {
logFileLF = "Windows";
}
var dateTime = new Date().toLocaleString();
logFile.open("w");
logFile.encoding = "UTF-8";
logFile.lineFeed = logFileLF;
logFile.write(dateTime + "\r" + "Document name: " + activeDocument.name + "\r" + "The following layers are linked and therefore skipped:" + "\r\r");
logFile.close();
// Get the selected layers: courtesy of jazz-y
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
sel = new ActionReference();
// Loop over the selected layers: courtesy of jazz-y
for (var i = 0; i < lrs.count; i++) {
sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
(r = new ActionReference()).putIdentifier(s2t('layer'), p);
(d = new ActionDescriptor()).putReference(s2t("target"), r);
executeAction(s2t('select'), d, DialogModes.NO);
// Linked SO conditional check courtesy of r-bin
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var d = executeActionGet(r);
if (d.hasKey(stringIDToTypeID("smartObject"))) {
d = d.getObjectValue(stringIDToTypeID("smartObject"));
if (d.hasKey(stringIDToTypeID("link"))) {
// Log the linked layers which were skipped
writeToLog();
} else {
var embeddedSOlayer = activeDocument.activeLayer.name;
// Call the new smart object via copy function: courtesy fo c.pfaffenbichler
newSmartObjectViaCopy();
}
}
}
// Finish the loop
// Restore the dialogs
app.displayDialogs = savedDisplayDialogs;
// Open the log file
logFile.execute();
///// FUNCTIONS /////
function writeToLog() {
logFile.open("a");
logFile.encoding = "UTF-8";
logFile.lineFeed = logFileLF;
logFile.write(activeDocument.activeLayer.name + "\r");
logFile.close();
}
function newSmartObjectViaCopy() {
try {
var idplacedLayerMakeCopy = stringIDToTypeID("placedLayerMakeCopy");
executeAction(idplacedLayerMakeCopy, undefined, DialogModes.NO);
return app.activeDocument.activeLayer;
} catch (e) {
alert(e);
}
}
}
// Single history stage undo
activeDocument.suspendHistory("Selected Layers to New Smart Object via Copy.jsx", "main()");
Copy link to clipboard
Copied
Very industrious!
Now it would be interesting to know what the original poster actually intended.
Copy link to clipboard
Copied
Very industrious!
Now it would be interesting to know what the original poster actually intended.
By @c.pfaffenbichler
I had fun anyway!
Copy link to clipboard
Copied
This exactly what i meant! Thank you very much 🙂