Script to convert all text to Variable/Objects

Dec 14, 2020

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.

TOPICS
Import and export, Scripting, Third party plugins

Views

112

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Script to convert all text to Variable/Objects

Dec 14, 2020

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.

TOPICS
Import and export, Scripting, Third party plugins

Views

113

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 14, 2020 0
Dec 14, 2020

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 14, 2020 0
Dec 14, 2020

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? 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 14, 2020 0
Dec 14, 2020

Copy link to clipboard

Copied

what do you mean by objects? please show screenshots

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 14, 2020 0
Dec 14, 2020

Copy link to clipboard

Copied

 

Using the script Variables are added, but objects section remains blank.

 

Screenshot 2020-12-14 161856.png

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?

Screenshot 2020-12-14 162128.png

I hope this makes sense. Thanks again for your help.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 14, 2020 0
Dec 14, 2020

Copy link to clipboard

Copied

I see, I'm not sure what's happening. I'm getting this

dynamic variables.PNG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 14, 2020 0
Dec 15, 2020

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. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2020 0
Dec 15, 2020

Copy link to clipboard

Copied

After some troubleshooting, script is working now!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2020 1
Dec 15, 2020

Copy link to clipboard

Copied

what was the issue?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2020 0
Dec 15, 2020

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? 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2020 0
Silly-V LATEST
Dec 15, 2020

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:

    <v:sampleDataSets  xmlns="&ns_custom;" xmlns:v="&ns_vars;">
      <v:sampleDataSet  dataSetName="Data Set 1">


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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 15, 2020 2
Resources