Skip to main content
lfcorullon13651490
Legend
Jan 4, 2018 3:45 PM UTC
Answered

Load/Import text variables

Hello, scripters!!!

Since InDesign has a native option to load text variables from another file, I would ask you: where are the documentation about that option? I cannot find anything here at the Forums or at Jongware's documentation website, or even Adobe PDFs about scripting.

Is there a way to load/import textVariables?

Thank you. Best regards from Brazil.

This topic is closed to new replies. Start a new post to keep the conversation going.
LaubenderCorrect answer
Community Expert
Jan 4, 2018 5:42 PM UTC

lf.corullon  wrote

… My goal: update all textVariables in the current document from the source one. …

Ok. Then first rename all text variables in the target document, that have the same name in source.

Then go through all variable text instances—associatedInstances—of a renamed one and apply the correct text variable from source by using property associatedTextVariable.

I hope, that makes sense.

Regards,
Uwe

9 replies

lfcorullon13651490
Legend
Jan 5, 2018 12:13 AM UTC

Great.

Well... I think it's done.

Thank you so much again!

Do you know the best approach to my next goal: "import" layers and it's pageItems from the source doc to the target.

Translate
Community Expert
Jan 5, 2018 12:38 AM UTC

lf.corullon  wrote

… Do you know the best approach to my next goal: "import" layers and it's pageItems from the source doc to the target.

Only a hint: You cannot use method move() for layers to transfer layers from document A to document B.

You would need to move pageItems from doc A to doc B and assign a layer through its itemLayer property.

Also see into app.clipboardPreferences.pasteRemembersLayers if you choose to select(), copy() and pasteInPlace() the items.

Maybe it's best to do a new thread on this.

Regards,
Uwe

Translate
Community Expert
Jan 4, 2018 5:14 PM UTC

lf.corullon  wrote

… Is there a way to load/import textVariables?

Not explicitely, I think.

You have to use text variables with text and move the text from document to document.

Before doing that I would recommend to compare all properties for variables with same names in source and target docs.

Regards,
Uwe

Translate
lfcorullon13651490
Legend
Jan 4, 2018 5:26 PM UTC

It was what I feared.

I'll need to list all the text variables, and then the type of each one, and then the properties of each type of each of them?  My god... I just don't know how to start this.

I found this snipet from Tomaxxi:

if(app.documents.length > 0){

  var myDoc = app.activeDocument;

  var myVariables = myDoc.textVariables;

  var myVariablesTable = ["Index","Name","Type"];

  var rowCount = 1;

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

    myVariablesTable.push(String(myVariables.index));

    myVariablesTable.push(String(myVariables.name));

    myVariablesTable.push(String(myVariables.variableType));

    rowCount++;

  }

  var myTextFrame = myDoc.pages[0].textFrames.add();

  myTextFrame.geometricBounds = [20,20,250,300];

  var myVariablesTbl = myTextFrame.insertionPoints[0].tables.add();

  myVariablesTbl.columnCount = 3;

  myVariablesTbl.columns.item(0).width="15mm";

  myVariablesTbl.columns.item(2).width="90mm";

  myVariablesTbl.bodyRowCount = rowCount;

  myVariablesTbl.contents = myVariablesTable;

  myTextFrame.fit(FitOptions.FRAME_TO_CONTENT);

}

It creates a list of index, name and type of each textVariable, but not the properties.

To list the properties I need to loop thru the types and then read the properties for each one?

Any help will be appreciated.

My goal: update all textVariables in the current document from the source one.

My next goal: do the same with layers, that doesn't have a native load option in InDesign.

Translate
LaubenderCommunity ExpertCorrect answer
Community Expert
Jan 4, 2018 5:42 PM UTC

lf.corullon  wrote

… My goal: update all textVariables in the current document from the source one. …

Ok. Then first rename all text variables in the target document, that have the same name in source.

Then go through all variable text instances—associatedInstances—of a renamed one and apply the correct text variable from source by using property associatedTextVariable.

I hope, that makes sense.

Regards,
Uwe

Translate