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

Search for Text in document and export

New Here ,
Jun 12, 2024 Jun 12, 2024

Copy link to clipboard

Copied

I get ewrror on the findtext, not sure how to fix
 
 
// Define the file path where you want to save the exported text
var exportFilePath = "C:\Users\270007378.RXLUSA\Documents\ExportedText.txt";

// Get the active document
var doc = app.activeDocument;

// Get the character style
var characterStyle = doc.characterStyles.itemByName(characterStyleName);

// Check if the character style exists
if (!characterStyle.isValid) {
    alert("Character style not found: " + characterStyleName);
    exit();
}

// Find all text with the specified character style
var foundTexts = doc.findText({
    appliedCharacterStyle: characterStyle
}, false);


// Collect the text content
var collectedText = "";
for (var i = 0; i < foundTexts.length; i++) {
    collectedText += foundTexts[i].contents + "\n";
}

// Write the collected text to a file
var file = new File(exportFilePath);
file.encoding = "UTF-8";
file.open("w");
file.write(collectedText);
file.close();

alert("Text exported to: " + exportFilePath);
TOPICS
UXP Scripting

Views

59

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 ,
Jun 12, 2024 Jun 12, 2024

Copy link to clipboard

Copied

LATEST

Seems the issue is with the findText method you have. That takes just a boolean argument. See

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html%23d1e49551__d1e54325

You would need to do something like the following

app.findTextPreferences = NothingEnum.NOTHING;
app.findTextPreferences.appliedCharacterStyle = characterStyle
var foundTexts = doc.findText()
app.findTextPreferences = NothingEnum.NOTHING;

-Manan

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