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.
Hi @brian_p_dts
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 item
...Copy link to clipboard
Copied
What about adding a tag object to each item with values such as "was locked" or "was invisible"?
Copy link to clipboard
Copied
Hi @brian_p_dts, 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
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?
Copy link to clipboard
Copied
Hi @brian_p_dts
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.
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.
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.
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.
Copy link to clipboard
Copied
Hi @brian_p_dts, 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