Highlighted

Merge two selected layers and position the merged layer in the order of the bottom layer in the stac

Contributor ,
Nov 21, 2020

Copy link to clipboard

Copied

 

Hello everyone! The title alone says it all.
Illustration:

Capturar.PNG

How to make this possible with scripts! Thanks

Adobe Community Professional
Correct answer by Kukurykus | Adobe Community Professional
sTT = stringIDToTypeID

id = (aD = activeDocument).activeLayer.id; function slctn(v) {
	(ref = new ActionReference()).putIdentifier(sTT('layer'), id);
	(dsc = new ActionDescriptor()).putReference(sTT('null'), ref), sM = 'selectionModifier'
	dsc.putEnumerated(sTT(sM), sTT(sM + 'Type'), sTT(v + 'Selection')), executeAction(sTT('select'), dsc)
}

slctn('removeFrom'), nme1 = aD.activeLayer.name;

(ref = new ActionReference()).putProperty(sTT('property'), tL = sTT('targetLayers'))
ref.putEnumerated(sTT('document'), sTT('ordinal'), sTT('targetEnum'));
indx = (executeActionGet(ref).getList(tL)).getReference(0).getIndex();

(ref1 = new ActionReference()).putIdentifier(sTT('layer'), id);
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref1);
(ref2 = new ActionReference()).putIndex(sTT('layer'), indx + 1)
dsc.putReference(sTT('to'), ref2), executeAction(sTT('move'), dsc)

slctn('addTo'), runMenuItem(sTT('newPlacedLayer'))
nme2 = (lyr = aD.activeLayer).name, lyr.name = nme1 + '-' + nme2
TOPICS
Actions and scripting

Views

54

Likes

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

Merge two selected layers and position the merged layer in the order of the bottom layer in the stac

Contributor ,
Nov 21, 2020

Copy link to clipboard

Copied

 

Hello everyone! The title alone says it all.
Illustration:

Capturar.PNG

How to make this possible with scripts! Thanks

Adobe Community Professional
Correct answer by Kukurykus | Adobe Community Professional
sTT = stringIDToTypeID

id = (aD = activeDocument).activeLayer.id; function slctn(v) {
	(ref = new ActionReference()).putIdentifier(sTT('layer'), id);
	(dsc = new ActionDescriptor()).putReference(sTT('null'), ref), sM = 'selectionModifier'
	dsc.putEnumerated(sTT(sM), sTT(sM + 'Type'), sTT(v + 'Selection')), executeAction(sTT('select'), dsc)
}

slctn('removeFrom'), nme1 = aD.activeLayer.name;

(ref = new ActionReference()).putProperty(sTT('property'), tL = sTT('targetLayers'))
ref.putEnumerated(sTT('document'), sTT('ordinal'), sTT('targetEnum'));
indx = (executeActionGet(ref).getList(tL)).getReference(0).getIndex();

(ref1 = new ActionReference()).putIdentifier(sTT('layer'), id);
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref1);
(ref2 = new ActionReference()).putIndex(sTT('layer'), indx + 1)
dsc.putReference(sTT('to'), ref2), executeAction(sTT('move'), dsc)

slctn('addTo'), runMenuItem(sTT('newPlacedLayer'))
nme2 = (lyr = aD.activeLayer).name, lyr.name = nme1 + '-' + nme2
TOPICS
Actions and scripting

Views

55

Likes

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
Nov 21, 2020 0
Most Valuable Participant ,
Nov 21, 2020

Copy link to clipboard

Copied

Or move Layer 6 above layer 3 in the layer stack then merge down.  The steps would also be like the process you show above.  The script need have some logic to know which two layer need to be merged and position in the layer stack.   If You target two layers before running your script  Your script  can get which layers are targeted and work on them. Order the top selected layer above the bottom targeted layer and merge down. Its so easy to do manually drag 6 above 3 and Ctrl+E. I do not know why you would want to script that.

 

Script and actions should be use to automated processes you do regularly. Perhaps batch process.  Having to manually target two layer then run a script is not really an automated task for it requires your interaction.

JJMack

Likes

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
Reply
Loading...
Nov 21, 2020 0
Adobe Community Professional ,
Nov 21, 2020

Copy link to clipboard

Copied

sTT = stringIDToTypeID

id = (aD = activeDocument).activeLayer.id; function slctn(v) {
	(ref = new ActionReference()).putIdentifier(sTT('layer'), id);
	(dsc = new ActionDescriptor()).putReference(sTT('null'), ref), sM = 'selectionModifier'
	dsc.putEnumerated(sTT(sM), sTT(sM + 'Type'), sTT(v + 'Selection')), executeAction(sTT('select'), dsc)
}

slctn('removeFrom'), nme1 = aD.activeLayer.name;

(ref = new ActionReference()).putProperty(sTT('property'), tL = sTT('targetLayers'))
ref.putEnumerated(sTT('document'), sTT('ordinal'), sTT('targetEnum'));
indx = (executeActionGet(ref).getList(tL)).getReference(0).getIndex();

(ref1 = new ActionReference()).putIdentifier(sTT('layer'), id);
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref1);
(ref2 = new ActionReference()).putIndex(sTT('layer'), indx + 1)
dsc.putReference(sTT('to'), ref2), executeAction(sTT('move'), dsc)

slctn('addTo'), runMenuItem(sTT('newPlacedLayer'))
nme2 = (lyr = aD.activeLayer).name, lyr.name = nme1 + '-' + nme2

Likes

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
Reply
Loading...
Nov 21, 2020 1
Contributor ,
Nov 21, 2020

Copy link to clipboard

Copied

Uaw, what a genius! Here it works perfectly. Kukurykus thanks for sharing your knowledge

Likes

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
Reply
Loading...
Nov 21, 2020 1