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

Merge all layers with the same prefix

New Here ,
Sep 15, 2017 Sep 15, 2017

Copy link to clipboard

Copied

I am trying to figure out how to merge all layers with the same prefix and then use the prefix to name the new combined layer

The example would be as follows. An INDD file contains the following layers

  • FPO layer 1
  • FPO layer 2
  • SHELL random naming
  • SHELL another random name
  • SHELL A 3rd random name
  • Another Layers
  • More Layers

Upon running the script a dialog would ask me for a Prefix word, in this case i would type 'SHELL' and hit ok

the resulting layers would look as follows

  • FPO layer 1
  • FPO layer 2
  • SHELL
  • Another Layers
  • More Layers

Any help with this would be much appreciated!

Thanks

TOPICS
Scripting

Views

1.6K

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

Enthusiast , Sep 15, 2017 Sep 15, 2017

Here is a sample of layer merge in AppleScript

tell application "Adobe InDesign CC 2017"

  tell document 1

  set layerList to layers whose name begins with "SHELL"

  end tell

  if length of layerList > 1 then

  set mergeLayer to item 1 of layerList

  set remainingLayers to rest of layerList

  tell mergeLayer to merge with remainingLayers

  end if

end tell

and in ExtendScript:

var selArr = [];

var testit;

var layerName;

var docRef = app.documents[0];

var layerArr = docRef.layers.everyItem().name;

for (i = 0; i <

...

Votes

Translate

Translate
Enthusiast ,
Sep 15, 2017 Sep 15, 2017

Copy link to clipboard

Copied

Here is a sample of layer merge in AppleScript

tell application "Adobe InDesign CC 2017"

  tell document 1

  set layerList to layers whose name begins with "SHELL"

  end tell

  if length of layerList > 1 then

  set mergeLayer to item 1 of layerList

  set remainingLayers to rest of layerList

  tell mergeLayer to merge with remainingLayers

  end if

end tell

and in ExtendScript:

var selArr = [];

var testit;

var layerName;

var docRef = app.documents[0];

var layerArr = docRef.layers.everyItem().name;

for (i = 0; i < layerArr.length; i++) {

testit = layerArr.substr(0,5);

if (testit == "SHELL") {

     layerName = layerArr;

     selArr.push(docRef.layers.item(layerName));

  }

}

var mergeLayer = selArr.shift();

mergeLayer.merge(selArr);

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 ,
Sep 18, 2017 Sep 18, 2017

Copy link to clipboard

Copied

This is amazing, thankyou!

one final thing... if i wanted the final layer to end up as the word 'SHELL' how would i incorporate this into the ExtendScript. I believe by modifying the AppleScript as shown below i should get the result i am looking for, but i am not sure on the ExtendScript

tell application "Adobe InDesign CC 2017"

  tell document 1

  set layerList to layers whose name begins with "SHELL"

  end tell

  if length of layerList > 1 then

  set mergeLayer to item 1 of layerList

  set remainingLayers to rest of layerList

  tell mergeLayer to merge with remainingLayers

  set the name of mergeLayer to "SHELL"

  end if

end tell

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
Explorer ,
Mar 02, 2019 Mar 02, 2019

Copy link to clipboard

Copied

hi,

how do i make the search case insensitive? I tried the \regex\ construct. It doesn't work.

Shell, shell, etc

var selArr = [];

var testit;

var layerName;

var docRef = app.documents[0];

var layerArr = docRef.layers.everyItem().name;

for (i = 0; i < layerArr.length; i++) {

testit = layerArr.substr(0,5);

if (testit == "SHELL") {

     layerName = layerArr;

     selArr.push(docRef.layers.item(layerName));

  }

}

var mergeLayer = selArr.shift();

mergeLayer.merge(selArr);

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 02, 2019 Mar 02, 2019

Copy link to clipboard

Copied

You could convert the string being matched to lowercase and then match it with a lowercase representation of the search string. Like below

if (testit.toLowerCase() == "shell")

Or you could use the regex with case insensitive flag. Like below

if (testit.match(/shell/i))

-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
Explorer ,
Mar 02, 2019 Mar 02, 2019

Copy link to clipboard

Copied

LATEST

thank you Manan!

didn't know the syntax. It's perfect!

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