Of course. Here is a rewritten prompt with a high level of detail, clear instructions, and best practices that will guide an AI to create a robust and user-friendly script.
AI Task: Create an Adobe Illustrator Script to Convert Groups into Individual Artboards
Objective:
Develop a JavaScript (.jsx) script for Adobe Illustrator that finds all top-level grouped objects in a document, creates a new, perfectly sized artboard for each group, and then provides an option to clean up the original artboards.
Core Workflow (Step-by-Step Logic):
The script must follow this precise sequence to avoid errors and data loss:
-
Initialization Check:
- Verify that a document is open. If not, display an alert: "Please open a document before running this script." and terminate.
- Scan the active document for all top-level groups.
- If no groups are found, display an alert: "No grouped objects found in the document." and terminate.
-
Store Original State:
- Before making any changes, get a list of all existing artboards in the document. This list will be used later for the deletion step.
-
Iterate and Create:
- Loop through each identified top-level group.
- For each group, calculate its precise bounding box (
geometricBounds).
- Create a new artboard whose dimensions and position match the calculated bounding box of the group.
- Assign a name to the newly created artboard (see Naming Convention section below).
-
Cleanup Phase:
- Crucially, this step must happen after all new artboards have been created.
- If the user has opted to delete the original artboards, iterate through the list of artboards stored in Step 2 and delete each one. This ensures that objects on the original artboards are not lost before their new artboards are ready.
User Interface (UI) and Customization:
The script must present a ScriptUI dialog window to the user with the following options before running:
1. Scope of Operation:
* Radio Buttons:
* (o) Process All Groups in Document (Default)
* ( ) Process Selected Groups Only (This option should be disabled if no groups are currently selected).
2. Artboard Sizing:
* Padding: A numerical input field to add extra space around the object. The label should be "Padding (in points)". Default value: 0.
3. Artboard Naming Convention:
* A dropdown menu labeled "Name New Artboards Using:":
* Sequential Numbering (e.g., Artboard-1, Artboard-2) (Default)
* Original Group Name (If a group has a custom name in the Layers panel. If it's just named <Group>, fall back to sequential numbering for that item).
* A text input field for a custom Prefix. Default value: Artboard-.
4. Cleanup Options:
* A checkbox labeled:
* [ ✓ ] Delete original artboards after processing (Default: checked). This is a critical option for making the script non-destructive if needed.
5. Action Buttons:
* "Run" Button: Executes the script with the chosen settings.
* "Cancel" Button: Closes the dialog window without making any changes.
Technical Specifications and Best Practices:
- Language: ExtendScript (JavaScript for Adobe Illustrator,
.jsx file).
- Compatibility: Ensure the script is compatible with Adobe Illustrator CC 2020 and newer.
- Target Objects: The script should only target top-level groups. It must ignore nested groups and individual objects that are not part of a group.
- Undo Functionality: The entire script operation must be wrapped in a single, atomic undo state. This allows the user to press
Ctrl+Z or Cmd+Z once to revert all changes made by the script.
- Error Handling: Use
try/catch blocks to gracefully handle unexpected errors during the process and inform the user with a clear message.
- Code Structure:
- Write modular code. Use separate functions for UI creation, finding groups, creating artboards, and deleting old artboards.
- Include clear comments explaining the purpose of functions and complex lines of code.
- User Feedback:
- Display a confirmation alert upon successful completion, e.g., "Process complete. Created [X] new artboards."
Deliverables:
- The complete, commented
.jsx script file.
- Clear instructions on how to install and run the script in Adobe Illustrator (e.g., "Place the .jsx file in the Scripts folder and access it via File > Scripts").
- A brief explanation of each UI option so the user understands the functionality of the padding, naming, and cleanup settings.