Copy link to clipboard
Copied
Hi,
I am brand new to scripting and I've pieced together the below from other forum posts. I am trying to open all smart objects in a document and clear guides with one click (or shortcut).
It is currently working when I run it with a layer selected, but I am having trouble with how to make it run for all of the layers in the document, not just the selected/active layer. I appreciate any help or suggestions!
if (app.activeDocument.activeLayer.kind == "LayerKind.SMARTOBJECT") {
app.doAction("ClearGuides", "SmartObjects");
}
Thank you!
@EliseClaire – welcome to scripting!
Try this:
/*
Remove Guides From All Smart Object Layers.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-run-action-on-all-smart-objects/td-p/12983602
Stephen Marsh, 4th June 2022 - v1.0
*/
#target photoshop
var myDocument = app.activeDocument;
myDocument.suspendHistory("processAllSmartObjects", "processSOLayers(myDocument)");
// processSOLayers function courtesy of c.pfaffenbichler
function processSOLayers(theParent) {
...
Copy link to clipboard
Copied
layerUpdate();
function layerUpdate(){
if(documents.length > 0){
var originalDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.ERROR;
var originalRulerUnits = preferences.rulerUnits;
try{
var docRef = activeDocument;
for(var i = 0; i < docRef.artLayers.length; i++){
var LayerRef = docRef.artLayers[i];
if(LayerRef.kind == LayerKind.SMARTOBJECT){
//do stuff
}
}
preferences.rulerUnits = originalRulerUnits;
app.displayDialogs = originalDialogMode;
}
catch(e){
}
}
}
Copy link to clipboard
Copied
@EliseClaire – welcome to scripting!
Try this:
/*
Remove Guides From All Smart Object Layers.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-run-action-on-all-smart-objects/td-p/12983602
Stephen Marsh, 4th June 2022 - v1.0
*/
#target photoshop
var myDocument = app.activeDocument;
myDocument.suspendHistory("processAllSmartObjects", "processSOLayers(myDocument)");
// processSOLayers function courtesy of c.pfaffenbichler
function processSOLayers(theParent) {
// Loop over all the layers
for (var i = theParent.layers.length - 1; i >= 0; i--) {
var theLayer = theParent.layers[i];
// Apply the function to smart object layers
if (theLayer.typename === "ArtLayer") {
if (theLayer.kind === LayerKind.SMARTOBJECT) {
var theVisibility = theLayer.visible;
myDocument.activeLayer = theLayer;
// Run the function to remove guides
removeGuidesFromSOlayers();
// Reset visibility;
theLayer.visible = theVisibility;
}
// Run the function on the smart object layers inside layerSets (implied, not explicitly defined)
} else {
processSOLayers(theLayer);
}
}
return;
function removeGuidesFromSOlayers() {
app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
var idclearAllGuides = stringIDToTypeID("clearAllGuides");
executeAction(idclearAllGuides, undefined, DialogModes.NO);
activeDocument.close(SaveOptions.SAVECHANGES);
}
}
Copy link to clipboard
Copied
This worked perfectly!
I have some researching to do to fully understand how it works but I hope to get there.... Thank you so much!