Copy link to clipboard
Copied
Hello there,
I need hel creating the script for templet file in Illustrator where some text field need to fill automatically. Please see below:
Date: xyzxyz (auto fill based on the date of creation)
Customer: xyzxyz (drop down menu based on path wher the file is)
Part#: KG12345 (it gets from template file name)
Description: Beef Sausage 400g (it gets from template file name)
Template file name example: KG12345_Beef Sausage 400g-PROOF
Copy link to clipboard
Copied
Hi @bosko_5014 there are many, many ways of approaching this type of need, but here is a fairly simple one: you put your text frames into a group called "info" and name the text frames "partNumber", "description", "date" and "client". The script finds them, collects the data you need, and populates those frames' contents.
To test it out, first run it with the attached demo document so you can see it in its most simplest case. Let me know how it goes. Note that it assumes the "client" is the name of the document's parent folder.
- Mark
/**
* @file Populate Text From Filename.js
*
* Finds a group called "Info" and textframes inside that group
* and populates their contents as follows:
* - PartNumber: from document file name
* - Description: from document file name
* - Date: the document's file's creation date, as YYYY-MM-DD
* - Customer: The document's file's parent's (folder) name
*
* @author m1b
* @version 2025-01-16
* @discussion https://community.adobe.com/t5/illustrator-discussions/script-for-illustrator-25-0/m-p/15091263
*/
(function () {
var settings = {
// extract the part number and description from the filename
matchFilename: /([A-Z]+\d+)_([^\-]+)-/,
// a GroupItem in the document must be named this
INFO_GROUP_NAME: 'info',
// the names of the target text frames
FRAME_NAMES: [
'partNumber',
'description',
'date',
'client',
],
};
var doc = app.activeDocument;
if (!doc.fullName)
return alert('Please save the document and try again.');
var match = doc.name.match(settings.matchFilename);
if (!match || 3 !== match.length)
return alert('Could not parse the filename "+doc.name+".');
// collect the info
var partNumber = match[1],
description = match[2],
date = doc.fullName.created.toJSON().slice(0, 10),
client = doc.fullName.parent.name;
// collect the text frames from the "info group"
var infoGroup = getThing(doc.groupItems, 'name', settings.INFO_GROUP_NAME);
if (!infoGroup)
return alert('Could not find the group item named "' + settings.INFO_GROUP_NAME + '".');
// find the text frames
var infoTexts = {
partNumber: getThing(infoGroup.textFrames, 'name', settings.FRAME_NAMES[0]),
description: getThing(infoGroup.textFrames, 'name', settings.FRAME_NAMES[1]),
date: getThing(infoGroup.textFrames, 'name', settings.FRAME_NAMES[2]),
client: getThing(infoGroup.textFrames, 'name', settings.FRAME_NAMES[3]),
};
// set the info
if (infoTexts.partNumber)
infoTexts.partNumber.contents = partNumber;
if (infoTexts.description)
infoTexts.description.contents = description;
if (infoTexts.date)
infoTexts.date.contents = date;
if (infoTexts.client)
infoTexts.client.contents = client;
})();
/**
* Returns a thing with matching property.
* If `key` is undefined, evaluate the object itself.
* @author m1b
* @version 2024-04-21
* @param {Array|Collection} things - the things to look through.
* @param {String} [key] - the property name (default: undefined).
* @param {*} value - the value to match.
*/
function getThing(things, key, value) {
for (var i = 0, obj; i < things.length; i++)
if ((undefined == key ? things[i] : things[i][key]) == value)
return things[i];
};
Copy link to clipboard
Copied
Hi Mark,
Thank you for your response. I don't know anything about scripting and I wouldn't know how to use what you sent me. If I snd you my template file would you be able to make it work and send it back to me? I'm willing to pay for your service.
Regards,
Bosko
Copy link to clipboard
Copied
Hi @bosko_5014, sure i'd be happy to help—click on my username and send me a message that way.
- Mark
P.S. here is a good tutorial on using scripts in Illustrator.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now