Reply to topic  [ 24 posts ]  Go to page 1, 2  Next
How to display Character Count without multiple clicks 
Author Message

Joined: 2007-09-30 21:25:42
Posts: 17
Hi everyone,

I'm looking for a way to display the character count in a file (or selected table) in a simpler way than by opening Tools, clicking on the Pencil, and viewing the Stats. Basically I would like to use a Menu Key or even a Keyboard Maestro macro to save time using this repetitive action that I perform on a regular basis.

Can anyone help?

Japan Rich :)


2015-12-02 22:27:36
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Here a couple of ways to get at the character count quicker:

1. Use the menu Window > Palettes > Statistics to show the stats palette as a floating palette, without the tool drawer showing. If you like this arrangement, you can keep it floating all the time and it will update to give information about the frontmost document.
2. Run the attached macro.

Naturally you could assign either of these a custom keyboard shortcut using our Menu Key preferences, for even easier access. I hope that helps!

One final note: these two methods may show different character counts. The stats palette does not count some ancillary text areas like table cells and footnotes, while the macro does.


Attachments:
Character Counts.nwm [3.96 KiB]
Downloaded 43 times
2015-12-02 23:19:04
Profile WWW

Joined: 2007-09-30 21:25:42
Posts: 17
Martin,

Thank you so much for the "Character Counts" macro! It is great that the macro also counts within tables.
That's just what I needed, and I assigned a shortcut to it and now I'm set.

Would it be too much to ask for a similar macro for "Word Count"?

Japan Rich


2015-12-03 15:07:52
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
JapanRich wrote:
Would it be too much to ask for a similar macro for "Word Count"?


Here's a macro that will give all the stats (character count, word count, paragraph count) in one window:
[Removed: see below]

_________________
philip


Last edited by phspaelti on 2015-12-05 08:43:39, edited 1 time in total.



2015-12-03 21:18:24
Profile

Joined: 2007-09-30 21:25:42
Posts: 17
Many, many thanks for this macro that includes word count and character count in the Statistics!
I've already set Menu Keys for the Palette and this Macro.
Much appreciated!

Japan Rich


2015-12-03 21:23:12
Profile

Joined: 2007-09-30 21:25:42
Posts: 17
A request for modification of the Document Statistics macro.

I selected text across cells in a table, and the macro didn't work, citing:

'There was an error on line 22 in the macro "Document Statistics".

Expected a TextSelection object, not a Selection object.'

This is line 22 in the macro:

$doc.setSelection $docSelection

---
Is it possible for the macro to accommodate both? Or are separate macros needed depending on whether the selection is from a table or not?
Thanks for your attention to this matter! I'm really impressed.
Japan Rich


2015-12-04 22:44:47
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Hello Rich,
I must say that I didn't spend much time testing the macro before posting it here. Sorry!

That said I can (a) confirm that it does fail as you say, and (b) admit that I am completely baffled by this error. The point that is baffling is that the instruction that fails is executed twice before "Line 22" and succeeds without complaint. I fail to understand what the problem is the third time around. The error message too is no help, since the ".setSelection" command should, and usually does, allow for a "Selection object".

I'll have to see what can be done about this.

[One simple temporary fix is to quote out lines 22, 23 and 32. This eliminates the reporting of the number of paragraphs in the selection, but otherwise works.]

_________________
philip


2015-12-05 01:02:03
Profile

Joined: 2007-09-30 21:25:42
Posts: 17
Philip,

I never need to know the number of paragraphs in a selection, only the character or word count, so if you are able to modify the macro to "quote out lines 22, 23 and 32", that would certainly suit my purposes!

Japan Rich


2015-12-05 02:54:10
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Here is:
[removed: see below]

_________________
philip


Last edited by phspaelti on 2015-12-05 08:44:22, edited 1 time in total.



2015-12-05 03:30:24
Profile

Joined: 2007-09-30 21:25:42
Posts: 17
The revised Document Statistics macro displays the count in BOTH selection and document at the same time!
Excellent, thank you so much! I wonder how many Nisus users could use this macro!

Japan Rich


2015-12-05 03:49:38
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Okay, I figured out how to fix the problem.
Attachment:
Document Statistics.nwm [4.49 KiB]
Downloaded 38 times

_________________
philip


2015-12-05 08:45:27
Profile

Joined: 2012-12-19 05:02:52
Posts: 225
Hello Philip et al.,

There are scenarios where I need to see how much text the first, let's say, 6500 words of a document amounts to (the word number may differ), and how many pages it will require. If I do this manually, I have to select the text several times, until I finally find the exact number.

How can I select the first 6500 words of a document with a macro?

I tried the following crude macro, but it takes far too much time to complete. And why does the counter have to start with 21, if I want to find the first 6500 words, and with 5 if I want to find the first 1500?

Code:
Select All
Select Start
$counter = 21
While $counter <6500
   Find @Text<(?:\b\w+\b)>, 'E'
   Format:Text Color:Red
   $counter = $counter + 1
End

Þorvarður


2015-12-06 06:13:16
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Þorvarður wrote:
How can I select the first 6500 words of a document with a macro


Code:
$doc = Document.active
$words = $doc.text.findAll @Text<(?:\b\w+\b)>, 'E'
if $words.count > 6500
     $sel = TextSelection.new $doc.text, Range.new (0, $words[6500].bound)
      $doc.setSelection $sel
else
      Prompt 'This document has only ' & $words.count & ' words'
end


It might seem counter-intuitive that it's much faster to look for all the words and then just select the first 6500 of them, but that's the way it is.
Actually the real problem with your approach is that you are doing all that applying of red to the words one at a time, and doing it using regular "Find" in a loop.

_________________
philip


2015-12-06 08:28:21
Profile

Joined: 2012-12-19 05:02:52
Posts: 225
Grüezi Philip,

As always, thank you very much for your help. This is what I was looking for.

There seems to be a slight aberration though, because the macro selects 6,525 words instead of 6,500. If I want just 2 words selected and change the macro accordingly, I get 3 words selected instead of 2. This may increase proportionally, depending on which number I choose, but I have not looked closely into this yet to find a pattern.


2015-12-06 14:35:36
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Actually what you will find is that the deviation is not proportional. The deviation where the macro selects 3 words instead of 2 is actually a "bug". Note that my original macro says $word[6500]. Since arrays are indexed from 0 this actually means that the macro should select 6501 words, not 6500. So as written the macro will always select one "word" extra. But any other deviations that you will find have to do with issues of the definition of "word", but also other technical differences which I am not even entirely sure about.

Consider the following example:
Attachment:
Regular Word Count Test file.rtf [91.04 KiB]
Downloaded 30 times


The above file has 30 completely regular paragraphs with 5 * 100 word sentences of the form "Text text … text." for a word count total of 15,000. If you use the built-in document statistics you might find a word count of 14,910! If you try the "Select 6500 first words" macro then you should see that it selects 13 full paragraphs plus the first word of the 14th. The built-in stats report "6,462 words and 13 paragraphs", while my "Document Statistics" macro reports "6,501 words and 14 paragraphs".

Finally as another test, let's try the Nisus Macro Language Reference.
The "Select 6500 first words" macro will select all the way up to:
Quote:
Set Fixed Line Height points v2.0.7
Changes the paragraph’s line height to

in the section "Commands > Formatting Text".
The built-in stats will report "5,675 words 533 paragraphs", the "Document Statistics" macro "6,430 words 647 paragraphs". Obviously the built-in stats live in a different universe, but why the disagreement with the "Document Statistics" macro? Who knows? The file we're checking contains many tables, and other types of 'broken-up' text as well as many 'strange' words. If you want to know exactly what's going on you can try the following modified version of the "Select 6500 first words" macro:

Code:
$doc = Document.active
$words = $doc.text.findAll @Text<\w+>, 'E'
if $words.count > 6500
   $words6500 = $words.subarrayInRange Range.new(0,6500)
   $doc.setSelection $words6500
else
   Prompt 'This document has only ' & $words.count & ' words'
end

This macro will select the "words" individually, and you see that the built-in stats now comes much closer. (For me it shows 6,499 words). One thing that I find baffling is that it selects some of the content of the table in the section "Indexing" which is beyond the main body text that has been selected. Don't understand this.

At this point I have to say that this is beyond the point that I care about.

_________________
philip


2015-12-06 15:56:56
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 24 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software