Skip to main content
Known Participant
October 9, 2022
Question

Indesign Server Script find/change based on ParagraphStyle

  • October 9, 2022
  • 2 replies
  • 987 views

Hello, I am working with IDS and I need a script that allows me to change the style based on the text and the paragraph style applied.  Does anyone has something working like this on IDS ? So far the script I had it's not working, and can't find a good way to solve this. When I do a search by pagrapthStyle, the script I am using just fails:

var originalParaStyle = "Style1";
var changedParaStyle = "NewStyle";
        
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
if (findWhat) app.findTextPreferences.findWhat = findWhat;
if (changeTo) app.changeTextPreferences.changeTo = changeTo;
        
app.findTextPreferences.appliedParagraphStyle = originalParaStyle;
app.changeTextPreferences.appliedParagraphStyle = changedParaStyle;
    
if (findChrStyle) app.findTextPreferences.appliedCharacterStyle = findChrStyle;
if (changeChrStyle) app.changeTextPreferences.appliedCharacterStyle = changeChrStyle;

doc.changeText();

The part where it fails it's when I set the appliedParagraphStyle. If the property is set empty, the script works, but with other value it just make IDS to reboot.  I have tried setting is as String and ParagraphStyle path, but doesn't work.

If anyone has a working script for IDS that let's you change the ParagraphStyle of a text, of has any idea on how to overcome this, it would be really helpful.

Thanks!

This topic has been closed for replies.

2 replies

brian_p_dts
Community Expert
Community Expert
October 9, 2022

Your if statements confuse me. I assume this is a snippet of a larger script (since you use a doc variable at the end). Can you post more of the code?

Known Participant
October 10, 2022

Hi, this is the function I am currently using. It's a findChange script. I've tried setting both the Object and the String of the paragraphStyle, but still happens the same. It works on Indesign in the same document.

function findChange(findWhat, changeTo) {
    var doc = app.documents[0];

    var originalParaStyle = "Style1";
    var changedParaStyle = "NewStyle";
    
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
    if (findWhat) app.findTextPreferences.findWhat = findWhat;
    if (changeTo) app.changeTextPreferences.changeTo = changeTo;
    
    app.findTextPreferences.appliedParagraphStyle = originalParaStyle;
    app.changeTextPreferences.appliedParagraphStyle = changedParaStyle;

    doc.changeText();
}

 THanks!

Community Expert
October 9, 2022
  • Can you try using this on desktop version of InDesign.
  • You say you tried with ParagraphStyle path, what does it mean? Did you try using the paragraphStyle object in place of string?
  • Do you any logs in the IDS console/log before crash?
  • Does the style exist in the document?

-Manan

-Manan
Known Participant
October 10, 2022

I have used it on InDesign and it works. It's a classic find/replace script that its around.

I used both ParagraphStyle Object and String, same issue.

There are no logs, just IDS rebooting itself (I am looking events on Event Viewer).

The style exists in the Template and the Word Document.