Copy link to clipboard
Copied
Hello,
I have a problem modifying sublayers inside a locked layer;
If I expand the layer, I can't see any objects inside it.
The objects appear only if I select the layer shift+ctrl+click on it;
This is not letting the SDK return those items when I run Spread.GetItemsOnPage()
Any idea whats going on here?
So if you want to traverse the pageitems and masterpageitems present on the page. You can use the following JS code
var pages = app.documents[0].pages.everyItem().getElements()
for (var k = 0; k < pages.length; k++) {
var items = app.documents[0].pages[k].masterPageItems;
items = items.concat(app.documents[0].pages[k].allPageItems)
for (var i = 0; i < items.length; i++) {
var item = items[i];
alert("Found object");
}
}
-Manan
Layers are not related to spreads or masterspread in such a way that they are sepecific to them. Layers are document wide, so if you want to unlock all the layers in the document the following code shall work
app.documents[0].layers.everyItem().locked = false
-Manan
Copy link to clipboard
Copied
So you mean to say that the locked layer if expanded shows blank under it and when you unlock it then you start seeing the pageitems? Can you post screenshots? This is not normal behaviour, normally you should see the pageitems on expanding the layer even if the layer is locked. Does this happen with every document you create?
Also can you post your code snippet, describing what you are trying to do and what errors does the code give you. If possible send a demo document to test the code with
-Manan
Copy link to clipboard
Copied
Even if I unlock it, pageItems are not shown in the layer panel, to make them appear, I have to unlock the layer and select it by using ctr + alt + click on the layer.
Before and After images attaches
Copy link to clipboard
Copied
Does this happen with every document you create? Can you share a demo document for me to test this out?
Also the after image you shared is it after your script ran on the document? If so then please share the code of the script for us to have a look at.
-Manan
Copy link to clipboard
Copied
No this is happening only for this document and for this layer only;
The after image is after selecting the layer (unlock and ctrl + alt + click)
The code works for all other layers/pages
I use this C++ function to get all the page items on the spread from
ISpread Class Referenceabstract
virtual void GetItemsOnPage (int32 pgPos, UIDList *items, bool16 bIncludePage=kTrue, bool16 bIncludePasteboard=kFalse, bool16 bIncludeBleedAndSlug=kTrue) const =0
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I also can't get the 'damaged' layers, I get other layers though using this JS code:
for (var k = 0; k < pages.length; k++) {
var items = pages[k].pageItems;
for (var i = 0; i < items.length; i++) {
var item = items[i];
alert("Layer name =" + item.itemLayer.name + " locked? =" + item.itemLayer.locked);
item.itemLayer.locked = false;
alert("Layer name =" + item.itemLayer.name + " still locked? =" + item.itemLayer.locked);
for (var m = 0; m < item.itemLayer.pageItems.length; m++) {
pItem = item.itemLayer.pageItems[m];
}
}
}
Copy link to clipboard
Copied
Ahh, I never noticed this, These items are places on the Parent Page and not on the document page. If you look for the masterspread items you should be able to get your code working. So setting the page to pages of masterspreads will work
var pages = app.documents[0].masterSpreads.everyItem().pages.everyItem().getElements()
-Manan
Copy link to clipboard
Copied
Is it possible to unlock all layers in all masterspreads in JS?
Copy link to clipboard
Copied
Layers are not related to spreads or masterspread in such a way that they are sepecific to them. Layers are document wide, so if you want to unlock all the layers in the document the following code shall work
app.documents[0].layers.everyItem().locked = false
-Manan
Copy link to clipboard
Copied
So if you want to traverse the pageitems and masterpageitems present on the page. You can use the following JS code
var pages = app.documents[0].pages.everyItem().getElements()
for (var k = 0; k < pages.length; k++) {
var items = app.documents[0].pages[k].masterPageItems;
items = items.concat(app.documents[0].pages[k].allPageItems)
for (var i = 0; i < items.length; i++) {
var item = items[i];
alert("Found object");
}
}
-Manan