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

select every Variable Text Frame and turn it to static

Enthusiast ,
Feb 21, 2018 Feb 21, 2018

Copy link to clipboard

Copied

Hello,

I am wondering if there is any way to create a script that would take every variable text frame, picking up the image name, to turn into a static text frame, so that I could use a GREP style to remove the suffix and apply a nested style.

I just realized that I cannot do a find or change or apply a nested paragraph style to a variable text frame. I have to convert it to static text first.

There has got to be a way to select every single text frame and covert it to static? I have found a few things, but nothing that I can figure out.

Been piecing together what I can find, but just getting errors.

var myDoc = app.activeDocument;

  1. var myCap = myDoc.textVariables.item(“Image Name”);
  2. var l = myCap.associatedInstances.length;
  3. while (l--)
  4. myCap.associatedInstances[0].convertToText();

This was my last attempt after finding something on the forum:

Any additional help would be greatly appreciated.

Best,

Babs

TOPICS
Scripting

Views

1.3K

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 Expert ,
Feb 21, 2018 Feb 21, 2018

Copy link to clipboard

Copied

Have you tried Tomaxxi's snippet from the indesignsecrets forum?

https://indesignsecrets.com/topic/script-to-convert-all-text-variables

try{

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

app.activeDocument.stories.everyItem().textVariableInstances.everyItem().convertToText();}

}catch(e){alert("Something gone wrong!r" + e);};

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!

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
Community Expert ,
Feb 21, 2018 Feb 21, 2018

Copy link to clipboard

Copied

Hi Babs,

you are ( nearly ) on the right track 🙂

Wheras Colin's script will perhaps convert too much text variable instances.

 

The problem is how to identify the text variable you are looking for. It's perhaps not what you think, it might be not named "Image Name".

It could be something else, because I assume that you did dynamic captions with the names of the placed images, right?!

 

With my German InDesign this would be "Dynamische Metadatenbeschriftung: Name"

With your English version perhaps something like "Dynamic Metadata Captioning: Name".

 

But whatever it is, whatever it's name is in a different localized version of InDesign, we could gather it, if you select one text variable instance before running the script below. Then it's easy to get the right one:

 

( function()
{
    // Some tests before doing anything.

    // Is a document open?
    if(app.documents.length == 0){ return };

    // Is something selected? And if yes is the number of selected items just one?
    if(app.selection.length != 1){ return };

    // Do you have text selected?
    if(!app.selection[0].hasOwnProperty("baselineShift")){ return };

    // Is there exactly one textVariableInstance in the selected text?
    if(app.selection[0].textVariableInstances.length != 1){ return };

    // Here we get the text variable out of the selected instance:

    var textVariable = app.selection[0].textVariableInstances[0].associatedTextVariable;

    // All instances as array:
    var instancesArray = textVariable.associatedInstances;
    var instancesArrayLength = instancesArray.length;

    // Loop the array and convert to text:
    for(var n=0;n<instancesArrayLength;n++)
    {
        instancesArray[n].convertToText();
    };
}() )

 

Regards,
Uwe Laubender

( ACP )

 

// EDITED the code, because moving this thread to the new InDesign forum damaged the code!

// Now it should work as expected.

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
Enthusiast ,
Mar 17, 2023 Mar 17, 2023

Copy link to clipboard

Copied

quote

With my German InDesign this would be "Dynamische Metadatenbeschriftung: Name"

With your English version perhaps something like "Dynamic Metadata Captioning: Name".


I just checked and I believe what you're referring to is called "Live Metadata Caption: Name" in English.

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
Enthusiast ,
Feb 23, 2018 Feb 23, 2018

Copy link to clipboard

Copied

Hello Colin and Laubender,

Thank you both...

I have tried to get both to work, but have been unsuccessful.

I tried taking both of your options, placing the code into a text edit program, removing the line numbers, and saving as a .jsx file.

I put it in the samples area in InDesign to access and run, but I get errors.

I also went to the InDesign Secrets page to look at the snippet, but my problem is I don't know enough about what the snippet needs to be wrapped inside of to work.

I am not much of a code person, a little AppleScript and HTML5 here and there, but very unfamiliar with Javascript, so I am sure I am missing probably obvious code to get it to run.

I thank you anyway for your time!!
I may just have to convert these by hand for now...but I will keep trying.

Best,

Babs

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
Community Expert ,
Feb 24, 2018 Feb 24, 2018

Copy link to clipboard

Copied

iBabs2  wrote

… I tried taking both of your options, placing the code into a text edit program, removing the line numbers, and saving as a .jsx file.

Hi Babs,

go to the forum, do not copy/paste code from a recieved mail.


If you copy/paste my code when logged in to the forum you will not get the line numbers.
Therefore—I hope—you get in no trouble changing something in the process of copy/paste code.

Make sure that the file you paste the code is pure text. Best you do this with the ExtendScript Toolkit app.

To run my code successfully just select some text that includes exactly one text variable.

The one that you want to convert to text. All instances of this text variable will then be converted to text.

Regards,
Uwe

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
Enthusiast ,
Feb 24, 2018 Feb 24, 2018

Copy link to clipboard

Copied

Hello Laubender,

Gotcha...So far, I have not gotten into any trouble...just not successful.

I just downloaded the Extendscript toolkit..Thank You...... I will start looking for tutorials and lessons on how to use it.. I just need to really take the time to sit with it.. Working 3 jobs right now, make the time issue challenging, but this is the only area I really struggle with..Scripting... and it is the one I really need to focus on...

Appreciate all the help and guidance...

Babs

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
Enthusiast ,
Mar 17, 2023 Mar 17, 2023

Copy link to clipboard

Copied

I created a script very similar to what was suggested here butI wrapped mine in a doScript so that there aren't hundreds of Undos in a document. This only expands the variables to text.

function idExpandTextVar(txtVar) {
  function main(txtVar) {
    aInt = app.activeDocument.textVariables.item(txtVar).associatedInstances;
    lng = aInt.length;
    for (i = 0; i < lng; i++) {
      aInt[i].convertToText();
    }
  }
  //Put the do script in here so it always has 1 undo
  app.doScript("main('" + txtVar + "')", ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, txtVar + " Expanded")
}
idExpandTextVar('Live Metadata Caption: Name');

 

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
Contributor ,
Sep 11, 2023 Sep 11, 2023

Copy link to clipboard

Copied

LATEST

Brilliant!

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