Copy link to clipboard
Copied
Hi ACP's,
This is Prem. Good day to you.
I am trying to unlock all the layers by using the below script
"set the properties of every layer to {locked:false}"
But the problem is sublayers are not unlocked.
Please help
Thanks,
Prem
Got the correct answer in applescript. Thanks to Silly-V and Loic.Aigon.
I have combined your both the scripts and putting below:
on unlockLayer(subjectLayer)
local thisSubLayer
tell application "Adobe Illustrator"
set the properties of subjectLayer to {locked:false}
if (count of layers in subjectLayer) > 0 then
repeat with i from 1 to count of layers in subjectLayer
set thisSubLayer to layer i in subjectLayer
-- set the properties of thisSubLayer to {locked:false}
my unlockLayer(thisSubLa
...Copy link to clipboard
Copied
Here is a JS approach :
var doc = app.activeDocument;
var unlockLayers = function ( layers ) {
var n = layers.length, layer;
while ( n-- ) {
layer = layers
; layer.locked = false;
layer.layers.length && unlockLayers ( layer.layers );
}
}
unlockLayers ( doc.layers );
HTH
Loic
Copy link to clipboard
Copied
Actually i need the apple script.
Copy link to clipboard
Copied
tell application "Finder"
set f to choose file
set {nExt} to ({name extension} of f)
end tell
if nExt = "jsx" then
tell application "Adobe Illustrator"
if (count of documents) > 0 then
do javascript f
end if
end tell
end if
Copy link to clipboard
Copied
prema56615405 schrieb
Actually i need the apple script.
It seems to be very hard to say: Loic.Aigon Thank You
Copy link to clipboard
Copied
pixxxel schubser He he thanks for the attention but it's been a while that I am no longer waiting for such marks of respect.
I do participate by pleasure. Once in a while, I hit one's fingers when it's all about : "give me the code now". But as I feel more and more like tilting at windmills…
Copy link to clipboard
Copied
Found the right applescript to unlock the sublayers too..
set locked of (every layer whose locked is true) to false
set locked of (every layer of every layer whose locked is true) to false
Copy link to clipboard
Copied
Thanks for this! I had written a recursive function with for loops that was stopping, but looking at your while example it made me notice my variable scope was global instead of local. Fixed that, and was able to accomplish similar results with different functionality. Also learned a bit of shorthand as well!
Below is a Javascript for alternative... still not Applescript, but I'm posting in case it helps anyone on their personal quest for recursion...
aD = app.activeDocument;
layerCount = 0;
deleteCount = 0
function lyrExplore(layers) {
//Declare the scope for these variables or otherwise they will stop looping!
var n = layers.length, curLyr;
for(var i = n - 1;i>=0;i--){
curLyr = layers;
if(curLyr.layers.length>0) lyrExplore(curLyr.layers);
if(curLyr.pageItems.length == 0 && curLyr.layers.length == 0) {curLyr.remove(); deleteCount++;}
layerCount++;
}
}
lyrExplore(aD.layers);
alert(layerCount+" Layers Processed || "+ deleteCount+ " Deleted");
Copy link to clipboard
Copied
That would not work with deeper nested layers
Copy link to clipboard
Copied
Yes. You are correct.
Do you have any solution in applescript for this?
Copy link to clipboard
Copied
Probably possible but gave it a try with no success and to be honest too time consuming. I can't think of a reason where I could prefer using Applescript over Javascript unless of course I need to drive external apps or system commands. But even them, I would use do javascript for Illustrator.
Feel free to explain me why you are such in need for an applescript
FWIW
Loic
Copy link to clipboard
Copied
One of the Creative Developer Summit attendees is an AppleScript expert! I had asked him for help, but have not yet had the chance to send him my sample code to figure out why it's not working.
Copy link to clipboard
Copied
I tried recursivity with no luck. The editor won't allow the call inside some function scope.
curious about this
Copy link to clipboard
Copied
Hi Loic.Aigon,
why not using your own suggestion? This should do the job exactly.
I don't know the AppleScript syntax, but it should be something like that pseudocode
set js to "var doc = app.activeDocument; unlockLayers ( doc.layers ); var unlockLayers = function ( layers ) {var n = layers.length, layer; while ( n-- ) { layer = layers
; layer.locked = false; layer.layers.length && unlockLayers ( layer.layers ); }};" tell application "Adobe Illustrator"
do javascript js
end tell
Have fun
Copy link to clipboard
Copied
yes that's what i offered in my second reply. But pur friend seems obssesed with applescript
Copy link to clipboard
Copied
Hey Guys! Awesome, I was able to help get this figured out with a clue from this AppleScript expert I met! Turns out, that tell block also needs to be inside the function too.
Then, I was having a personal error because I was trying to get "layer i of layers of thisLayer", while the syntax it likes is instead "layer i of thisLayer".
Have fun yall!
on unlockLayer(subjectLayer)
local thisSubLayer
tell application "Adobe Illustrator"
set the properties of subjectLayer to {locked:false}
if (count of layers in subjectLayer) > 0 then
repeat with i from 1 to count of layers in subjectLayer
set thisSubLayer to layer i in subjectLayer
-- set the properties of thisSubLayer to {locked:false}
my unlockLayer(thisSubLayer)
end repeat
end if
end tell
end unlockLayer
tell application "Adobe Illustrator"
local thisLayer, activeDoc
if (count of documents) > 0 then
set activeDoc to front document
repeat with i from 1 to count of layers of activeDoc
-- set the properties of layer i of front document to {locked:false}
set thisLayer to layer i of front document as layer
-- set the properties of thisLayer to {locked:false}
my unlockLayer(thisLayer)
end repeat
end if
end tell
Copy link to clipboard
Copied
Hi
Great ! I understand now why my recursive call didn't work. It needed the "my" command obviously. Applescriot has its own logic
Apart from that, I got an execution error at first:
But then I commented out "as layer" like this
set thisLayer to layer i of front document --as layer
And it ended working.
Good work
Copy link to clipboard
Copied
Got the correct answer in applescript. Thanks to Silly-V and Loic.Aigon.
I have combined your both the scripts and putting below:
on unlockLayer(subjectLayer)
local thisSubLayer
tell application "Adobe Illustrator"
set the properties of subjectLayer to {locked:false}
if (count of layers in subjectLayer) > 0 then
repeat with i from 1 to count of layers in subjectLayer
set thisSubLayer to layer i in subjectLayer
-- set the properties of thisSubLayer to {locked:false}
my unlockLayer(thisSubLayer)
end repeat
end if
end tell
end unlockLayer
tell application "Adobe Illustrator"
local thisLayer, activeDoc
if (count of documents) > 0 then
set activeDoc to front document
repeat with i from 1 to count of layers of activeDoc
-- set the properties of layer i of front document to {locked:false}
set thisLayer to layer i of front document
-- set the properties of thisLayer to {locked:false}
my unlockLayer(thisLayer)
end repeat
end if
end tell
Copy link to clipboard
Copied
All seems to be ok.
But only for interest: did someone try the code in my post #12 ? (I know, this is not pure AppleScript )
Copy link to clipboard
Copied
I have ran many do javascript just how you have written it with it working just the way you expect. (working at all, haha).
But I have not tested yours, however I'm 100% sure it's going to work just fine