Copy link to clipboard
Copied
Hi!
To make wine labels for a store, I used the Variables function to automate switching out the text. However, there are still lots of minor tweaks to make to the labels, so I'd like to also automate the process of creating a new artboard in the document for each dataset. I've been at it for a few hours trying to script something for this, but I'm still pretty new to Javascript. Through stitching together some things I found online, I wrote this:
var myDocument = app.activeDocument;
function addArtboard() {
var firstArtBoard = myDocument.artboards[0];
for(var prop in firstArtBoard) {
if(firstArtBoard.hasOwnProperty(prop)) {
$.writeln(prop);
}
}
$.writeln(firstArtBoard.artboardRect);
var x1 = firstArtBoard.artboardRect[2] + 10;
var y1 = firstArtBoard.artboardRect[1];
var x2 = x1 + firstArtBoard.artboardRect[2];
var y2 = firstArtBoard.artboardRect[3];
myDocument.artboards.add([x1, y1, x2, y2]);
}
for (i = 0; i < myDocument.dataSets.length; i++) {
var wineType = myDocument.dataSets[i];
var newBoard = myDocument.artboards[i];
addArtboard(i);
newBoard.dataSet = wineType;
}
(all the code for creating a new artboard from here)
It creates 9 long artboards on top of one another to the right of the initial one-- I realize now this is due to the createArtboard() referencing the initial artboard when specifying the new position, but again, I'm unsure how to fix the position or size. I would attach the illustrator file, but it's coming up with a strange error that prevents it.
Any help is appreciated!
Scripting along with datasets to affect a single document can be a special challenge, because dataset processing is mostly geared toward exporting single-state documents based on the variable template. However, they do give us an option to actually work on the one document and not do any exporting via this option inside the Batch Actions dialog: Destination None.
In your case you may be able to use just the native batch actions to accomplish most of your needs and potentially use smaller auxilli
...Copy link to clipboard
Copied
Can't help you with the script, but to show AI files, please upload them to Dropbox or Creative Cloud and post a link in the forum. Thank you.
Copy link to clipboard
Copied
Scripting along with datasets to affect a single document can be a special challenge, because dataset processing is mostly geared toward exporting single-state documents based on the variable template. However, they do give us an option to actually work on the one document and not do any exporting via this option inside the Batch Actions dialog: Destination None.
In your case you may be able to use just the native batch actions to accomplish most of your needs and potentially use smaller auxilliary scripts to help other aspects of the workflow.
I created a sample test based on this use case and wonder if it would help you. Here is what it does: it uses actions and the batch process to copy some template artwork in the document and place it at a chosen distance from the last active artboard, then it creates a new artboard for the copied artwork. The copied artwork is going to be the live variable-bound art which will get populated with new text or images on the next dataset cycle.
Luckily the behavior of copy/pasting in Illustrator when it comes to variable-bound art does paste the item back in without the variable being bound, which is a good thing for this process.
Here is the document setup: there is one layer with one group in it. This group has a textframe named "name" and a rectangle the size of the artboard in it. More in-depth the group actually has a special note in it inside of Attributes > notes that says "original". The yellowish rectangle also has a note in it that says "bg". These are used later by the action.
Here is the action:
Now let's run the process.
Remember, the batch action dialog can be set to a source of Data Sets and a Destination of None, which will export no files but allow you to run a series of custom actions on the same document for each dataset record.
The batch actions play and create the new artboards with the different versions of editable art on their separate layers.
The very first layer contains the original artwork that is bound to the variables, and it has the values of the very last dataset after the process is over. You could hide or delete this artwork, choose to keep it and ignore this first artboard when using asset export or do whatever you wish with this extra artboard as it suits your workflow.
Well, I hope this helps in some way. Now, you may have noticed how although it is very nice that these new layers and artboards get made, but they are all named generic such as "Artboard 1". This is where other tiny helper scripts could come in handy should you also wish to do something actions absolutely can't during the batch process. It would be nice if a very simple script could just name the current layer or new artboard to some specific variable's value. Using the Insert Menu item it's possible to insert a custom script to play on each dataset inside of the action. Such a script could even be made to sense whether the current dataset is the last one, or first one, and do something extra to the document like cleaning up and removing the very first original artboard.
Copy link to clipboard
Copied
Thank you so so much! This is exactly what I needed. You just saved me hours of work!
I'm sure there's a way to script it so the names will automatically match a variable, but that sort of thing is way beyond me haha. Thank you again for such a clear and helpful tutorial!
Copy link to clipboard
Copied
This would be great as a downloadable action 🙂
Copy link to clipboard
Copied
Hi,
I have a bit stupid question 😄
step number one,
1- Set Selection - selects all objects whose note has "original".
how to select all objects with certain note?
Also, what do I need to change in your action to do the same copies in the same artboard
I need to duplicate the lable within the same artboard using next dataset everytime
Thank you
Copy link to clipboard
Copied
1- Set Selection - selects all objects whose note has "original".
By @Taha Moussa
The action panel's menu has an option called 'Select Object'.
It's not a stupid question. It's obscure for most users.
Copy link to clipboard
Copied
Thank you so much
Copy link to clipboard
Copied
Thanks you the tip.