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

Select layer group below the currently selected group

Engaged ,
Aug 09, 2022 Aug 09, 2022

Copy link to clipboard

Copied

Dear @Manan Joshi is it possible to make similar thing with a group of layers instead of single layer. To be more precise i need to select group of layers bellow currently selected group? Thanks in advance

TOPICS
Actions and scripting

Views

373

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

Community Expert , Aug 16, 2022 Aug 16, 2022

So you mean that the code should not look for groups inside the currently selected group but outside that? Try the following version

var s2t = stringIDToTypeID;
var t2s = typeIDToStringID;

function getProperty(className, property, index)
{
	var r = new ActionReference(), p = s2t(property)
	r.putProperty(s2t('property'), p)
	if(index != undefined)
		r.putIndex(s2t(className),index)
	else
		r.putEnumerated(s2t(className), s2t('ordinal'), s2t('targetEnum'))
	var a = executeActionGet(r)
	return a
}
...

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

Hi @milevic,

Give the following code a try. When run with a group selected in the layers panel, it will search for the next group under it and select it if found

var s2t = stringIDToTypeID;
var t2s = typeIDToStringID;

function getProperty(className, property, index)
{
	var r = new ActionReference(), p = s2t(property)
	r.putProperty(s2t('property'), p)
	if(index != undefined)
		r.putIndex(s2t(className),index)
	else
		r.putEnumerated(s2t(className), s2t('ordinal'), s2t('targetEnum'))
	var a = executeActionGet(r)
	return a
}

function isGroup(layerIdx){
	var r 
	if(layerIdx !== null)
		r = t2s(getProperty("layer", "layerSection", layerIdx).getEnumerationValue(s2t("layerSection")))
	else
		r = t2s(getProperty("layer", "layerSection").getEnumerationValue(s2t("layerSection")))
		
	return r === "layerSectionStart"
}

function selectGroup(layerName, layerID) {
    var idselect = stringIDToTypeID("select");
    var desc25 = new ActionDescriptor();
    var idnull = stringIDToTypeID("null");
    var ref11 = new ActionReference();
    var idlayer = stringIDToTypeID("layer");
    ref11.putName(idlayer, layerName);
    desc25.putReference(idnull, ref11);
    var idmakeVisible = stringIDToTypeID("makeVisible");
    desc25.putBoolean(idmakeVisible, false);
    var idlayerID = stringIDToTypeID("layerID");
    var list5 = new ActionList();
    list5.putInteger(layerID);
    desc25.putList(idlayerID, list5);
    executeAction(idselect, desc25, DialogModes.NO);
}

var layerIdx = activeDocument.activeLayer.itemIndex
var bgLayer = getProperty("document", "hasBackgroundLayer").getBoolean(s2t("hasBackgroundLayer")) ? 0 : 1
!bgLayer && layerIdx--
if(isGroup())
{
	r = isGroup(--layerIdx)
	while(!r && layerIdx > bgLayer){
		r = isGroup(--layerIdx)
	}

	if(isGroup(layerIdx)){
		var n = getProperty("layer", "name", layerIdx).getString(s2t("name"))
		selectGroup(n, layerIdx)
	}
}

-Manan

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
Engaged ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

Thanks for the answering, i tested the script but a problem appears if the selected folder contains subfolders, is it possible to improve this?

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
Community Expert ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

So you mean that the code should not look for groups inside the currently selected group but outside that? Try the following version

var s2t = stringIDToTypeID;
var t2s = typeIDToStringID;

function getProperty(className, property, index)
{
	var r = new ActionReference(), p = s2t(property)
	r.putProperty(s2t('property'), p)
	if(index != undefined)
		r.putIndex(s2t(className),index)
	else
		r.putEnumerated(s2t(className), s2t('ordinal'), s2t('targetEnum'))
	var a = executeActionGet(r)
	return a
}

function isGroup(layerIdx){
	var r 
	if(layerIdx !== null)
		r = t2s(getProperty("layer", "layerSection", layerIdx).getEnumerationValue(s2t("layerSection")))
	else
		r = t2s(getProperty("layer", "layerSection").getEnumerationValue(s2t("layerSection")))
		
	return r === "layerSectionStart"
}

function movetoEnd(grpIdx){
	var r = t2s(getProperty("layer", "layerSection", grpIdx).getEnumerationValue(s2t("layerSection")))
	while(r !== "layerSectionEnd")
		r = t2s(getProperty("layer", "layerSection", --grpIdx).getEnumerationValue(s2t("layerSection")))
		
	return grpIdx
}

function selectGroup(layerName, layerID) {
    var idselect = stringIDToTypeID("select");
    var desc25 = new ActionDescriptor();
    var idnull = stringIDToTypeID("null");
    var ref11 = new ActionReference();
    var idlayer = stringIDToTypeID("layer");
    ref11.putName(idlayer, layerName);
    desc25.putReference(idnull, ref11);
    var idmakeVisible = stringIDToTypeID("makeVisible");
    desc25.putBoolean(idmakeVisible, false);
    var idlayerID = stringIDToTypeID("layerID");
    var list5 = new ActionList();
    list5.putInteger(layerID);
    desc25.putList(idlayerID, list5);
    executeAction(idselect, desc25, DialogModes.NO);
}

var layerIdx = activeDocument.activeLayer.itemIndex
var bgLayer = getProperty("document", "hasBackgroundLayer").getBoolean(s2t("hasBackgroundLayer")) ? 0 : 1
!bgLayer && layerIdx--
if(isGroup())
{
	layerIdx = movetoEnd(layerIdx)
	r = isGroup(--layerIdx)
	while(!r && layerIdx > bgLayer){
		r = isGroup(--layerIdx)
	}

	if(isGroup(layerIdx)){
		var n = getProperty("layer", "name", layerIdx).getString(s2t("name"))
		selectGroup(n, layerIdx)
	}
}

-Manan

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
Engaged ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

that is it, thanks a lot

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
Community Expert ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

Great news, I have started adding scripts I create on the forum to a Github repo.

Repo URL :- https://github.com/Manan-Joshi/Photoshop-Scripts

Script URL :- https://github.com/Manan-Joshi/Photoshop-Scripts/blob/master/GroupSelect.jsx

-Manan

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
Engaged ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

That is great. well done

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
New Here ,
Mar 15, 2024 Mar 15, 2024

Copy link to clipboard

Copied

Hi Manan,

Im sorry to bring that topic to life after very long time. But i have a question? Can we change this script to backwards?

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
Community Expert ,
Mar 15, 2024 Mar 15, 2024

Copy link to clipboard

Copied

@burk13 

 

Simply change all four decrement occurrences to increment.

 

From:

 

--

 

To:

 

++

 

 

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
New Here ,
Mar 18, 2024 Mar 18, 2024

Copy link to clipboard

Copied

LATEST

@Stephen_A_Marsh very appreciated, thank you.

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