Skip to main content
Known Participant
May 4, 2012
Answered

[JS][CS5] finding instances of a Paragraph style, and doing something to the parentTextFrame

  • May 4, 2012
  • 1 reply
  • 851 views

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..

This topic has been closed for replies.
Correct answer Dave_Saunders

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

1 reply

Dave_SaundersCorrect answer
Inspiring
May 4, 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

PrntScrAuthor
Known Participant
May 4, 2012

Thanks a lot Dave!

It works. Have a great friday!