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

Code to be evaluated! [015] Text Column Break! …

LEGEND ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

Hi all!

This code has a problem on the "rage" definition! … And I don't find why!! 

app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Column Jump! …");

function main()

    {      

        var myDoc = app.activeDocument,

        myStories = myDoc.stories.everyItem().getElements(),

        S = myStories.length,

        myCharStyle = myDoc.characterStyles.item("Red");

        for (var s = 0; s < S; s++) {

            app.findGrepPreferences = app.changeGrepPreferences = null;

            app.findGrepPreferences.findWhat = "~M";

            myColumnBreaks = myStories.findGrep();

            myStories.characters.itemByRange(0, myColumnBreaks[0].index).appliedCharacterStyle = myCharStyle;

        }

        app.findGrepPreferences = null;

    }

Thanks for help! 

(^/)

TOPICS
Scripting

Views

329

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

correct answers 1 Correct answer

People's Champ , Mar 02, 2017 Mar 02, 2017

Nothing really problematic to me at first sight. You may not want to set the grep find preferences every loop though.

app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Column Jump! …"); 

 

 

function main() 

{        

  var myDoc = app.activeDocument, 

  myStories = myDoc.stories.everyItem().getElements(), 

  S = myStories.length, 

  myCharStyle = myDoc.characterStyles.itemByName("Red"); 

  app.findGrepPreferences = app.changeGrepPreferences = null; 

  app.fin

...

Votes

Translate

Translate
People's Champ ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

Nothing really problematic to me at first sight. You may not want to set the grep find preferences every loop though.

app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Column Jump! …"); 

 

 

function main() 

{        

  var myDoc = app.activeDocument, 

  myStories = myDoc.stories.everyItem().getElements(), 

  S = myStories.length, 

  myCharStyle = myDoc.characterStyles.itemByName("Red"); 

  app.findGrepPreferences = app.changeGrepPreferences = null; 

  app.findGrepPreferences.findWhat = "~M"; 

  for (var s = 0; s < S; s++) { 

  myColumnBreaks = myStories.findGrep(); 

  myColumnBreaks.length>0 && myStories.characters.itemByRange(0, myColumnBreaks[0].index).appliedCharacterStyle = myCharStyle; 

  } 

  app.findGrepPreferences = null; 

what's the issue exactly ?

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
LEGEND ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

Hi Loïc,

You're right!

I've just fixed it with:

if (myColumnBreaks.length !== 0) myStories.characters.itemByRange(0, myColumnBreaks[0].index-1).appliedCharacterStyle = myCharStyle;

… because there's a story on master pages!

But I prefer yours:

myColumnBreaks.length>0 && myStories.characters.itemByRange(0, myColumnBreaks[0].index).appliedCharacterStyle = myCharStyle;   

… And you're totally right about to set the Grep find prefs out of the loop!

Thanks! 

(^/)

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
People's Champ ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

Hi

… because there's a story on master pages!

Then you should be concerned by

app.findChangeGrepOptions

But I prefer yours:

Not an absolute. Think it avoids an internal scope (if).

… And you're totally right about to set the Grep find prefs out of the loop!

It just doesn't make sense.

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
LEGEND ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

LATEST

Loïc,

I could but I could have "blank" pages with empty story among the current pages too. So I prefer your way!

Yes, I often forget this point! Use yours is, for my little brain, a better writing to debug a script (in this case).

This is, imho, "intellectually", more interesting!

Thanks for all! I'm always a newbie but I make efforts! Aha!

(^/) 

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