I am working on a script to make change the visibility of some layers in a book. At this moment I am stuck with a array problem, I think.
A little bit expiation: a document has several layers, including 3 Price layers. I want to make all layers visible except the prices I won’t publish (so two layers has to be invisible).
this is what I get at this moment:
tell application "Adobe InDesign CS5.5"
activate
if active book exists then
else
set GetParentPath to ((choose file with prompt "Kies een Indesignbook:" of type "IDb5.5"))
open GetParentPath
delay 1
end if
end tell
tell application "Adobe InDesign CS5.5"
tell active book
set fileList to full name of book contents
end tell
--general
set CountryArray to {"BE", "FR", "NL", "EX", "DE"}
set CountryID to choose from list CountryArray with prompt "Selecteer de juiste catalogus prijzen." OK button name "Update book" without multiple selections allowed
--make all layers visible
repeat with aFile in fileList
set theDoc to open aFile
set myDocument to active document
tell myDocument
set AllLayers to every layer
repeat with thisLayer in AllLayers
set visible of thisLayer to true
end repeat
end tell
--make 1 Price layer visible
if CountryID is false then return
set Country to characters 1 thru 2 of item 1 of CountryID as string
set ActivateLayer to "Prijzen " & Country & ""
set DeactivateLayer to "Prijzen " & Country & ""
close theDoc saving yes
end repeat
end tell
My problem is that I can’t make the layers of the other prices invisible. I don’t know how I can call the other items of the array.
Hi. I’ve written an example of how to work with this property. You may want to revisit your code and incorporate one or more of these lines.
tell application "InDesign CS"'s document 1
set layers's visible to true --the visibility property is enabled for every layer
set layer "whatever"'s visible to false --the visibility property is disabled for a named layer
tell layer "whatever" to set visible to not (its visible) --the visibility property is toggled for a named layer
--disable chosen layer from list
set layer ((choose from list {"BE", "FR", "NL", "EX", "DE"})'s item 1)'s visible to false--item 1 refers to the string value inside the returned list, not the first item in the list as a whole
end tell
tell application "Adobe InDesign CS5"
activate
if active book exists then
else
set GetParentPath to ((choose file with prompt "Kies een Indesignbook:" of type "IDb5.5"))
open GetParentPath
delay 1
end if
end tell
tell application "Adobe InDesign CS5"
tell active book
set fileList to full name of book contents
end tell
--general
set CountryArray to {"BE", "FR", "NL", "EX", "DE", "NO"}
set CountryID to choose from list CountryArray with prompt "Selecteer de juiste catalogus prijzen." OK button name "Update book" without multiple selections allowed
--make all layers visible
repeat with aFile in fileList
set theDoc to open aFile
set myDocument to active document
tell myDocument
set AllLayers to every layer
repeat with thisLayer in AllLayers
set visible of thisLayer to true
end repeat
--make 1 Price layer visible
if CountryID is false then return
set Country to characters 1 thru 2 of item 1 of CountryID as string
set ActiveLayer to (Country & " prices")
set DeactivateLayer to {}
repeat with x from 1 to count of CountryArray
set i to item x of CountryArray as string
if i is Country then
else
set thisLayer to (i & " prices")
try
set visible of layer thisLayer to false
end try
end if
end repeat
end tell
close theDoc saving yes
end repeat
end tell
I don’t know if it is the wright thing write the script, but it works…
If there is a better way, please tell me :-)[center][/center]
Good catch. I didn’t consider the button. The choose from list structure resists functional attempts at single line reduction, as the result is not immediately realized; something either has to be trapped, coerced, or checked against a boolean.
This could be done more sensibly, but I stumbled upon this variation of the offset syntax and thought it was interesting; it’s practically inscrutable. :lol:
tell application "InDesign CS"'s document 1
(choose from list {"Layer 1", "Layer 2"})
if (offset in result without of) = 0 then set layer (result as string)'s visible to false
end tell
Evisita,
The segment make all layers visible can be shortened, as no loop is required. See the first line of my first post’s example. The general and make 1 Price layer visible segments can be combined and shortened. You have a couple references in there that aren’t doing anything at all. You also disallowed multiple selections, so the repeat in that part is unnecessary.
tell application "InDesign CS"'s document 1
set CountryID to (choose from list {"BE", "FR", "NL", "EX", "DE", "NO"} with prompt "Selecteer de juiste catalogus prijzen." OK button name "Update book" without multiple selections allowed)
if CountryID ≠false then set layer (CountryID as string)'s visible to false
end tell