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

create group from existing layers

Participant ,
Jun 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

I have 2 layers that I wish to place in a new group called DATA, they have just been linked by the follwing code and so I can learn a bit more is it better to create the group first and add layers to it or does that not matter?

activeDocument.layers['INFO'].link(activeDocument.layers['ICONS']);
TOPICS
Actions and scripting

Views

1.0K

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 2 Correct answers

LEGEND , Jun 16, 2020 Jun 16, 2020

Select both layers (to be grouped) and use this code:

 

 sTT = stringIDToTypeID;
 
(ref1 = new ActionReference()).putClass(sTT('layerSection'));
(dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);
(ref2 = new ActionReference()).putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum'))
dsc1.putReference(sTT('from'), ref2); (dsc2 = new ActionDescriptor()).putString(sTT('name'), 'DATA')
dsc1.putObject(sTT('using'), sTT('layerSection'), dsc2), executeAction(sTT('make'), dsc1)

 

Votes

Translate

Translate
LEGEND , Jun 16, 2020 Jun 16, 2020
sTT =stringIDToTypeID, dsc = new ActionDescriptor(), ref = new ActionReference()
for(i = 0; i < (a = ['INFO', 'ICONS']).length;) ref.putName(sTT('layer'), a[i++])
dsc.putReference(sTT('null'), ref), executeAction(sTT('select'), dsc)

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

Do you want to use DOM-code or AM-code? 

 

Referencing Layers by name seems a bit risky by the way. 

If you created the Layers withing the Script you may want to define them as a var right away. 

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
Participant ,
Jun 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

In all honesty I do not know the difference between the 2 types of code

The layer names will always be the same as they are created in the script

I have just found a way to create a Group (but this may not be the best method obviously)

 

 

	var docRef = app.activeDocument;
	var newGroup = docRef.layerSets.add();
	newGroup.name = "DATA";

 

so if I add that early enough I can use the following to add the layers to the group using after each new layer

 

activeDocument.activeLayer.move(docRef.layerSets["DATA"], ElementPlacement.INSIDE);

 


but when I try to run this I get an error

 

	activeDocument.layers['INFO'].link(activeDocument.layers['ICONS']);

 



 

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 ,
Jun 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

lrs = (aD = activeDocument).layers
inf = lrs['INFO'], icns = lrs['ICONS']

//	use here code to move layers to layerSet

inf.link(icns)

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
Participant ,
Jun 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

That linked the layers fine.

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 ,
Jun 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

Select both layers (to be grouped) and use this code:

 

 sTT = stringIDToTypeID;
 
(ref1 = new ActionReference()).putClass(sTT('layerSection'));
(dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);
(ref2 = new ActionReference()).putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum'))
dsc1.putReference(sTT('from'), ref2); (dsc2 = new ActionDescriptor()).putString(sTT('name'), 'DATA')
dsc1.putObject(sTT('using'), sTT('layerSection'), dsc2), executeAction(sTT('make'), dsc1)

 

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
Participant ,
Jun 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

This created the new group above existing layers but only put the top layer in the group.

Mike

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 ,
Jun 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

Did you select both layers like I said?

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
Participant ,
Jun 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

No, my bad, something else I need to learn how to do

Mike

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 ,
Jun 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

sTT =stringIDToTypeID, dsc = new ActionDescriptor(), ref = new ActionReference()
for(i = 0; i < (a = ['INFO', 'ICONS']).length;) ref.putName(sTT('layer'), a[i++])
dsc.putReference(sTT('null'), ref), executeAction(sTT('select'), dsc)

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
Participant ,
Jun 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

LATEST

I think I will be owing you a few beers at this rate, runs very nicely

Many

 

thanks

Mike

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