• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to delete the last (recent) Layer Comps? (specify amount to a func)

Advocate ,
May 25, 2021 May 25, 2021

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... 😉

TOPICS
Actions and scripting

Views

5.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 26, 2021 May 26, 2021

 

while((lCs = (aD = activeDocument).layerComps).length &&
(lC = lCs[lCs.length - 1]).name.split(/^TMP_/)[1]) lC.remove()

 

Votes

Translate

Translate
Adobe
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

An action *does* record when you activate a Comp (not when you select, AFAIK), so in theory I might be able to do it in the action if I activate them first, but the amount of extra steps and the "jumping around" of Comps feels "messy," and depending on the situation might be error prone...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

while((lCs = activeDocument.layerComps).length > 2) lCs[lCs.length - 1].remove()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

You replied before I asked!  😉

 

I'm waiting for r-bin's faster version now... 😉

 

Seriously... Thanks again!

 

But I can't figure out how to do it in one line, if possible?

 

Why does this give an error if I wanna remove the last 3?

while( (lCs = activeDocument.layerComps).length > 0) lCs[lCs.length - 3].remove()

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Ok, I think I get why it fails..

Just have to put that line in another loop then or something...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Is it then correct answer or not?

 

Ps. if you want to remove last 3 then change 2 to 1 in my code.

 

Btw you didn't ask for fastest solution. Additionally in this case speed does no big difference.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Thanks. Still testing.

Speed is just a joke 😉

I'll be back to assign Correct asap.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

"Ps. if you want to remove last 3 then change 2 to 1 in my code."

 

> This only removed two...

I think I'm too tired to "get it" now. Seems so simple...

Testing more tomorrow.

It's good enough to assign Correct.

TYVM 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Original code already removes 3 last layerComps. The change I did, so using value one instead of two was to remove 'last 3' so 2, 3, 4 (to 5) accordingly to sense of your previous request? 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

I did this and it worked. This logic I can get too...

while( (lCs = activeDocument.layerComps).length >= 2)  lCs[lCs.length - 1].remove()

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Actually, I do NOT get that logic...  LOL

But seems I can get it to work...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Nope it removed all but one now...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

That's exactly same as you used '> 1'  instead of '>= 2', so like in the code I posted.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Origianlly you wanted to keep 1 & 2 by removing 3, 4 & 5. I'm not sure what you want now?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

I'm not sure you get what I'm asking...

If I created 5, I want a script that removes 5.

But there may be Comps I have created before that have to remain; therefore "most recent 5" (from the bottom)

 

Your code seems to function as... "Delete everything until there are only two left"

We don't know what came before and how many have to stay. Just wanna delete the most recent 5.

while((lCs = activeDocument.layerComps).length > 2) lCs[lCs.length - 1].remove()

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

My initial question meant to say I will usually put down 2 to 5 Layer Comps.

So I only need 4 scripts (DEL 2 last ones, DEL 3 last ones, DEL 4 last ones, and DEL 5 last ones)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

You mean you can have minimally 2 layerComps and maximally 5?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

So if you have 4 layerComps and then add 5th, you want the code to remove recent 5th?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

I can have any amount already there before I do my action.

 

This action wil create (for example) 5 new ones.

Very soon after I wanna delete those 5 most recent ones.

Other actions may create 2, or 3 or 4. Then I wanna delete the last 2, or 3, or 4. No more.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Then select (so no apply) the layerComp you want to be kept together with other original ones over it (which you don't have to add to selection) and then use long - awaited script:

 

while(!(lC=(lCs=activeDocument.layerComps)[lCs.length-1]).selected)lC.remove()

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Let me try...

But, I don't wanna keep *any* of the very recent Comps. They are just for quickly flipping through. I don't care to keep them; I want them gone.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

You won't keep them, just indicate to over which one the newest have to be removed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Hm, I don't think I have to try that.  You are looking too deeply into it 🙂

It's really very simple and cool (IMO).

 

Can you give a hardcoded script that deletes the 5 last Comps my action just made? (don't even think about layers and selected Comps, unless your code needs that)

If I can then changet that 5 to 4, 3 or 2, that's all I need.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

I also don't wanna make clicks or selections.

I have a Stop step in my action. When I Continue (after I made my choice of layer to keep), I want the last 5 Comps removed by a script (by pressing Continue)..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Script doesn't know which layer comps were only ones before you added another ones by your action, so you must say to script (by selection I suggested) which is the last one that is important for you. Otherwise we are going "to deeply into it" by reconstructing past events.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines