Copy link to clipboard
Copied
I sometimes like to have an action lay down some variations + Layer Comps.
I flip through the Comps and when I've made my choice, I want to delete those temporary, say, last 2 to 5 Comps.
Is this possible with a script where I specify the amount of Comps to delete from the bottom?
After I decided on my favorite, I don't need any of the Comps anymore, and I can handle the rest with the action. Would just like a few scripts that "Delete 2 Last Comps", 3, 4, 5.
As they always seem to be added on the bottom, I'm hoping it's not elusive to do this...
Until now, I've always deleted the whole lot – but that's not professional... 😉
while((lCs = (aD = activeDocument).layerComps).length &&
(lC = lCs[lCs.length - 1]).name.split(/^TMP_/)[1]) lC.remove()
Copy link to clipboard
Copied
In this simple example, I can let the action do the cleanup of the Comps too. But it's messier and more work than calling a script to "Delete last 3 Comps." It feels safer to me too (while it may not be...).
Copy link to clipboard
Copied
"My action removes Red and Blue layer."
> Correction: a script does that. It keeps the selected layer and throws away the rest (all three are inside a Group, but I kept it simple here).
Copy link to clipboard
Copied
app.activeDocument.layerComps.removeAll();
Do you need this?
Copy link to clipboard
Copied
I probably got that out of a PDF... 😉
That's what I've been using.
But it doesn't respect what was already there. That's what I now wanna improve on.
Copy link to clipboard
Copied
It is probably easier to create temporary LayerComps with a fixed or standard name, for example, TMP or TMP1, TMP2, etc., perhaps using a script (or action), and then delete these temporary LayerComps based on the name.
Copy link to clipboard
Copied
I have this idea often but never tried it.
I would wanna keep meaningful names though, so I'm usually wondering if I can delete layers based on a prepended code.
For example, ...
tmp_ Meaningful description 1
tmp_ Meaningful description 2
tmp_ Meaningful description 3
Then delete all Comps starting with tmp_
Copy link to clipboard
Copied
I then wouldn't need the DUMMY Comp and it would be a touch less hardcoded (just the 'tmp_')
Copy link to clipboard
Copied
The right prepended characters could even help to make the new Comps stand out nicely, so I guess it is the better solution. My mistake to not think of it from the start...
Copy link to clipboard
Copied
while((lCs = (aD = activeDocument).layerComps).length &&
(lC = lCs[lCs.length - 1]).name.split(/^TMP_/)[1]) lC.remove()
Copy link to clipboard
Copied
A great combined effort...!
Signfeld: awesome ideas 😜
r-bin: wise solutions
Kukurykus: immaculate finisher 😉
Thank You Script Team!
Copy link to clipboard
Copied
(1) Your code did exactly what I needed at the time: it deletes Layer Comps prepended with "– ", but only from the bottom up.
As it doesn't work to remove any prepended LC, I've been trying to rewrite it using a "for" loop structure, but I'm ashamed to always get errors...
(Help 😛 )
I want removed: – LC 3, – LC 6, – LC 4
UPDATE.: Figured it out, I think...
var doc = app.activeDocument;
for(i = doc.layerComps.length-1; i >= 0 ; i--){
if( doc.layerComps[i].name.split(/^– /)[1] ){
doc.layerComps[i].remove();
}
}
(2) Also, to execute "next Layer Comp," it works using Script Listener code or xtools "action to script," but is that the fastest way? (This doesn't have to fly of course; just wondering if there is shorter code that is not 50ms slower.)
Copy link to clipboard
Copied