Different ways of counting characters in Indesign using javascript
I'm writing a javascript program to handle each character intо Indesign document.
To begin with, I wrote two different ways of counting characters, which for some reason give different results for large documents. Why?
var
myDocument, docStories, docCharacters,
docFootnotesCharacters, docTablesCharacters;
myDocument = app.activeDocument;
var TotalChars = 0;
// Fisrt way
docStories = myDocument.stories.everyItem();
docCharacters = docStories.characters.length;
docFootnotesCharacters = docStories.footnotes.everyItem().characters.length;
docTablesCharacters = docStories.tables.everyItem().cells.everyItem().characters.length;
statReport = ;
// Second way
for ( j = 0; j < myDocument.stories.length; j++ ) {
myStory = myDocument.stories.item(j);
var Frames = myStory.textContainers;
for ( i = 0; i < Frames.length; i++ ) {
var Frame = Frames[i];
for (var TextCnt = 0; TextCnt < Frame.texts.length; TextCnt++) {
CurrentText = Frame.texts.item(TextCnt);
TotalChars += CurrentText.characters.length;
}
for (var TableCnt = 0; TableCnt < Frame.tables.length; TableCnt++) {
var CurrentTable = Frame.tables.item(0);
for ( var CellCnt = 0; CellCnt < CurrentTable.cells.length; CellCnt++ ) {
var CurrentCell = CurrentTable.cells.item(CellCnt);
TotalChars += CurrentCell.characters.length;
}
}
for (var FootNoteCnt = 0; FootNoteCnt < Frame.footnotes.length; FootNoteCnt++) {
var CurrentFootNote = Frame.footnotes.item(0);
TotalChars += CurrentFootNote.characters.length;
}
}
}
statReport.push ( "Characters: " + ( docCharacters + docFootnotesCharacters + docTablesCharacters ) );
statReport.push ( "TotalChars: " + TotalChars );
alert ( statReport.join ( "r" ), "Document Text Statistic" );
javascript indesign
add a comment |
I'm writing a javascript program to handle each character intо Indesign document.
To begin with, I wrote two different ways of counting characters, which for some reason give different results for large documents. Why?
var
myDocument, docStories, docCharacters,
docFootnotesCharacters, docTablesCharacters;
myDocument = app.activeDocument;
var TotalChars = 0;
// Fisrt way
docStories = myDocument.stories.everyItem();
docCharacters = docStories.characters.length;
docFootnotesCharacters = docStories.footnotes.everyItem().characters.length;
docTablesCharacters = docStories.tables.everyItem().cells.everyItem().characters.length;
statReport = ;
// Second way
for ( j = 0; j < myDocument.stories.length; j++ ) {
myStory = myDocument.stories.item(j);
var Frames = myStory.textContainers;
for ( i = 0; i < Frames.length; i++ ) {
var Frame = Frames[i];
for (var TextCnt = 0; TextCnt < Frame.texts.length; TextCnt++) {
CurrentText = Frame.texts.item(TextCnt);
TotalChars += CurrentText.characters.length;
}
for (var TableCnt = 0; TableCnt < Frame.tables.length; TableCnt++) {
var CurrentTable = Frame.tables.item(0);
for ( var CellCnt = 0; CellCnt < CurrentTable.cells.length; CellCnt++ ) {
var CurrentCell = CurrentTable.cells.item(CellCnt);
TotalChars += CurrentCell.characters.length;
}
}
for (var FootNoteCnt = 0; FootNoteCnt < Frame.footnotes.length; FootNoteCnt++) {
var CurrentFootNote = Frame.footnotes.item(0);
TotalChars += CurrentFootNote.characters.length;
}
}
}
statReport.push ( "Characters: " + ( docCharacters + docFootnotesCharacters + docTablesCharacters ) );
statReport.push ( "TotalChars: " + TotalChars );
alert ( statReport.join ( "r" ), "Document Text Statistic" );
javascript indesign
Different how? is it consistently larger or smaller?
– cybernetic.nomad
Dec 19 '18 at 19:24
In your second method I notice this:var CurrentFootNote = Frame.footnotes.item(0)
, should it not bevar CurrentFootNote = Frame.footnotes.item(FootNoteCnt)
?
– cybernetic.nomad
Dec 19 '18 at 19:25
Thanks for your help. I was inattentive. The same error with tables Frame.tables.item(0);
– nkp07
Dec 20 '18 at 16:41
add a comment |
I'm writing a javascript program to handle each character intо Indesign document.
To begin with, I wrote two different ways of counting characters, which for some reason give different results for large documents. Why?
var
myDocument, docStories, docCharacters,
docFootnotesCharacters, docTablesCharacters;
myDocument = app.activeDocument;
var TotalChars = 0;
// Fisrt way
docStories = myDocument.stories.everyItem();
docCharacters = docStories.characters.length;
docFootnotesCharacters = docStories.footnotes.everyItem().characters.length;
docTablesCharacters = docStories.tables.everyItem().cells.everyItem().characters.length;
statReport = ;
// Second way
for ( j = 0; j < myDocument.stories.length; j++ ) {
myStory = myDocument.stories.item(j);
var Frames = myStory.textContainers;
for ( i = 0; i < Frames.length; i++ ) {
var Frame = Frames[i];
for (var TextCnt = 0; TextCnt < Frame.texts.length; TextCnt++) {
CurrentText = Frame.texts.item(TextCnt);
TotalChars += CurrentText.characters.length;
}
for (var TableCnt = 0; TableCnt < Frame.tables.length; TableCnt++) {
var CurrentTable = Frame.tables.item(0);
for ( var CellCnt = 0; CellCnt < CurrentTable.cells.length; CellCnt++ ) {
var CurrentCell = CurrentTable.cells.item(CellCnt);
TotalChars += CurrentCell.characters.length;
}
}
for (var FootNoteCnt = 0; FootNoteCnt < Frame.footnotes.length; FootNoteCnt++) {
var CurrentFootNote = Frame.footnotes.item(0);
TotalChars += CurrentFootNote.characters.length;
}
}
}
statReport.push ( "Characters: " + ( docCharacters + docFootnotesCharacters + docTablesCharacters ) );
statReport.push ( "TotalChars: " + TotalChars );
alert ( statReport.join ( "r" ), "Document Text Statistic" );
javascript indesign
I'm writing a javascript program to handle each character intо Indesign document.
To begin with, I wrote two different ways of counting characters, which for some reason give different results for large documents. Why?
var
myDocument, docStories, docCharacters,
docFootnotesCharacters, docTablesCharacters;
myDocument = app.activeDocument;
var TotalChars = 0;
// Fisrt way
docStories = myDocument.stories.everyItem();
docCharacters = docStories.characters.length;
docFootnotesCharacters = docStories.footnotes.everyItem().characters.length;
docTablesCharacters = docStories.tables.everyItem().cells.everyItem().characters.length;
statReport = ;
// Second way
for ( j = 0; j < myDocument.stories.length; j++ ) {
myStory = myDocument.stories.item(j);
var Frames = myStory.textContainers;
for ( i = 0; i < Frames.length; i++ ) {
var Frame = Frames[i];
for (var TextCnt = 0; TextCnt < Frame.texts.length; TextCnt++) {
CurrentText = Frame.texts.item(TextCnt);
TotalChars += CurrentText.characters.length;
}
for (var TableCnt = 0; TableCnt < Frame.tables.length; TableCnt++) {
var CurrentTable = Frame.tables.item(0);
for ( var CellCnt = 0; CellCnt < CurrentTable.cells.length; CellCnt++ ) {
var CurrentCell = CurrentTable.cells.item(CellCnt);
TotalChars += CurrentCell.characters.length;
}
}
for (var FootNoteCnt = 0; FootNoteCnt < Frame.footnotes.length; FootNoteCnt++) {
var CurrentFootNote = Frame.footnotes.item(0);
TotalChars += CurrentFootNote.characters.length;
}
}
}
statReport.push ( "Characters: " + ( docCharacters + docFootnotesCharacters + docTablesCharacters ) );
statReport.push ( "TotalChars: " + TotalChars );
alert ( statReport.join ( "r" ), "Document Text Statistic" );
javascript indesign
javascript indesign
edited Jan 2 at 22:42
usr2564301
17.8k73370
17.8k73370
asked Dec 19 '18 at 15:45
nkp07nkp07
1
1
Different how? is it consistently larger or smaller?
– cybernetic.nomad
Dec 19 '18 at 19:24
In your second method I notice this:var CurrentFootNote = Frame.footnotes.item(0)
, should it not bevar CurrentFootNote = Frame.footnotes.item(FootNoteCnt)
?
– cybernetic.nomad
Dec 19 '18 at 19:25
Thanks for your help. I was inattentive. The same error with tables Frame.tables.item(0);
– nkp07
Dec 20 '18 at 16:41
add a comment |
Different how? is it consistently larger or smaller?
– cybernetic.nomad
Dec 19 '18 at 19:24
In your second method I notice this:var CurrentFootNote = Frame.footnotes.item(0)
, should it not bevar CurrentFootNote = Frame.footnotes.item(FootNoteCnt)
?
– cybernetic.nomad
Dec 19 '18 at 19:25
Thanks for your help. I was inattentive. The same error with tables Frame.tables.item(0);
– nkp07
Dec 20 '18 at 16:41
Different how? is it consistently larger or smaller?
– cybernetic.nomad
Dec 19 '18 at 19:24
Different how? is it consistently larger or smaller?
– cybernetic.nomad
Dec 19 '18 at 19:24
In your second method I notice this:
var CurrentFootNote = Frame.footnotes.item(0)
, should it not be var CurrentFootNote = Frame.footnotes.item(FootNoteCnt)
?– cybernetic.nomad
Dec 19 '18 at 19:25
In your second method I notice this:
var CurrentFootNote = Frame.footnotes.item(0)
, should it not be var CurrentFootNote = Frame.footnotes.item(FootNoteCnt)
?– cybernetic.nomad
Dec 19 '18 at 19:25
Thanks for your help. I was inattentive. The same error with tables Frame.tables.item(0);
– nkp07
Dec 20 '18 at 16:41
Thanks for your help. I was inattentive. The same error with tables Frame.tables.item(0);
– nkp07
Dec 20 '18 at 16:41
add a comment |
1 Answer
1
active
oldest
votes
In the second method, you're counting all the characters inside text frames in the story. But stories can be overset (the text overflows). The first method will count overset text (because you're counting the characters in a story, but the second method will ignore those, because it's only counting characters in story frames.
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– Michel
Dec 31 '18 at 16:16
2
Of course it answers the question. The question was why do the 2 methods give different answers. The answer is precisely as stated.
– Ariel
Jan 1 at 1:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53854677%2fdifferent-ways-of-counting-characters-in-indesign-using-javascript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In the second method, you're counting all the characters inside text frames in the story. But stories can be overset (the text overflows). The first method will count overset text (because you're counting the characters in a story, but the second method will ignore those, because it's only counting characters in story frames.
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– Michel
Dec 31 '18 at 16:16
2
Of course it answers the question. The question was why do the 2 methods give different answers. The answer is precisely as stated.
– Ariel
Jan 1 at 1:53
add a comment |
In the second method, you're counting all the characters inside text frames in the story. But stories can be overset (the text overflows). The first method will count overset text (because you're counting the characters in a story, but the second method will ignore those, because it's only counting characters in story frames.
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– Michel
Dec 31 '18 at 16:16
2
Of course it answers the question. The question was why do the 2 methods give different answers. The answer is precisely as stated.
– Ariel
Jan 1 at 1:53
add a comment |
In the second method, you're counting all the characters inside text frames in the story. But stories can be overset (the text overflows). The first method will count overset text (because you're counting the characters in a story, but the second method will ignore those, because it's only counting characters in story frames.
In the second method, you're counting all the characters inside text frames in the story. But stories can be overset (the text overflows). The first method will count overset text (because you're counting the characters in a story, but the second method will ignore those, because it's only counting characters in story frames.
edited Jan 1 at 1:55
answered Dec 31 '18 at 0:05
ArielAriel
877
877
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– Michel
Dec 31 '18 at 16:16
2
Of course it answers the question. The question was why do the 2 methods give different answers. The answer is precisely as stated.
– Ariel
Jan 1 at 1:53
add a comment |
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– Michel
Dec 31 '18 at 16:16
2
Of course it answers the question. The question was why do the 2 methods give different answers. The answer is precisely as stated.
– Ariel
Jan 1 at 1:53
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– Michel
Dec 31 '18 at 16:16
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
– Michel
Dec 31 '18 at 16:16
2
2
Of course it answers the question. The question was why do the 2 methods give different answers. The answer is precisely as stated.
– Ariel
Jan 1 at 1:53
Of course it answers the question. The question was why do the 2 methods give different answers. The answer is precisely as stated.
– Ariel
Jan 1 at 1:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53854677%2fdifferent-ways-of-counting-characters-in-indesign-using-javascript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Different how? is it consistently larger or smaller?
– cybernetic.nomad
Dec 19 '18 at 19:24
In your second method I notice this:
var CurrentFootNote = Frame.footnotes.item(0)
, should it not bevar CurrentFootNote = Frame.footnotes.item(FootNoteCnt)
?– cybernetic.nomad
Dec 19 '18 at 19:25
Thanks for your help. I was inattentive. The same error with tables Frame.tables.item(0);
– nkp07
Dec 20 '18 at 16:41