Copy link to clipboard
Copied
Hi all,
I am looking for a script that would add variable/objects to all the text on the same layer of an illustrator file.
Copy link to clipboard
Copied
Hi all,
I am looking for a script that would add variable/objects to all the text on the same layer of an illustrator file.
Copy link to clipboard
Copied
check the script in this thread, it does exactly that. It creates variables and binds them to each text frame in the active layer
https://community.adobe.com/t5/illustrator/batch-creation-of-variables/m-p/6078151?page=1#M224180
Copy link to clipboard
Copied
Thanks Carlos,
I ran that script it does add the "variable" but does not add "objects".
Is there a step I am missing?
Copy link to clipboard
Copied
what do you mean by objects? please show screenshots
Copy link to clipboard
Copied
Using the script Variables are added, but objects section remains blank.
When the Variable is done manually the text is visible in the object area. Also, is the object area needed for when you export the variables.xml?
I hope this makes sense. Thanks again for your help.
Copy link to clipboard
Copied
I see, I'm not sure what's happening. I'm getting this
Copy link to clipboard
Copied
I tried running the script with just plain text boxes similiar to your example and I am still getting the same results "objects" section does not add the text.
Copy link to clipboard
Copied
After some troubleshooting, script is working now!
Copy link to clipboard
Copied
what was the issue?
Copy link to clipboard
Copied
I re-copied and re-saved the script and it works now.
Now that i have the .xml file with all the text variables, how can i replace the text with translations, using a .csv file? Can the .xml with the variables outlined be converted to a spreadsheet format?
Copy link to clipboard
Copied
Yes, actually it can - using the still-existing handy ExtendScript XML feature.
You can use XML inside the JSX file like this sample snippet:
#target illustrator
function test(){
function getScriptProperties(node){
var propObj = {};
var propertiesNode = node.children("properties"), propsArr, propAmt, propName, thisProp;
if(propertiesNode != ""){
propsArr = propertiesNode.children();
propAmt = propsArr.length();
for (var i = 0; i < propAmt; i++) {
thisProp = propsArr[i];
propName = thisProp.name();
if(propName != ""){
propObj[propName] = propsArr[i].toString().trim();
}
}
return propObj;
}
return null;
};
var z = "<root><apples></apples><properties><prop1>Hello</prop1><prop2>World</prop2></properties></root>";
var myXml = XML(z);
alert(getScriptProperties(myXml).toSource());
}
test();
This feature is called "E4X", and this snippet illustrates a sample custom procedure which uses some of the E4X functions such as 'node.children()'. It will work with a simple xml string as above, but not with an xml file containing Illustrator's variables. The variables file contains xml namespaces with colons:
For this, there may be proper E4X methods to deal with that somehow, but I've never been aware of such. If anyone knows, please post.
The workaround could be to process the xml string as text first, replacing any text which causes an error when attempting to use the XML() function.
Otherwise, to create a CSV without working on the text is a very slow and not-recommended way of cycling each dataset in the document and obtaining all the text variables from the variable textbox's contents.