NISUS Archives

April 2016

NISUS@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Nobumi Iyanaga <[log in to unmask]>
Reply To:
Date:
Thu, 14 Apr 2016 11:27:34 +0900
Content-Type:
text/plain
Parts/Attachments:
text/plain (161 lines)
Hello Philip,

Thank you very much for the good instruction. Yes, I could write this macro, which works very well. 
Thank you again for all your kind help!

-- But when I finished establishing my indexes, I finally generated the indexes -- and... I had to notice that they were all corrupted (strange characters added to each entry, bad alphabetical order, all the indexes generated at once, etc.). I tried to do the same thing with an earlier version of NWP, and it worked. But what is bad is that it is the document file itself which is corrupted, so that I have to remove all the indexes from the file, redo the same work, etc. with the earlier version.

Just now, I have no time to report this bug to Nisus, but I will do that as soon as I will finish my current work...!

Anyway, thank you so much for your good macros!

Best regard,

Nobumi Iyanaga
Tokyo,
Japan

> On Apr 13, 2016, at 12:34 PM, spaelti <[log in to unmask]> wrote:
> 
> Hello Nobumi,
> 
>> On 2016 Apr 13, at 09:42, Nobumi Iyanaga <[log in to unmask]> wrote:
>> 
>> Hello Philip,
>> 
>> Thank you very much again for your kind help! This works very well.
>> 
>> I just found that I need another functionality: that is, a text can be indexed in multiple index styles, and these texts must be found as well...
>> 
>> I think "$doc.textIndexStyleNames" should be used, but how…??
> 
> If you look at my macro you’ll see that the second line looks like this:
> $indexStyles = $doc.textIndexStyleNames
> 
> The macro doesn’t actually use this line. I apparently started something else and then forgot about it. But this is exactly what you need now.
> First let me make a small change:
> $indexNames = $doc.textIndexStyleNames
> 
> (I like to use good names for the variables, so I know what they are doing. I use temporary names when I write the macro then I go back and change the names to something else, when I understand how my macro works.)
> 
> Anyhow the variable $indexNames [plural!] will now contain the names of all the indexes in the document. So this variable is an array. To work with arrays the macro language has a convenient structure:
> 
> foreach $variable in $array
> …
> end
> 
> The name of $variable can be anything you like, but I like to use a singular version of the plural array name. This type of loop allows us to check each item in an array, one at a time.
> 
> Okay. Now that we want to work with all indexes, not just the active one, we get rid of the next line:
> $indexName = Active Text Index Name
> 
> The next place in the macro that we refer to the indexes is in the following line:
> $topic = $attr.textIndexTopicsForStyleName($indexName)
> 
> [NB: parentheses around an argument are mostly optional. I like to use them or leave them out, depending on what I find clearer.]
> 
> Since we have deleted the declaration of $indexName, we will have to fix that. We want to check not just one index, but all of them. We can do that with a foreach loop:
> foreach $indexName in $indexNames
>    $topic = $attr.textIndexTopicsForStyleName($indexName)
> end
> 
> This will check that stretch of text for topics. However we’re in a loop, and we keep piling the results into the same variable, thereby erasing earlier results. Index topics are complicated things; they are arrays of arrays (!). We’ll have to decide what we want.
> 
> Now let’s say we are just happy to know the number of times this bit has been indexed. My earlier macro got the topic array and when it saw that the array had more than one thing we stopped. Now what we’ll do is pile all the topic arrays the bit of text has (which will usually be none) in all indexes into the same array, and look how many topics that bit of text has in total. So we change the loop like this:
> $topic = Array.new
> foreach $indexName in $indexNames
>    $topic.appendValuesFromArray $attr.textIndexTopicsForStyleName($indexName)
> end
> 
> So first we create an empty topic array, then we pile in all the topics from the topic arrays for each index, and we get a combined array.
> Of course if your macro should distinguish different indexes (later?) then this might not be the best approach. On the other hand this macro would catch places that have been indexed *once each* in two or more indexes, which is something the other macro would not do.
> 
> Hope this is clear enough.
> Best
> Philip
> 
> 
>> 
>> Thank you so much again.
>> 
>> Best regard,
>> 
>> Nobumi Iyanaga
>> Tokyo,
>> Japan
>> 
>>> On Apr 13, 2016, at 12:31 AM, spaelti <[log in to unmask]> wrote:
>>> 
>>> Hello again,
>>> 
>>> Here is a macro which should do this, I think:
>>> 
>>> # Macro Select Next Multiply Indexed Item
>>> 
>>> $doc = Document.active
>>> $indexStyles = $doc.textIndexStyleNames
>>> 
>>> # Get the name of the index style
>>> $indexName = Active Text Index Name
>>> 
>>> # Go through the document and look for indexed items
>>> $sel = TextSelection.active
>>> $loc = $sel.bound
>>> $txt = $sel.text
>>> 
>>> while $loc < $txt.length
>>> $attr = $txt.attributesAtIndex $loc
>>> $range = $txt.rangeOfAttributesAtIndex $loc
>>> $topic = $attr.textIndexTopicsForStyleName($indexName)
>>> # If an indexed item is found, check if it is multiply
>>> # indexed and if so, select it and quit
>>> if Defined $topic
>>> if $topic.count > 1
>>> $indexed = TextSelection.new $txt, $range
>>> $doc.setSelection $indexed
>>> Prompt $indexed.substring, 'Indexed as :' & $topic
>>> Exit
>>> end
>>> end
>>> $loc = $range.bound
>>> end
>>> 
>>> # If nothing is found
>>> Prompt 'No indexed items found.'
>>> 
>>> # end of macro
>>> 
>>> best
>>> Philip
>>> 
>>> 
>>>> On Apr 12, 2016, at 17:32 , Nobumi Iyanaga <[log in to unmask]> wrote:
>>>> 
>>>> Hello all,
>>>> 
>>>> Another macro I would need is one which would find the next text in a document which is indexed with more than one "topic" (any topics). Is such a macro possible to create?
>>>> 
>>>> I would be very grateful to anyone (Philip, perhaps??) who would write a macro for this purpose.
>>>> 
>>>> Best regard,
>>>> 
>>>> Nobumi Iyanaga
>>>> Tokyo,
>>>> Japan
>>> 
>>> Philip Spaelti
>>> [log in to unmask]
>>> 
>>> 
>>> 
>>> 
>>> 
> 
> Philip Spaelti
> [log in to unmask]
> 
> 
> 
> 
> 

ATOM RSS1 RSS2