I am using the below script to number the grey box / "dynamic" portion of the tag. Basically, you select all the objects you want numbered and run the script. So in my case, I select same fill of the grey "dynamic" portion and run the script and it adds number, however formatting isn't quite right.
I feel like I am almost there.. But I need help to edit a bit to get the formatting...
Basically, here is what I am looking for as the desired outcome. Need to adjust the following elements:
- Change it to a defined font character and style, ie: Proxima Nova Regular, size= 17pt, tracking= -10, paragraph= align center.
- Define the color as a specific CMYK value, ie: C0 M0 Y0 K1
- Add leading 00's so the outcome would be 001 through 999 (this one I could do without if it's complicated, as I can use the "fix sequential numbers script" below to add the 00's if need be - or maybe you can help incorporate this as part of this script?).
- Center the 001 vertically and horizontally on the grey box
- Maintain the group, ie: so the number created is grouped with the rest of the tag.
Here is the script I'm using thus far...
Add numbers script
var document = app.activeDocument; //Use the current open Ai File
var selected = document.selection; //Use the current selection in Ai
for (var i = 0; i < selected.length; i++) { //Iterate over every selected object
var text = document.textFrames.add(); //Add a new text object
text.contents = i + 1; //Set the corresponding number text
text.top = selected[i].top - 10; //Position the text object underneath
text.left = selected[i].left;
text.textRange.characterAttributes.size = 24;
text.textRange.characterAttributes.fillColor = document.swatches[4].color; // use the 4th swatch's color
}
Fix Sequential Numbers Script
// fixing sequential numbers
// a script for Adobe Illustrator CSx-CCx
// For the selected text objects, change each content so that they become
// a sequential numerical values at even intervals from the backmost value
// to the foremost value.
// For the number of decimal places and the number of zero-filled digits,
// the largest one of the foremost value and the backmost value is adopted.
// (Fractions are rounded off as necessary.)
// ex. (the left end is the backmost and the right end is the foremost)
// 1 1 1 1 5 -> 1 2 3 4 5
// 1.0 x x x 5 -> 1.0 2.0 3.0 4.0 5.0
// 1 1 1 1 5.00 -> 1.00 2.00 3.00 4.00 5.00
// 1.0 1 1 1 6 -> 1.0 2.3 3.5 4.8 6.0
// 1 1 1 1 6 -> 1 2 4 5 6
// 01 1 1 1 5 -> 01 02 03 04 05
// 00 1 1 1 1 10 -> 00 02 04 06 08 10
// Hiroyuki Sato
// http://shspage.blogspot.com/2009/06/fixing-sequential-numbers.html
// 2018-10-03
main();
function main(){
if( app.documents.length < 1 ){
alert("ABORT\rthere's no open document");
return;
}
var texts = [];
var sel = app.activeDocument.selection;
if(!(sel instanceof Array) || extractTextFrames(sel, texts) < 3){
alert("ABORT\rplease select 3 or more text objects");
return;
}
var num_to = texts[0].contents - 0;
var num_from = texts[ texts.length - 1 ].contents - 0;
if(isNaN(num_to) || isNaN(num_from)){
alert("ABORT\rthe foremost and the backmost text objects in the selection must be a number.");
return;
}
var interval = (num_to - num_from) / (texts.length - 1);
var decimal_places = 0;
if( texts[0].contents.match(/\.(\d+)/)){
decimal_places = RegExp.$1.length;
}
if( texts[ texts.length - 1 ].contents.match(/\.(\d+)/)){
decimal_places = Math.max( decimal_places, RegExp.$1.length );
}
var zero_fill = 0;
if( texts[0].contents.match(/^0+\d*/)){
zero_fill = RegExp.lastMatch.length;
}
if( texts[ texts.length - 1 ].contents.match(/^0+\d*/)){
zero_fill = Math.max( zero_fill, RegExp.lastMatch.length );
}
var s;
for(var i = 0; i < texts.length; i++){
s = (num_to - interval * i).toFixed(decimal_places);
if( zero_fill > 1 ){
while( s.match(/^\d+/)
&& RegExp.lastMatch.length < zero_fill ){
s = "0" + s;
}
}
texts[i].contents = s;
}
}
// --------------------------------------
function extractTextFrames(s, arr){
for(var i = 0; i < s.length; i++){
if(s[i].locked || s[i].hidden){
continue;
} else if(s[i].typename == "TextFrame"){
if(s[i].textRange.characters.length > 0) arr.push(s[i]);
} else if (s[i].typename == "GroupItem"){
extractTextFrames(s[i].pageItems, arr);
}
}
return arr.length;
}