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
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
Any help with this would be much appreciated!
Thanks
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 <
...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);
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
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);
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
Copy link to clipboard
Copied
thank you Manan!
didn't know the syntax. It's perfect!