Script to convert all text to Variable/Objects

Community Beginner ,
Dec 14, 2020 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

602

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
community guidelines

correct answers 2 Correct answers

Community Beginner , Dec 15, 2020 Dec 15, 2020

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
Adobe Community Professional , Dec 15, 2020 Dec 15, 2020

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
...

Likes

Translate

Translate
Adobe Community Professional ,
Dec 14, 2020 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
community guidelines
Community Beginner ,
Dec 14, 2020 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
community guidelines
Adobe Community Professional ,
Dec 14, 2020 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
community guidelines
Community Beginner ,
Dec 14, 2020 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
community guidelines
Adobe Community Professional ,
Dec 14, 2020 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
community guidelines
Community Beginner ,
Dec 15, 2020 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
community guidelines
Community Beginner ,
Dec 15, 2020 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
community guidelines
Adobe Community Professional ,
Dec 15, 2020 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
community guidelines
Community Beginner ,
Dec 15, 2020 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
community guidelines
Adobe Community Professional ,
Dec 15, 2020 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
community guidelines
Community Beginner ,
May 25, 2022 May 25, 2022

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.HenrySolis_0-1653496777787.png

@CarlosCanto can you please help out. Thanks

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
community guidelines
Community Beginner ,
May 25, 2022 May 25, 2022

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?

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
community guidelines
Adobe Community Professional ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

I'm on 26.2.1, I'll troubleshoot when I upgrade...but I'm in a crunch.

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
community guidelines
Community Beginner ,
May 27, 2022 May 27, 2022

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. 

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
community guidelines
Adobe Community Professional ,
May 28, 2022 May 28, 2022

Copy link to clipboard

Copied

LATEST

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.

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
community guidelines