• 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] finding instances of a Paragraph style, and doing something to the parentTextFrame

Community Beginner ,
May 04, 2012 May 04, 2012

Copy link to clipboard

Copied

Hello,

From being helped earlier with looping through objects looking for a fill color, and then deleting found objects, I decided to try and reuse the loop for another purpose.

I'd like to loop through all stories in a document, finding those who have a particular paragraph style applied to them, and then 'climb out' using .parentTextFrame[0] to move the containing text frame.

Here's what I have:

Main();

function Main() {

    var doc = app.activeDocument;

    var stories = doc.stories;

    var STYLE = doc.paragraphStyles.item("STYLE");

    for (var i = stories.length-1; i >= 0; i--) {

        if (stories.appliedParagraphStyle == STYLE) stories.parentTextFrames[0].move([3,5]);

    }

}

The script executes but the frames don't move.

Changing 
"if (stories.appliedParagraphStyle == STYLE) stories.parentTextFrames[0].move([3,5]);"
to
"if (stories.appliedParagraphStyle == STYLE) stories.remove();"  
deletes the story.

I'm thankful for any help. Looks like this should work in theory, but obviously there is something wrong..

TOPICS
Scripting

Views

757

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

Advocate , May 04, 2012 May 04, 2012

You need: stories.paragraphs[0].parentTextFrames[0].move([3,5)];

or stories.textContainers[0].move([3,5]);

Stories don't have a parentTextFrames property, so when JavaScript sees that, it thinks you're creating a new property. I'm not sure why attempting to move it doesn't result in an error, but not getting errors when you think you should is all part of the JS experience.

Dave

Votes

Translate

Translate
Advocate ,
May 04, 2012 May 04, 2012

Copy link to clipboard

Copied

You need: stories.paragraphs[0].parentTextFrames[0].move([3,5)];

or stories.textContainers[0].move([3,5]);

Stories don't have a parentTextFrames property, so when JavaScript sees that, it thinks you're creating a new property. I'm not sure why attempting to move it doesn't result in an error, but not getting errors when you think you should is all part of the JS experience.

Dave

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
Community Beginner ,
May 04, 2012 May 04, 2012

Copy link to clipboard

Copied

LATEST

Thanks a lot Dave!

It works. Have a great friday!

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