script to generate a setup of layers in indesign
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
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
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?
Copy link to clipboard
Copied
Is there a way to tell InDesign the color of the layer?
Copy link to clipboard
Copied
Hi,
Can you post a screen shot of the code and the error?
Regards
Malcolm
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 )
Copy link to clipboard
Copied
Hast du auch eine Lösung für das oben abgebildete Applescript? Das wäre der Hammer.
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
Copy link to clipboard
Copied
Bei AppleScript muss ich leider passen.
Nicht meine Baustelle…
Gruß,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
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

