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

Apply a noBreak with javascript

New Here ,
Dec 10, 2008 Dec 10, 2008
I am trying to apply a no break to a currency sign followed by numbers.
I tryed this javascript. But nothing seems to change in the textframe that I selected before running this script:

var txt = app.selection[0].parentStory.contents;
var myfound = txt.match( /( \d\d?\d?)(\.\d\d\d)?(\.\d\d\d)?(\.\d\d\d)?(\,)(\d\d)/g );
if( myfound != null )
{
for( var i = 0; i < myfound.length; i++ )
{
myfound.noBreak = true;
}
}

Is there something missing?

Please excuse my poor english.

P.S. if i select only the sign and the digits, instead of the textframe, and run

app.selection[0].noBreak = true;

it will work great.
TOPICS
Scripting
891
Translate
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 ,
Dec 10, 2008 Dec 10, 2008
nilom,

There's nothing wrong with your regular expression, it works fine, though you make things unnecessarily complicated. You might as well use this one:
>var myfound = txt.match( /( [\d.,]+)/g );

which does the same. But the reason why it doesn't work is that with your regular expression you collect an array (myfound), and then apply something to that array -- apply noBreak. This has no effect on the array at all (because noBreak is relevant to InDesign objects, not to arrays of strings), and your InDesign document is unaffected.

Before we go on it is useful to know which version of InDesign you use (CS 2, 3, or 4).

Peter
Translate
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
New Here ,
Dec 10, 2008 Dec 10, 2008
oh Peter,
i got running just a few days ago with javascript, thanks to you three books i bought from oreally:
AutomatingInDesignwithRegularExpressions; GREPinInDesignCS3CS4;ScriptingInDesignwithJavaScript.
Fantastic and clear (considering that I am a newbie).
I didn't expect an answer from you and I'm glad.

Excuse my ot and let's answer.

I'm using InDesign CS 3

Thank you.

Nilom
Translate
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 ,
Dec 10, 2008 Dec 10, 2008
Thanks for your kind words. As to your script, you were caught up in big changes between CS2 and CS3/4. Your approach (approaching InDesign stories as text) was going the CS2 way, which was the only way to go because CS2 did not know GREP natively. But CS3 and CS4 do know GREP natively, which make many things a lot easier. What you want to do ca\n be scripted in CS3 as follows:
app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.findWhat = " [\\d.,]+";
app.changeGrepPreferences.noBreak = true;
app.activeDocument.changeGrep();


The O'Reilly titles aren't clear on this -- yet. They soon will be.

Peter
Translate
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
New Here ,
Dec 11, 2008 Dec 11, 2008
LATEST
Thank you so much.

Works perfect (don't need to tell you)

nilom
Translate
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