How to select all note reference and make change to them?

Get help using and writing Nisus Writer Pro macros.
Post Reply
Nobumi Iyanaga
Posts: 158
Joined: 2007-01-17 05:46:17
Location: Tokyo, Japan
Contact:

How to select all note reference and make change to them?

Post by Nobumi Iyanaga »

Hello,

Here is what I would like to achieve:
Select all the note references (in the main text and notes);
changes their font
add a space after the note reference in the notes.

Could anyone show me how to do this?

Thank you very much in advance!

Best regard,

Nobumi Iyanaga
Tokyo,
Japan
Best regards,

Nobumi Iyanaga
Tokyo,
Japan
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: How to select all note reference and make change to them?

Post by Þorvarður »

Hello,
You can do this with the commands: [1] Select Next Note Reference and [2] Select Note Text number


# This macro will first allow you to change the font for note references in the document, then it will add a space after the note reference in the notes.
View:Page View
# Just in case the insertion point happens to be in the last note. This will put the insertion point in the main document.
Find @Text<(?:.|\n|\f)>, 'E', '-n'
Select All
Select Start
Select Next Note Reference
$doesThisDocumentHaveFootnotes = Selection Length
if $doesThisDocumentHaveFootnotes == 0
Prompt 'Oops…This document has neither footnotes nor endnotes!', '', 'Abort', ''
exit
end
$font = Prompt Input 'Choose the font you want for the note references in the document …','', 'OK', 'Times'
Select All
Select Start
$count = 0

While Select Next Note Reference
Set Font Name $font
$count = $count +1 # This will find out how many footnotes are in the document
End

while $count > 0
Select Note Text $count # We start with the last footnote and end with the 1st footnote
Select Start
Type Text " " # one space inserted
$count = $count-1
end
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to select all note reference and make change to them?

Post by phspaelti »

While Þorvarður's approach is one way to go, you can really do things much more simply.

First, note (pun :lol: ) that you have the character styles "Note Reference" and "Note Reference in Note". If you want to change the font of these things, just make a change to those character styles.

Second, for inserting a space (or some other character) after the Note References in the Notes, you can use a macro like this (for demo purposes this inserts an em-dash):

Code: Select all

$doc = Document.active
$notes = $doc.allNotes
foreach $note in $notes
$note.fullText.insertAtIndex $note.fullTextReferenceRange.bound, '—'
end
philip
Nobumi Iyanaga
Posts: 158
Joined: 2007-01-17 05:46:17
Location: Tokyo, Japan
Contact:

Re: How to select all note reference and make change to them?

Post by Nobumi Iyanaga »

Thank you very much, Þorvarður and phspaelti, for your respective solutions.

Þorvarður's macro worked well for me -- except that for some reason that I don't understand, it inserted 208 extra spaces after the first note reference in note (there are 207 notes in all in the document).

phspaelti's macro worked very well -- much quicker than Þorvarður's, and it did not inserted extra spaces. But as to the change of the styles, that did not work. One thing is that I find is that it seems there is no way to force apply a style defined in the style view to the actual texts in the document. But I am not sure if such a feature is implemented, that would be useful. Useful perhaps only for note references in the texts and in the notes...

One thing that I should have added to my original request was that I wanted to insert a space after the note reference in note IF there was no space there. -- But in fact, I am not sure if it is possible to recognize in a macro if a space follows a note reference in note, if this space is added there according the style defined in the style view, in the footnote style, as the "Default note text"; anyway, it seems it is impossible to select this space as a separate character...

Thank you very much anyway.
Best regards,

Nobumi Iyanaga
Tokyo,
Japan
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to select all note reference and make change to them?

Post by phspaelti »

Nobumi Iyanaga wrote: 2018-03-17 15:33:58 One thing that I should have added to my original request was that I wanted to insert a space after the note reference in note IF there was no space there. -- But in fact, I am not sure if it is possible to recognize in a macro if a space follows a note reference in note, if this space is added there according the style defined in the style view, in the footnote style, as the "Default note text"; anyway, it seems it is impossible to select this space as a separate character...
Of course it is possible to do this in a macro. In fact I kind of thought that you might want to do this and should have written the macro that way. I was just too lazy :)
I'm not sure why you say that it is impossible to select the space. Note Default Text is just that. It's just some text that Nisus inserts each time, and there is nothing special about it.
Anyhow here is an improved macro that checks before it inserts the text. You can adjust the default text in the macro.

Code: Select all

$doc = Document.active
#Default Note Text
$dnt = '. '
foreach $note in $doc.allNotes
  $loc = $note.fullTextReferenceRange.bound
  $r = Range.new $loc, $dnt.length
  $bit = $note.fullText.substringInRange $r
  if $bit != $dnt
    $note.fullText.insertAtIndex $loc, $dnt
  end
end
philip
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to select all note reference and make change to them?

Post by phspaelti »

Nobumi Iyanaga wrote: 2018-03-17 15:33:58 But as to the change of the styles, that did not work. One thing is that I find is that it seems there is no way to force apply a style defined in the style view to the actual texts in the document. But I am not sure if such a feature is implemented, that would be useful. Useful perhaps only for note references in the texts and in the notes...
Are you saying that your note references have a style applied "by hand"? That would of course override any attributes applied by style.
Here is yet another macro to select all the references in the notes. You can then apply (or remove) any formatting they might need.

Code: Select all

$doc = Document.active
$sels = Array.new
foreach $note in $doc.allNotes
$sels.push TextSelection.new($note.fullText, $note.fullTextReferenceRange)
end
$doc.setSelection $sels
And here's the same to select the note references in the text.

Code: Select all

$doc = Document.active
$sels = Array.new
foreach $note in $doc.allNotes
$sels.push TextSelection.new($note.documentText, $note.documentTextRange)
end
$doc.setSelection $sels
philip
Nobumi Iyanaga
Posts: 158
Joined: 2007-01-17 05:46:17
Location: Tokyo, Japan
Contact:

Re: How to select all note reference and make change to them?

Post by Nobumi Iyanaga »

Hello phspaelti,

Wow! Thank you very much! You satisfied all my requests.

Thank you so much again!
Best regards,

Nobumi Iyanaga
Tokyo,
Japan
Post Reply