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

script to generate a setup of layers in indesign

Participant ,
Sep 07, 2018 Sep 07, 2018

Copy link to clipboard

Copied

Hi, I have used a script in the past to generate a set of pre-defined layers:

for some reason if I un this AppleScript I get an error now 'Expected end of line but found identifier.' with LayerName highlighted. I can't work out why this has happened now. Can anyone help? code below.

thanks

lister

tell application "Adobe InDesign CS6"

   set LayerName to "Background"

   tell document 1

      -- Is this layer is exist ?

      try

         set myLayer to layer LayerName

         -- No? -> create it

      on error

         set myLayer to make layer with properties {name:LayerName}

      end try

   end tell

   set LayerName to "UCL Logo"

   tell document 1

      -- Is this layer is exist ?

      try

         set myLayer to layer LayerName

         -- No? -> create it

      on error

         set myLayer to make layer with properties {name:LayerName}

      end try

   end tell

   set LayerName to "Blank SRP"

   tell document 1

      -- Is this layer is exist ?

      try

         set myLayer to layer LayerName

         -- No? -> create it

      on error

         set myLayer to make layer with properties {name:LayerName}

      end try

   end tell

   set LayerName to "Cutting/Ratio Guide"

   tell document 1

      -- Is this layer is exist ?

      try

         set myLayer to layer LayerName

         -- No? -> create it

      on error

         set myLayer to make layer with properties {name:LayerName}

      end try

  

  delete layer "Layer 1"

   end tell

end

TOPICS
Scripting

Views

2.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
Community Expert ,
Sep 07, 2018 Sep 07, 2018

Copy link to clipboard

Copied

Hi,

I was able to run your script without any problems, although find a new version of your script below which uses a function to avoid any duplicate code, therefore making it easier to spot any errors.

my createNewLayerWithName("Background")

my createNewLayerWithName("UCL Logo")

my createNewLayerWithName("Blank SRP")

my createNewLayerWithName("Cutting/Ratio Guide")

tell application "Adobe InDesign CS6"

    tell document 1

        delete layer "Layer 1"

    end tell

end tell

on createNewLayerWithName(LayerName)

    tell application "Adobe InDesign CS6"

        tell document 1

            try

                set myLayer to layer LayerName

            on error

                set myLayer to make layer with properties {name:LayerName}

            end try

        end tell

    end tell

end createNewLayerWithName

Hope this helps

Malcolm

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 ,
Sep 07, 2018 Sep 07, 2018

Copy link to clipboard

Copied

Thanks for this, Im not sure what Im doing, but when open the script and try to save this (in script editor) I get a syntax error "". not sure why?

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 ,
Feb 07, 2022 Feb 07, 2022

Copy link to clipboard

Copied

Is there a way to tell InDesign the color of the layer?

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 ,
Sep 09, 2018 Sep 09, 2018

Copy link to clipboard

Copied

Hi,

Can you post a screen shot of the code and the error?

Regards

Malcolm

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 ,
Feb 07, 2022 Feb 07, 2022

Copy link to clipboard

Copied

"Is there a way to tell InDesign the color of the layer?"

 

Hi Steffen,

yes. You could use one of the pre-defined UI Colors or define your own RGB values.

With ExtendScript (JavaScript) it goes like this to assign a color:

// Recolor first layer in the active document:
app.documents[0].layers[0].layerColor = UIColors.GOLD;

 Or:

// Recolor first layer in the active document:
app.documents[0].layers[0].layerColor = [ 255 , 0 , 128 ] ;

 

See DOM documentation of the layer object and property layerColor:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Layer.html

 

Regards,
Uwe Laubender

( ACP )

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 ,
Feb 07, 2022 Feb 07, 2022

Copy link to clipboard

Copied

Hast du auch eine Lösung für das oben abgebildete Applescript? Das wäre der Hammer. 

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 ,
Feb 07, 2022 Feb 07, 2022

Copy link to clipboard

Copied

Ich habe es so probiert. Die Ebenen werden erstellt, aber nicht in der gewünschten Farbe.

my createNewLayerWithName("Produkte", "violet")
my createNewLayerWithName("Abbinder", "red")
my createNewLayerWithName("STD Kennung", "light_blue")
my createNewLayerWithName("Texte", "magenta")
my createNewLayerWithName("STD Aktion", "green")
my createNewLayerWithName("Preise alle Häuser", "black")
my createNewLayerWithName("Info Layout", "blue")
my createNewLayerWithName("Fotostudio", "blue")
my createNewLayerWithName("Bildbearbeitung", "blue")
on createNewLayerWithName(LayerName, LayColor)
	tell application "Adobe InDesign 2021"
		tell document 1
			try
				set myLayer to make layer with properties {name:LayerName, layer color:LayColor}
			end try
		end tell
	end tell
end createNewLayerWithName
tell application "Adobe InDesign 2021"
	tell document 1
		delete layer "Ebene 1"
	end tell
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 ,
Feb 07, 2022 Feb 07, 2022

Copy link to clipboard

Copied

Bei AppleScript muss ich leider passen.

Nicht meine Baustelle…

 

Gruß,
Uwe Laubender

( ACP )

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 ,
Feb 07, 2022 Feb 07, 2022

Copy link to clipboard

Copied

LATEST

Hi,

 

Applescript would be something like.

tell application "Adobe InDesign 2022"
        -- this is the code over multiple lines
	set myDoc to active document
	set myLayers to every layer of myDoc
	set layer color of item 1 of myLayers to gold
	
        -- this is the above code but on 1 line.
	set layer color of item 1 of every layer of active document to gold
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