Copy link to clipboard
Copied
Hey all,
I've been trying to write this script for hours and can't seem to make any headway and any sort of help would be greatly appreciated. I essentially have a template for 8 different "types" of pages already setup and I need a script that starts with a dialogue box asking the user to input which template (i.e page 1-8) they want copy/pasted. Then it simply copies everything on the page and paste it in place for the current page. I need to make hundreds of pages so having a script would be vastly easier than trying to find which of the 8 I need each time to copy.
For example, lets say I want to use the template I have setup on page 4 and I'm currently on page 300. I would input 4 into the dialogue box and everything on page 4 would get copied and pasted in place on page 300. It feels like a very simple task but I can't get it.
Thanks in advance for any help
Copy link to clipboard
Copied
Can you post what you have? That way we can see your process and can steer you in the right direction.
Copy link to clipboard
Copied
Since posting this I found a few resources to help me get nearly all the way there. However when I duplicate (paste) the copied page, some of the objects are pasted 2-3 times so I have multiple overlapping. Didn't notice it at first until I went to edit a Text Box and saw the same placeholder text box still there.
// Adobe InDesign Script
// Function to copy contents from specified page to a specified page
function copyContentsToPage() {
var doc = app.activeDocument;
// Prompt the user for the source and destination page numbers
var sourcePageNumber = prompt("How many products on this page?", "", "Copy Contents");
var destinationPageNumber = prompt("Enter the page number to create template on:", "", "Paste Contents");
var destinationPageSide = prompt("Which side of the page is this on?\n\n" + "1. Left side\n" + "2. Right side",
"",
"Choose New Page Side"
);
// Check if the source and destination page numbers are valid
if (
sourcePageNumber !== null &&
destinationPageNumber !== null &&
!isNaN(sourcePageNumber) &&
!isNaN(destinationPageNumber)
) {
sourcePageNumber = parseInt(sourcePageNumber);
destinationPageNumber = parseInt(destinationPageNumber);
if (
sourcePageNumber > 0 &&
sourcePageNumber <= doc.pages.length &&
destinationPageNumber > 0 &&
destinationPageNumber <= doc.pages.length
) {
if (destinationPageSide == 2) {
var sourcePage = doc.pages[sourcePageNumber + 456];
var destinationPage = doc.pages[destinationPageNumber - 1];
} else {
var sourcePage = doc.pages[sourcePageNumber + 448];
var destinationPage = doc.pages[destinationPageNumber - 1];
}
// Duplicate the items from the source page to the destination page
var itemsToCopy = sourcePage.allPageItems;
for (var i = 0; i < itemsToCopy.length; i++) {
var duplicatedItem = itemsToCopy[i].duplicate(destinationPage);
}
alert(
sourcePageNumber + " contents created successfully" +
" on page " +
destinationPageNumber +
"."
);
} else {
alert("Invalid source or destination page number. Please provide valid page numbers.");
}
} else {
alert("Invalid input. Please enter valid page numbers.");
}
}
// Call the function
copyContentsToPage();
Copy link to clipboard
Copied
Any chance Master Pages would be a solution for you?
Or you could just duplicate whole page - instead of its contents.
Copy link to clipboard
Copied
I agree. Try just duplicating the page instead of the items on the page. I'm guessing you might be getting the duplicates from some of the objects being nested in other objects.
Copy link to clipboard
Copied
contentPlace might be another option as well. Instead of looping through all the items, just place them all in one go.
destinationPage.contentPlace(itemsToCopy);
Copy link to clipboard
Copied
If everything on the templated page needs to be transfered to a new page - then duplicating is the best way.
Copy link to clipboard
Copied
I agree, but it also means deleting the original page that was there. I was just trying to give additional options. There are always multiiple ways accomplish something, and we don't necessarily know all of the ins and outs of what the OP has and is trying to do.
For instance, your Master Page (Parent Page) idea would also accomplish this task quite succinctly, but could cause more work if something other than just a straight copy and go needs to be done.
Copy link to clipboard
Copied
Yeah, there is always more than one way to skin the cat - we just need to wait for more info from OP.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now