Copy link to clipboard
Copied
Hi,
I have a request for help
I found here scripts for blocking and unlocking objects. How to make it to work on the scope (range) of the pages (e.g. pages from 15 to 60)?
Or selected pages (e.g. 15, 18 and 25)?
The code looks like this:
1. unlock all items in the document:
app.activeDocument.pageItems.everyItem().locked = false;
2. unlock items just on master pages use this:
app.activeDocument.masterSpreads.everyItem().pageItems.everyItem().locked = false;
3. unlock all items just on pages, not master pages:
app.activeDocument.pages.everyItem().pageItems.everyItem().locked = false;
Thank you for your help and best regards
Piotr_W
// Create a dialog box
var inputDialog = app.dialogs.add({
name: "Unlock Pages",
canCancel: true
});
// Add a dialog column
var dialogColumn = inputDialog.dialogColumns.add();
// Add a static text to the dialog box
dialogColumn.staticTexts.add({
staticLabel: "Enter page numbers or range (e.g., 15-60)"
});
// Add an editbox to the dialog box for user input
var pageInput = dialogColumn.textEditboxes.add({
minWidth: 200
});
// Show the dialog box
if (inputDialog.show() === true)
...
Copy link to clipboard
Copied
// Create a dialog box
var inputDialog = app.dialogs.add({
name: "Unlock Pages",
canCancel: true
});
// Add a dialog column
var dialogColumn = inputDialog.dialogColumns.add();
// Add a static text to the dialog box
dialogColumn.staticTexts.add({
staticLabel: "Enter page numbers or range (e.g., 15-60)"
});
// Add an editbox to the dialog box for user input
var pageInput = dialogColumn.textEditboxes.add({
minWidth: 200
});
// Show the dialog box
if (inputDialog.show() === true) {
// Get user input from the editbox
var userInput = pageInput.editContents;
// Parse user input and unlock items on specified pages
var pagesToUnlock = parsePageInput(userInput);
unlockItemsOnPages(pagesToUnlock);
}
// Function to parse user input and return an array of page numbers
function parsePageInput(input) {
var pageNumbers = [];
var inputArray = input.split(",");
for (var i = 0; i < inputArray.length; i++) {
var range = inputArray[i].split("-");
if (range.length === 1) {
// Single page number
pageNumbers.push(parseInt(range[0]) - 1); // Page numbers are 1-indexed, convert to 0-indexed
} else if (range.length === 2) {
// Page range
var start = parseInt(range[0]);
var end = parseInt(range[1]);
for (var j = start; j <= end; j++) {
pageNumbers.push(j - 1); // Page numbers are 1-indexed, convert to 0-indexed
}
}
}
return pageNumbers;
}
// Function to unlock items on specified pages
function unlockItemsOnPages(pages) {
var document = app.activeDocument;
for (var i = 0; i < pages.length; i++) {
document.pages[pages[i]].pageItems.everyItem().locked = false;
}
}
Copy link to clipboard
Copied
Thank you very much!
That's what it was, works beautiful.
Best Regards
Piotr W.
Copy link to clipboard
Copied
For just a range - you can use "itemByRange" function directly:
var myPageRange = prompt("Enter Page Range","1,-1");
app.doScript("app.activeDocument.pages.itemByRange(" + myPageRange + ").pageItems.everyItem().locked = true;",ScriptLanguage.JAVASCRIPT);
Or it could be done as a second prompt.
Otherwise, @Eugene Tyson solution is much more sophisticated.
Copy link to clipboard
Copied
Thank you, I'll practice.
I'm currently using the code from @Eugene Tyson and it works perfectly.