This Illustrator script automates the duplication of the currently active artboard along with all its contents and guides. It first retrieves the properties of the active artboard (position, dimensions, and name), then creates a new artboard to the right of the original and names it by appending ” Copy” to the original artboard’s name. The script selects and copies all items from the active artboard and pastes them into the duplicated artboard. Additionally, it duplicates the guides from the original artboard, offsetting their positions to match the new artboard’s location. When complete, it displays a confirmation message.
JavaScript
// Duplicate Current Artboard with Guides and Content
#target illustrator
function duplicateArtboard() {
if (app.documents.length > 0) {
var doc = app.activeDocument;
var currentArtboard = doc.artboards[doc.artboards.getActiveArtboardIndex()];
// Store the current artboard's properties
var left = currentArtboard.artboardRect[0];
var top = currentArtboard.artboardRect[1];
var right = currentArtboard.artboardRect[2];
var bottom = currentArtboard.artboardRect[3];
var name = currentArtboard.name;
// Create a new artboard
var newArtboard = doc.artboards.add([left + (right - left), top, right + (right - left), bottom]);
newArtboard.name = name + " Copy";
// Select all items on the current artboard
doc.selectObjectsOnActiveArtboard();
// Copy selected items
app.copy();
// Activate the new artboard
doc.artboards.setActiveArtboardIndex(doc.artboards.length - 1);
// Paste the copied items
app.paste();
// Duplicate guides
for (var i = 0; i < doc.guides.length; i++) {
var guide = doc.guides[i];
var newGuide = doc.guides.add();
newGuide.orientation = guide.orientation;
newGuide.position = guide.position + (right - left);
}
alert("Artboard duplicated successfully!");
} else {
alert("No open document found. Please open a document and try again.");
}
}
duplicateArtboard();
Guidelines:
- Prerequisites:
- Open Adobe Illustrator and ensure that a document with at least one artboard is open.
- Make sure the artboard you want to duplicate is active.
- How to Run the Script:
- Launch Illustrator.
- Open the script via File > Scripts or by running it in your preferred scripting environment.
- The script will automatically process the active artboard.
- What the Script Does:
- Retrieves the active artboard’s location and dimensions.
- Creates a new artboard immediately to the right of the current one.
- Selects all objects on the current artboard, copies, and then pastes them onto the new artboard.
- Duplicates all the guides from the original artboard by offsetting their positions according to the width of the artboard.
- Displays an alert confirming a successful duplication once processing is complete.
- Customization:
- You can adjust the duplicated artboard’s offset or modify the naming convention by editing the script.
- Further modifications can also be made to control which items or guides are duplicated.