Mobile app version of vmapp.org
Login or Join
Connie430

: SpecialCharacters.PAGE_BREAK compare against TextFrame.contents var myStories = app.activeDocument.stories.everyItem().getElements(); for (i = myStories.length - 1; i >= 0; i--){ var myTextFrames

@Connie430

Posted in: #AdobeIndesign #IndesignScripting

var myStories = app.activeDocument.stories.everyItem().getElements();
for (i = myStories.length - 1; i >= 0; i--){
var myTextFrames = myStories[i].textContainers;
$.writeln(myTextFrames.length);
for (j = myTextFrames.length - 1; j >= 0; j--) {
$.writeln(myTextFrames[j].contents);
if (myTextFrames[j].contents == SpecialCharacters.PAGE_BREAK){
$.writeln("test hier");
myTextFrames[j].remove();
}
}
}


why does this not work? I guess because the SpecialCharacters.PAGE_BREAK is a number but I cannot make it work, I tried so much.

The condition gets never true even if there only a pagebreak in the textframe.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Connie430

2 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo857

I think I get what you are looking for but mdomino is right. You did not ask any question. To check if your textframe or story has a SpecialCharacters.PAGE_BREAK character you cant compare the whole contents of a textFrame. You need to examine each character on its own. This code should get do what you want.

var doc = app.activeDocument;
var story = doc.stories[0];
for(var i = 0; i < story.characters.length; i++) {
if(story.characters.item(i).contents === SpecialCharacters.PAGE_BREAK) {
$.writeln('found the page break SpecialCharacters.PAGE_BREAK at index ' + i);
}
}

10% popularity Vote Up Vote Down


 

@Cofer715

Reading the contents property seems to only return string objects. I am not sure why exactly that is the case, but the SpecialCharacters can be used for writing only in a script context (somebody correct me, if I am wrong, please). So the most simple way to check for a single page break in a text frame would be to simply check for a break in that frame:

if(myTextFrames[j].contents === "r")


Note that this will also return true for column breaks, frame breaks etc. If you need to find page breaks only, I think you need to script a GREP search for page breaks, which would be a bit more involved.

Btw. it would be nice, if you could ask your question with an actual explanation of your problem and what the code is supposed to do, instead of only pasting some code and asking, why it does not work. People are much more likely to help you, if you help them understand your problem quickly.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme