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..
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
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
Copy link to clipboard
Copied
Thanks a lot Dave!
It works. Have a great friday!