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

Changing layer names with a script in InDesign or Applescript

Community Beginner ,
Nov 03, 2016 Nov 03, 2016

Copy link to clipboard

Copied

Hello...

First time posting in this forum, I can't seem to find an answer to this problem I'm having in any forums here and elsewhere. I have the plug-in InData that I import from an excel text file into a prototype in an InDesign document that I use daily. I have created layers for different "backs" that I keep static (except for the text I import). The  problem I'm running into is that I don't know how to change the layer names except to manually change them. Is there a script that will change the form numbers automatically? The form number the layers need to be is actually in the text file that I import. Maybe in Applescript somehow to script change layer 1 to layer 15... (or any number.. to form 1234 to 5678...   Any help would be greatly appreciated. InDesign CS6 v8.0.. Thank you!Screen Shot 2016-11-03 at 3.34.16 PM.png

Views

2.4K

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 ,
Nov 03, 2016 Nov 03, 2016

Copy link to clipboard

Copied

Hi,

Are you able to extract a concordance list as, e.g.:

Layer_1 >> Layer_12

Layer_2 >> Layer_23

Layer_3 >> Layer_39

…

(^/)

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 ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

Could you be clearer ? Not sure I get the idea here.

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
Guide ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

Hi

Can you be clearer about what you want to achieve, especially why you need so many different layers?

If there is no specific reason to have that huge amount of layers, maybe you could use another import method, such as "merging data"?

Merge data to create form letters, envelopes, or mailing labels in Adobe InDesign

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 Beginner ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

I need the layers as I copy & paste into many documents that utilize my end product. I use the "remember layers" and that is why it would be very helpful to have these layers change automatically to coincide with the list from the excel spreadsheet. This list will change with every import. I'm a newbie to scripting and find these forums very helpful but have no idea how to get it to work. I apologize for the confusion.

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 ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

It's easy to rename layers via scripting, but as Obi suggests you would need to feed a script the names. So this AppleScript asks for a comma delimited list:

Screen Shot 2016-11-04 at 7.49.01 AM.png

Renames the layers top to bottom:

Screen Shot 2016-11-04 at 7.49.13 AM.png

-------------------------------------------------

tell application "Adobe InDesign CS6"

    set {t, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {","}}

    display dialog "Layer List (comma delimited no spaces)" default answer ""

    set myList to text items of (text returned of the result)

    set AppleScript's text item delimiters to t

    set l to every layer of active document

    repeat with i from 1 to count of l

        try

            set name of item i of l to item i of myList

        end try

    end repeat

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
Community Beginner ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

I will give this a try!

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 Beginner ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

This works great, I'll just have to rework my layers to begin top to bottom as I work bottom to top. It's not perfect abut workable. Thank you!

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 ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

The script can be altered to name the layers from the bottom up:

----------------------------------------

tell application "Adobe InDesign CS6"

    set {t, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {","}}

    display dialog "Layer List (comma delimited no spaces)" default answer ""

    set myList to text items of (text returned of the result)

    set AppleScript's text item delimiters to t

    set l to every layer of active document

    set n to 1

    repeat with i from (count of l) to 1 by -1

        try

            set name of item i of l to item n of myList

            set n to n + 1

        end try

    end repeat

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
Community Beginner ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

I have added a 3rd story to my prototype with the list of form numbers that I can paste into the display dialog that pops up but how do I get a dialog box to display the list that I'm importing? The display comes up with "Layer List" but without the actual list of forms.

set myTemplate to ((path to desktop as Unicode text) & "5W National Flyerbacks:NationalBack_5W.indd")

set myData to ((path to desktop as Unicode text) & "5W National Flyerbacks:5Wbacks.txt")

tell application id "com.Adobe.InDesign"

  set user interaction level of script preferences to never interact

  set myDocument to open myTemplate

  import data from file myData into story "story 1" using prototype story "proto 1"

  import data from file myData into story "story 2" using prototype story "proto 2"

  import data from file myData into story "story 3" using prototype story "proto 3"

  display dialog "layer List"

 

  set user interaction level of script preferences to interact with all

  set myDelims to AppleScript's text item delimiters

  set AppleScript's text item delimiters to "."

  set myPath to (text item 1 of myData)

 

  tell application "Adobe InDesign CS6"

  set {t, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {","}}

  display dialog "Layer List (comma delimited no spaces)" default answer ""

  set myList to text items of (text returned of the result)

  set AppleScript's text item delimiters to t

  set l to every layer of active document

  repeat with i from 1 to count of l

  try

  set name of item i of l to item i of myList

  end try

  end repeat

  end tell

  export document 1 format PDF type to (myPath & ".pdf") without showing options

  set AppleScript's text item delimiters to myDelims

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
Community Expert ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

It isn't clear to me what you are trying to do.

Looks like the list of names you want to use as layer names is somewhere in the file 5Wbacks.txt?

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 Beginner ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

Yes, that is correct, (import for proto 3 contains only the list of form numbers) - I want to display the list of names so that I can copy and paste into the display box that changes the layer names. Then if possible delete my prototype layer from the document.

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 ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

You would have to open the text file and get the list. So this script would get the text from a file named Text.txt and display a dialog with the text:

set myText to text of (read POSIX file "/Users/username/Desktop/Text.txt")

display dialog myText

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 ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

So this would get the layer names from a text file, but a lot could go wrong—the file can't have anything other than the comma delimited list, and the path has to be exactly right.

set myData to ((path to desktop) & "5W National Flyerbacks:5Wbacks.txt") as string

set pp to (the POSIX path of myData)

set myText to text of (read POSIX file pp)

tell application "Adobe InDesign CC 2014"

    set {t, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {","}}

    set myList to text items of myText

    set AppleScript's text item delimiters to t

    set l to every layer of active document

    set n to 1

    repeat with i from (count of l) to 1 by -1

        try

            set name of item i of l to item n of myList

            set n to n + 1

        end try

    end repeat

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
Community Beginner ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

Thank you, this is not something I'm familiar with. I'll try this until I get it.. 🙂 Thanks so much for your help.

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 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

LATEST

Hi Shirley,

Thanks for your help with this script. Is there a way to select (say 75 layers) and not have to type in 75 names in to get them to change. Say, any code that will change the name and add consecutive numbers at the end of it?

Thanks,

Peter

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