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

Unlocking sublayers - Applescript

Explorer ,
May 29, 2017 May 29, 2017

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.

Screen Shot 2017-05-29 at 9.47.59 am.png

Please help

Thanks,

Prem

TOPICS
Scripting

Views

2.4K

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

correct answers 1 Correct answer

Explorer , Jun 07, 2017 Jun 07, 2017

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

...

Votes

Translate

Translate
Adobe
People's Champ ,
May 29, 2017 May 29, 2017

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

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
Explorer ,
May 29, 2017 May 29, 2017

Copy link to clipboard

Copied

Actually i need the apple script.

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
People's Champ ,
May 29, 2017 May 29, 2017

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

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 ,
May 29, 2017 May 29, 2017

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

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
People's Champ ,
May 30, 2017 May 30, 2017

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…

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
Explorer ,
Jun 02, 2017 Jun 02, 2017

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

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
Enthusiast ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

LATEST

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");

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
People's Champ ,
Jun 02, 2017 Jun 02, 2017

Copy link to clipboard

Copied

That would not work with deeper nested layers

Capture d’écran 2017-06-02 à 12.29.37.png

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
Explorer ,
Jun 02, 2017 Jun 02, 2017

Copy link to clipboard

Copied

Yes. You are correct.

Do you have any solution in applescript for this?

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
People's Champ ,
Jun 02, 2017 Jun 02, 2017

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

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
Valorous Hero ,
Jun 02, 2017 Jun 02, 2017

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.

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
People's Champ ,
Jun 02, 2017 Jun 02, 2017

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

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 ,
Jun 03, 2017 Jun 03, 2017

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

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
People's Champ ,
Jun 03, 2017 Jun 03, 2017

Copy link to clipboard

Copied

yes that's what i offered in my second reply. But pur friend seems obssesed with applescript

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
Valorous Hero ,
Jun 03, 2017 Jun 03, 2017

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

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
People's Champ ,
Jun 07, 2017 Jun 07, 2017

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:

Capture d’écran 2017-06-07 à 11.43.29.png

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

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
Explorer ,
Jun 07, 2017 Jun 07, 2017

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

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 ,
Jun 07, 2017 Jun 07, 2017

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 )

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
Valorous Hero ,
Jun 07, 2017 Jun 07, 2017

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

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