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.
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?
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];
pr
...
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.
Copy link to clipboard
Copied
I've been using the script provided by @CarlosCanto for the last few years and it worked great. But today I started getting this erros message when trying to save the Data Set.
The filter cannot complete because of an unkown error.
@CarlosCanto can you please help out. Thanks
Copy link to clipboard
Copied
It looks like its the new illustrator version (26.3.1) causing the issue, I uninstalled it and installed the older version (26.2.1) and the script works fine again. Is there something in the script we can update to make it compitable?
Copy link to clipboard
Copied
I'm on 26.2.1, I'll troubleshoot when I upgrade...but I'm in a crunch.
Copy link to clipboard
Copied
@CarlosCanto Glad to connect with you again, hope you are doing well.
It is an illustrator issue with the new version, I tried to save a variable library without using the script at all and I still get the same error message.
Copy link to clipboard
Copied
oh ok, then if doing it manually shows the same issue, the script is not the problem. It is possible something got broken in the new version.