Is there a script to run a bulk import of variables from a text file?
Hello FrameMaker experts!
I'm trying to consolidate multiple documents into FrameMaker for translation purposes. The document has several text strings that would be easier to maintain/validate as variables. I was wondering if anyone found or created a script they'd be willing to share. I started this project in InDesign and have a script for that program, but it doesn't work in FrameMaker. I am no coding expert, but I didn't expect it to work.
Someone else posted about this a few years ago: https://community.adobe.com/t5/framemaker-discussions/script-for-importing-variables/m-p/13121274 with a link to a Swedish company. I will try translating that as a last resort.
Here is the link for the script that works in InDesign: https://gist.github.com/circleb/e87421b163479aa38d495163ba6ad76d and the code is as follows:
Any help would be appreciated!!
Thanks!
Wendy
/* ***************************************************************** */
/* Most of the code came from the InDesign script FindChangeByList.jsx
/* and the function setCustomTextVariable() by Jon S. Winters.
/*
/* DESCRIPTION
/* This script allows you to import a simple text file containing a
/* text variable list and registers them as "Custom Text Variables,"
/* this script doesn't work for any other kind of InDesign variable.
/* It will update any variables that already exist.
/*
/* INSTRUCTIONS
/* Make a text file with a new line for each variable you like to add.
/* Each line chould start with var, have a tab, then the variable name,
/* another tab and the variable value. Install the script in the proper
/* location, then run it from the Scripts panel. You'll be presented
/* a dialog box to choose your text file, choose the file and the
/* script will do the rest.
/*
/* ***************************************************************** */
var doc = app.activeDocument;
var myVars = doc.textVariables;
var variableNames = myVars.everyItem().name;
var myFindChangeFile;
var myFindChangeArray, myFindPreferences, myChangePreferences;
myFindChangeFile = myFindFile("./Test.ini")
if(myFindChangeFile != null){
myFindChangeFile = File(myFindChangeFile);
var myResult = myFindChangeFile.open("r", undefined, undefined);
if(myResult == true){
//Loop through the find/change operations.
do{
myLine = myFindChangeFile.readln();
//Ignore comment lines and blank lines.
if((myLine.substring(0,3)=="var")){
myFindChangeArray = myLine.split("\t");
setCustomTextVariable(doc, myFindChangeArray[1], myFindChangeArray[2])
}
} while(myFindChangeFile.eof == false);
myFindChangeFile.close();
}
}
function myFindFile(myFilePath){
var myScriptFile = myGetScriptPath();
var myScriptFile = File(myScriptFile);
var myScriptFolder = myScriptFile.path;
myFilePath = myScriptFolder + myFilePath;
if(File(myFilePath).exists == false){
//Display a dialog.
myFilePath = File.openDialog("Choose the file containing your find/change list");
}
return myFilePath;
}
function myGetScriptPath(){
try{
myFile = app.activeScript;
}
catch(myError){
myFile = myError.fileName;
}
return myFile;
}
function setCustomTextVariable(docRef, name, value) {
//-- Written: 2010.04.19 by Jon S. Winters of electronic publishing support
//-- eps@electronicpublishingsupport.com
try {
var atv = docRef.textVariables.everyItem();
if (atv.hasOwnProperty(name)) {
atv[name].variableOptions.contents = value;
}
else {
var newTV = docRef.textVariables.add({ name: name, variableType: VariableTypes.CUSTOM_TEXT_TYPE });
newTV.variableOptions.contents = value;
}
return true;
}
catch (failSilently) {
var localError = failSilently;
return false;
}
}
