• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Export and import variables

Participant ,
May 04, 2016 May 04, 2016

Copy link to clipboard

Copied

Hi all,

actually I'm seeking to find anyway to select all text on illustrator file then convert them all to variables then export it to .XML at the same path with illustrator file to be translated then import the same .XML after translation

i tried a lot but i stopped at the first step is to select all text frames and convert them to variables

var idoc = app.activeDocument;

var ilayer = idoc.activeLayer;

for (i=0; i<ilayer.textFrames.length; i++) {

    var itext = ilayer.textFrames;

    var idocvar = idoc.variables.add();

    idocvar.kind = VariableKind.TEXTUAL;

    try {itext.contentVariable = idocvar}

    catch (e) {idocvar.remove()}

}

any help please !!

Suzan

TOPICS
Scripting

Views

932

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 1 Correct answer

Valorous Hero , May 04, 2016 May 04, 2016

Here is a basic example to get you started.

#target illustrator

function test(){

  var doc = app.activeDocument, thisVar, thisText, newDataset;

  // Set up the variables for each text & bind.

  for(var i=0; i<doc.textFrames.length; i++){

    thisText = doc.textFrames;

    thisVar = doc.variables.add();

    thisVar.kind = VariableKind.TEXTUAL;

    thisText.contentVariable = thisVar;

  };

  // Capture one dataset

  newDataset = doc.dataSets.add();

  newDataset.name = "Test Data Set";

  newDataset.update();

  //

...

Votes

Translate

Translate
Adobe
Valorous Hero ,
May 04, 2016 May 04, 2016

Copy link to clipboard

Copied

Here is a basic example to get you started.

#target illustrator

function test(){

  var doc = app.activeDocument, thisVar, thisText, newDataset;

  // Set up the variables for each text & bind.

  for(var i=0; i<doc.textFrames.length; i++){

    thisText = doc.textFrames;

    thisVar = doc.variables.add();

    thisVar.kind = VariableKind.TEXTUAL;

    thisText.contentVariable = thisVar;

  };

  // Capture one dataset

  newDataset = doc.dataSets.add();

  newDataset.name = "Test Data Set";

  newDataset.update();

  // Export xml file in same directory as the AI file.

  doc.exportVariables(File(File(doc.fullName).parent + "/Test Variables.xml"));

};

test();

Votes

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
Participant ,
May 04, 2016 May 04, 2016

Copy link to clipboard

Copied

Thanks a lot dear, wroks like magic

well then can i ask about a code to import the same file back if possible?

Cheers

Suzan

Votes

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
Valorous Hero ,
May 04, 2016 May 04, 2016

Copy link to clipboard

Copied

You can import it back like this:

    var doc = app.activeDocument;

    var varsFile = File(File(doc.fullName).parent + "/Test Variables.xml");

    doc.importVariables(varsFile);

The text will already have those variables bound, so all you have to choose is the Test Data Set again from the datasets dropdown and the text will be updated.

Doing doc.dataSets[0].display() does not seem to work, so I force-refresh this by opening a new document and closing it, if that's really needed.

Votes

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
Participant ,
May 04, 2016 May 04, 2016

Copy link to clipboard

Copied

LATEST

my grateful thanks with kisses for your magic again

Cheers

Suzan

Votes

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