Convert this script to a dialog window
Hi there!
I wrote this script and it's working 100% accurately, it performs the following steps.
1-it reads the artboards of the opened document and copies the first artboard content. (I want to select a file with a dialog window)
2- It has the option to choose the destination file folder. (I want it after 1st one)
3- It creates a new document of a given width and height (I want these 2 fields to choose desired size document)
4- It creates a new document size rectangle of white color in the center of the document (I want to control the size of this rectangle and the option to add 1 or more rectangles of other shapes like a circle, rounded rectangle, star, or polygon shape)
5- then it pastes the artboard content and resizes it. (I want to control the resize value dynamically)
6- finally it saves the document in Illustrator EPS10 format. (I want to select any format with any version, and the option to save 1 or more formats as the illustrator built-in export feature does.)
Note: It doesn't have any progress bar. Need to add a progress bar too.
JavaScript code ...
// Get the active document
var doc = app.activeDocument;
// Count the number of artboards in the document
var numArtboards = doc.artboards.length;
alert("The document contains " + numArtboards + " artboards.");
// Ask the user for the path to save the files
var savePath = Folder.selectDialog("Select the folder to save the EPS files:");
// Loop through all artboards in the document
for (var i = 0; i < numArtboards; i++) {
// Get the current artboard
var artboard = doc.artboards[i];
// Select the objects on the current artboard
doc.selectObjectsOnActiveArtboard();
// Copy the selected objects
app.copy();
// Create a new document with the desired size
var newDoc = app.documents.add(DocumentColorSpace.RGB, 2400, 2400);
// Create a white color rectangle in the center of the artboard
var rect = newDoc.pathItems.rectangle(2400, 0, 2400, 2400);
rect.fillColor = new RGBColor();
rect.fillColor.red = 255;
rect.fillColor.green = 255;
rect.fillColor.blue = 255;
rect.stroked = false;
// Paste the copied content into the new document
newDoc.activate();
app.paste();
// Resize the pasted vector to 3437.5%
var myobject = newDoc.activeLayer.pageItems[0];
myobject.resize(2812.5,2812.5);
// Save the new document as an EPS Illustrator 10 file
var file = new File(savePath + "/" + (i+1) + ".eps");
var options = new EPSSaveOptions();
options.compatibility = Compatibility.ILLUSTRATOR10;
try {
newDoc.saveAs(file, options);
} catch (e) {
alert("An error occurred while saving the file: " + e);
}
// Close the new document
newDoc.close();
// Deselect the objects
// Deselect the objects
doc.selection = null;
// Select next artboard
doc.artboards.setActiveArtboardIndex(i+1);
// Copy the artboard content to the clipboard
doc.selectObjectsOnActiveArtboard();
app.copy();
}
// Show a success message
alert("The process is completed. The files have been saved in the selected folder.");
// Open the folder where the files were saved
savePath.execute();
END OF SCRIPT
========================
I know the code is very basic javaScript practices. Need to make it as desired and faster response.
Waiting for the solution from this Community
Regards
