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

[JSX] Remembering locked layers/pathitems/groupitems for easy recall across documents

Community Expert ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Hi all, 

 

I'm working on a script for some complex files with multiple layers, sublayers, groups, pathitems etc. To operate on the items I need to, I first iterate through the doc and unlock and make visible/unhidden all page items and layers. For the purposes of the script, I am duplicating some of the main layers to a new document. Rather than having to iterate through all page items again, is there an easier way to recall which may have been locked? I thought about passing the specific items to a layer, but since I'm copying to a new doc, I doubt those items would be valid. Is there a way to generate a list of previously locked items and their index chain within their respective parent? Or some other more obvious way that I might not be considering? Appreciate it. 

 

TOPICS
Scripting

Views

187

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

Community Expert , Aug 11, 2022 Aug 11, 2022

Hi @brianp311 

What about keeping an uuid of the items in two separate array one for visibility and another for locked items. And to fetch you can you use getPageItemFromUuid method.

Example:

 

var _id = app.selection[0].uuid;
var _itemUsingUUID = app.activeDocument.getPageItemFromUuid(_id);

 

You don't need to traverse all pageitems instead only those that are present in the stored array for visibility and locked. 

 

uuid is equivalent to the id,

getPageItemFromUuid is equivalent to the itemBy

...

Votes

Translate

Translate
Adobe
Guide ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

What about adding a tag object to each item with values such as "was locked" or "was invisible"?

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Hi @brianp311, do you need to keep track of these objects and properties over the course of a single script execution? Or between multiple script executions? Eg one script to unlock/unhide, and another script to lock/hide again later.

-Mark

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

It's all in the same script but the items are duplicated to a new document. @femkeblanco if I use tags, wouldn't I have to reiterate through everything anyway to read the tag, or can you call an item tag? 

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Hi @brianp311 

What about keeping an uuid of the items in two separate array one for visibility and another for locked items. And to fetch you can you use getPageItemFromUuid method.

Example:

 

var _id = app.selection[0].uuid;
var _itemUsingUUID = app.activeDocument.getPageItemFromUuid(_id);

 

You don't need to traverse all pageitems instead only those that are present in the stored array for visibility and locked. 

 

uuid is equivalent to the id,

getPageItemFromUuid is equivalent to the itemByID in the Indesign.

 

Best regards

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Good suggestion. I will see if the uuid carries over when I duplicate the hashed item to a new doc. 

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

I guess alternative if it doesn't would be to store the existing item name and the uuid as a key:value object in the array and rename it to it's uuid before duplicating, then rename it back using the object value. 

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Yes, that make sense. While duplicating I think, it will not be same, because uuid is unique id. Not tested from myside.

Best regards

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

LATEST

Hi @brianp311, I might not be understanding your constraints, but this is how I would do it:

1. just keep a normal reference to any pageItems you are unlocking/unhiding, eg. in array(s).

2. if any of those references are broken (eg. due to duplicating), use code to recapture them *immediately* after breaking them (ie. when duplicating, if you specify where you are duplicating with ElementPlacement, you can reliably grab a new reference to it). You must replace the old reference with the new one.

This method doesn't require any later iterating except over those arrays. But if that wouldn't work in your case, let us know.

- Mark

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