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

[JS][CS5.5] Syntax query

Explorer ,
May 18, 2012 May 18, 2012

Copy link to clipboard

Copied

Hi all

After another long gap I'm coming back to scripting again and I've probably forgotten most of what I learned here before. I'm trying to capture the contents of the first paragraph (which identifies what sort of article it is) so I can then analyse it and do different things depending on what it finds. I think I can do the analysis (famous last words!) but I'm stuck at the first hurdle.

If I use a para style to identify the first para (which obviously means I'd have to ask the client to style it) it works okay;

var myDoc = app.activeDocument;

//Find the first para in the story (which contains the article type)

app.findGrepPreferences.appliedParagraphStyle = "Identifier";

firstPara = myDoc.findGrep();

articleType = firstPara[0].contents;

alert(articleType);

But if I try to identify the first para using GREP (using app.findGrepPreferences.findWhat  = "\A^.+$";), which would be better as the para wouldn' thave to be styled, I get an "undefined is not an object error". Running a manual GREP search in ID with \A^.+$ finds the first para so it must be the syntax is wrong in my code.

Can anyone point out where I am going wrong please?

thanks,

Iain

TOPICS
Scripting

Views

640

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

Enthusiast , May 18, 2012 May 18, 2012

Should be app.findGrepPreferences.findWhat  = "\\A^.+$";

Votes

Translate

Translate
People's Champ ,
May 18, 2012 May 18, 2012

Copy link to clipboard

Copied

I'm not sure I've understood, but if you're just trying to get the first

paragraph of something, then, for example, given a story myStory, the

first paragraph would be

myStory.paragraphs[0]

or given a text selection:

mySelection = app.activeDocument.selection[0]

myFirstPara = mySelection.parentStory.paragraphs[0]

etc.

Ariel

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 ,
May 18, 2012 May 18, 2012

Copy link to clipboard

Copied

Should be app.findGrepPreferences.findWhat  = "\\A^.+$";

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
Explorer ,
May 18, 2012 May 18, 2012

Copy link to clipboard

Copied

LATEST

Aaargh! Thanks, I'd forgotten about having to escape that again. It works now.

Thanks also to Arïel - I'd forgotten about that method.

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