• 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.8K

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
LEGEND ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Can you first use my code? I mean select the last layerComp you want to be kept (so most bottom of those you had before adding temporary ones) and then run the script please 😉

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 forgot I can select the last one by action.

But do you leave the ones that were already there?

I'll test it...

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

Cool, that works! 🙂

 

But then I need another script, I think ...?

 

"If there are any Layer Comps already, select the bottom one"

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

 

if (lngth = (lCs = (aD = activeDocument).layerComps).length)
	aHS = aD.activeHistoryState, lCs[lngth - 1].remove(),
	aD.activeHistoryState = aHS

 

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!

I just discovered I need the Temp DUMMY Comp anyway, cos after I ended on some favorite new Comp, I have to select the original bottom layer right before running your winning script. That is easy by applying the DUMMY via action.

Now, I was surprised that even though I had not checkmarked anything to save in the Comp, it changes my layers (hides new ones). I can either fix that in the action, but I think ideally I'd like to update the DUMMY Layer Comp by name.

So after my favorite Comp is selected and I Continue the script, I need ...

Temp DUMMY Comp.update; (recapture?)

so it doesn't change visibility when I apply it (to have it selected before your script)...

Is that a last favor you can perform?  😛

 

Is it the .recapture?
LayerComp

 

So I can often find the keywords, but then I lose hours figuring out how to use them...

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

Better if you post screenshots...

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's say this is my favorite Comp.

I now am gonna apply the 'Temp Dummy Comp' to indicate up to where your script can delete (later I delete the DUMMY too).

But applying the DUMMY changes visibility in my layers (and action can't select it; maybe a script can?).

So can I first update (recapture) the DUMMY, like simply by name?

[pseudo code] getByName.layerComp("DUMMY").recapture;

 

Or does this have to go by Layer Comp index and opening up the next rabbit hole? (for me)

(again, if I can just select it by script, I think that solves it too) 

 

Photoshop_l75AyifZkd.jpg

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 don't have to create temporary layer comp by your action. Just as last step of it record to the extra script I wrote. It is going to remove bottom unselected layer comp to select it without applying by retrieving saved earlier history state. Then you run my main script, and that is all.

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

It's just deleting like one Comp now.

It's unclear where I have to put the latest one...

We are using ONLY two pieces of script you gave, right? (and I have to add no history state, etc.?)

 

Don't I have to use your latest script like right before I start creating my 5 LayerComps?

Or right before the main script?  (can it be in the same file?)

 

You are outclevering me again — which is too easy for you... 😜

 

We could resume tomorrow and I can think more about what it's doing first.

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 26, 2021 May 26, 2021

Copy link to clipboard

Copied

You're right, I didn't think much of this, so here is the correct code as one script:

 

lCs = (aD = activeDocument).layerComps
cmps = [].slice.call(lCs); while((lngth = lCs.length)
&& (lC = cmps.pop()).name != 'Temp DUMMY Comp')
	lC.remove(); lngth && 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 26, 2021 May 26, 2021

Copy link to clipboard

Copied

That works perfectly 🙂

No DUMMY there!  😉

Phew & 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 26, 2021 May 26, 2021

Copy link to clipboard

Copied

No dummy? There is one. Ah wait, yes, it removes dummy layer comp.

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

As far as I can see, the last script is a trick to have the last Comp selected? 🙂

 

But my action does a bunch after that.

How can your main script know what the previous bottom Comp was?

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

"As far as I can see, the last script is a trick to have the last Comp selected? "

> Hm, maybe not, as it doesn't become highlighted at least...

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

Yes I do 🙂

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 must say to script (by selection I suggested) which is the last one that is important for you."

> That system is great (just one or two scripts needed, and not one for every amount.

Good that you optionally can select the last Comp that is important.

But in my case, it doesn't matter.

Please have the last one selected by a script I use at the start of the action, if you can...?

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

Maybe I can find that myself from what you supplied earlier...; in a day or two 😜

( select length-1 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
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Ok, I realized I can solve that in the action by creating a DUMMY Layer Comp 🙂

 

Thank you for your patience and intelligent code! 🙂

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
Valorous Hero ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Who said the last one on the list is the most recent? 🙂

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 don't know if it is so on the inside...

 

I am just assuming since I'm removing them very soon after I created them... (and visually they always seem to add on to the bottom).

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

Yes, it confused me, but I believed that is mistake in 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
Valorous Hero ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

If you had read Photoshop JavaScript Ref.pdf at least once, there would have been no questions.
 
 
 

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

That's possible, but then forums should not exist maybe.

That is some pretty "boring stuff" and I always end up having to search the net to see an example I understand..

I do always consult the two 2 pdfs but I'm not familiar with methods by just seeing keywords...

The pdfs hardly have an example in them.

I just need small bits usually, but less obvious ones on many occasions.

More to follow... 😉

I am someone that hates asking and have usually spent half the day (or even years) on it already... 😉

I'm now just asking a bunch in a row, so I am done.

Well, I guess it never stops.... 😜

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

I agree, Adobe docs is unfriendly for beginners, especially those with no coding experience.

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

Visual example ...

An action makes 3 layers: R, G, B

I use the Layer Comps the action also made to flip through them and see what I prefer.

I decide to keep Green.  My action removes Red and Blue layer.

I now want the R, G, B Comps gone (3 last ones). They were just for flipping through the variations.

Photoshop_vMCMVBjVrL.jpg

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