Skip to main content
tokuredit
Inspiring
August 11, 2018
Answered

Select only red layers of color

  • August 11, 2018
  • 1 reply
  • 1858 views

A document has several layers with a red color and needs to select only the first (1st) in the top-down order. How to make this a reality using jsx? Thank you.

This topic has been closed for replies.
Correct answer Kukurykus

CC 2018:

function sTT(v) {return stringIDToTypeID(v)}

(ref = new ActionReference()).putEnumerated

(sTT('document'), sTT('ordinal'), sTT('targetEnum'))

nOL = executeActionGet(ref).getInteger(sTT('numberOfLayers'))

bGL = !executeActionGet(ref).getInteger(sTT('hasBackgroundLayer'))

for(i = nO - bGL; i >= 0; i--) {

     function ttS(v) {return typeIDToStringID(v) == 'red'}

     (ref = new ActionReference()).putIndex(sTT('layer'), idx = i + bGL)

     if (ttS(executeActionGet(ref).getEnumerationValue(sTT('color')))) {

          (ref1 = new ActionReference()).putIndex(sTT('layer'), idx);

          (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1)

          dsc1.putBoolean(sTT('makeVisible'), false)

          executeAction(sTT('select'), dsc1); break

     }

}

1 reply

Kukurykus
KukurykusCorrect answer
Legend
August 12, 2018

CC 2018:

function sTT(v) {return stringIDToTypeID(v)}

(ref = new ActionReference()).putEnumerated

(sTT('document'), sTT('ordinal'), sTT('targetEnum'))

nOL = executeActionGet(ref).getInteger(sTT('numberOfLayers'))

bGL = !executeActionGet(ref).getInteger(sTT('hasBackgroundLayer'))

for(i = nO - bGL; i >= 0; i--) {

     function ttS(v) {return typeIDToStringID(v) == 'red'}

     (ref = new ActionReference()).putIndex(sTT('layer'), idx = i + bGL)

     if (ttS(executeActionGet(ref).getEnumerationValue(sTT('color')))) {

          (ref1 = new ActionReference()).putIndex(sTT('layer'), idx);

          (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1)

          dsc1.putBoolean(sTT('makeVisible'), false)

          executeAction(sTT('select'), dsc1); break

     }

}

tokuredit
tokureditAuthor
Inspiring
August 12, 2018

That's exactly what I was looking for! Thank you Kukurykus