Hi all-
I have a script that runs on layer 1 or the first layer in the pallet in Illustrator. Currently I have to have the script run and unLock ALL the layers and Sub-Layers. When I try to have it only unLock the first layer / Layer 1 in Illustrator it gives me an error: “Target Layer Cannot be Modified”. What am I doing wrong??? Any help? Here is the code I am using…
Works but unLocks All layers and SubLayers:
tell application "Illustrator CS"
activate
set user interaction level to never interact --turns off the majority of dialogs
set theImage to open aFile --open and process one of the files
set thisDoc to current document
--Begin Unlock of Layers and Sub-Layers
set tLayers to name of every layer of thisDoc
tell thisDoc
repeat with i from 1 to (count tLayers)
set locked of layer (item i of tLayers) to false
try -- if layers or items are not unlocking try commenting out the try and end try statements to find out what the errors are.
set sLayers to every layer of layer (item i of tLayers)
repeat with aSLayer in sLayers
--set visible of aSLayer to true --makes every layer item visible
set locked of aSLayer to false
set locked of every page item of aSLayer to false -- I added the try statement above because if there are no page items in the sub-layer the code will error.
end repeat
end try
end repeat
end tell
--END Unlock of Layers and Sub-layers
--Unlock all objects on the page
try
set (locked of every page item of thisDoc whose locked is true) to false
end try
--End Unlock all objects
--Remove Stray points & empty Text boxes from the sub-layers
set strayPts to (every path item of thisDoc whose width is 0 and height is 0)
set emptyText to (every text frame of thisDoc whose contents is "" or contents is " " or contents is (tab as text) or contents is (return as text))
set deleteItems to strayPts & emptyText
delete deleteItems
--END Remove Stray Points and empty text boxes
This script gives me the error! Any help? Is there a better way?
tell application "Illustrator CS"
activate
set user interaction level to never interact --turns off the majority of dialogs
set theImage to open aFile --open and process one of the files
set thisDoc to current document
--Begin Unlock of Layers and Sub-Layers
try
set locked of layer 1 to false
end try
--set tLayers to name of every layer of thisDoc
--tell thisDoc
-- repeat with i from 1 to (count tLayers)
-- set locked of layer (item i of tLayers) to false
-- end repeat
--end tell
--END Unlock of Layers and Sub-layers
--Unlock all objects on the page
try
set (locked of every page item of thisDoc whose locked is true) to false
end try
--End Unlock all objects
--Remove Stray points & empty Text boxes from the sub-layers
set strayPts to (every path item of thisDoc whose width is 0 and height is 0)
set emptyText to (every text frame of thisDoc whose contents is "" or contents is " " or contents is (tab as text) or contents is (return as text))
set deleteItems to strayPts & emptyText
delete deleteItems
--END Remove Stray Points and empty text boxes
mamba