Automatic numbers lost in sort Table

Everything related to our flagship word processor.
Post Reply
withoutFeathers
Posts: 89
Joined: 2013-03-19 16:22:50

Automatic numbers lost in sort Table

Post by withoutFeathers » 2019-07-08 10:55:35

Hi,
I'm attempting to put a column of automatic numbers in a Table, each representing a 'Scene #' in a long book, which I was hoping to use to re-sort the table into that order again later. They add nicely and quickly in the column.

However, if I then sort the table by another column (say, 'number of words in scene') then the automatic 'Scene #' column loses its numbers; instead they get re-formulated into the new order after the 'number of words' sort, starting from the top.

My hunch is this problem is unsolvable, but perhaps there's a workaround.

To clarify, restated:
I want to use automatic numbers because I have a table that's 130 rows long whose number of rows will be changed during my editing process, as I define new scenes; I want to add a row here or there, or take one out, and I'd like the automatic numbers column to self-adjust, so the numbering is always accurate.

But as I said, if I sort the Table by any other column, then I can't use the Scene # column to sort it back (which is what it's there for, hopefully), because the numbers all update themselves to the new sort and the original sequence is lost.

I know I can do this by adding all the Scene # numbers by hand, but that is painful because then if I add or delete one, all the others need to be updated by hand. So I'd like auto-numbers if possible.

?

wF

Þorvarður
Posts: 277
Joined: 2012-12-19 05:02:52

Re: Automatic numbers lost in sort Table

Post by Þorvarður » 2019-07-09 08:15:13

Hi,
I'm attempting to put a column of automatic numbers in a Table
Let's begin by clarifying the terminology. Automatic Numbers in NWP are here: Insert –> Automatic Number. In your case, however, it seems you are not using automatic numbers, but rather a list style to generate numbers. That's why (the list) numbers always appear sorted ascending.
but perhaps there's a workaround
Yep. Use real numbers instead.
I know I can do this by adding all the Scene # numbers by hand, but that is painful because then if I add or delete one, all the others need to be updated by hand
If you are talking about numbers generated by a list style here, then you only need to select the cells in the scene # column and then choose the list style from Format –> Lists –> Scene # (where "Scene #" is a list style that you created for this purpose.) Or, alternatively, select the style name in the List palette, and your scene # column will be magically updated, all in one go. (See screenshot no. 2)

2.png
2.png (49.56 KiB) Viewed 3144 times

But as I already said, a better approach is to use real numbers. (See screenshot no. 1)
1.png
1.png (69.29 KiB) Viewed 3144 times

You don't need to enter the numbers by hand; use a macro to do this automatically.
Here is a macro that does this for you. If you add or delete rows, then just run the macro again and it will update all the numbers.
Attachments
Insert numbers in 1st column with various beginnings.nwm.zip
(9.63 KiB) Downloaded 64 times

withoutFeathers
Posts: 89
Joined: 2013-03-19 16:22:50

Re: Automatic numbers lost in sort Table

Post by withoutFeathers » 2019-07-09 10:41:14

Hi,
You don't need to enter the numbers by hand; use a macro to do this automatically.
Here is a macro that does this for you. If you add or delete rows, then just run the macro again and it will update all the numbers.
Thanks and that's great but introduces a new problem: the sort of the Scene1 etc. doesn't return to that order. Apparently the re-sort doesn't follow the numbers correctly.

That is, the main reason I want this scene # list is so I can re-sort to that sequence after I've sorted for '# of words' or any other criteria.
But after I downloaded and ran the macro, which beautifully made a list of Scene numbers in column 1, when I:
a. Sort for number of words.
b. Then sort again for Scene # to return to sequential, I get:
Resort of 1st column -- Screen Shot 2019-07-09 at 11.33.14 AM.png
Resort of 1st column -- Screen Shot 2019-07-09 at 11.33.14 AM.png (15.31 KiB) Viewed 3130 times
As you can see, the numbers do not sort correctly, since they should go from 1 to 134, in sequence.

Can this macro be edited to produce numbers in a way that will sort in sequence in the table?

I don't really need the word 'Scene' at the start, would tha help? Or using 1.1, 1.2, etc.? Or some other workaround?

wF

User avatar
phspaelti
Posts: 1022
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Automatic numbers lost in sort Table

Post by phspaelti » 2019-07-09 16:01:35

withoutFeathers wrote:
2019-07-09 10:41:14
I don't really need the word 'Scene' at the start, would tha help?
Exactly. "Numbers" of the form "Scene 1" are sorted alphabetically. So "Scene 101" will precede "Scene 25" which will precede "Scene 9". They would need to be 0-padded to sort correctly. But if you remove the "Scene " then they will sort as numbers.
philip

adryan
Posts: 305
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Automatic numbers lost in sort Table

Post by adryan » 2019-07-09 23:15:28

G’day, wF et al

And when you’ve finished all your sorting, you can, if you wish, reinstate the “Scene” appellation.

On occasions, it can be useful to employ a little sorting trick that Nisus Writer makes very easy. The idea is to permute the order of substrings in a string, perform the sorting operation, and then permute the substrings back to their initial order.

In the present instance, you might transfer the word “Scene” from the beginning of the expression to the end of it before performing the sorting operation, then transfer it back again later. Depending on your requirements at the time, you may need to pay due attention to the spacing. The whole procedure is very easily incorporated in a macro.

This trick can be particularly useful in “sorting by column” a slab of tab-delimited text that you have not incorporated in a table as such.

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

Þorvarður
Posts: 277
Joined: 2012-12-19 05:02:52

Re: Automatic numbers lost in sort Table

Post by Þorvarður » 2019-07-10 05:19:27

withoutFeathers wrote:
2019-07-09 10:41:14
Can this macro be edited to produce numbers in a way that will sort in sequence in the table?
Yes, just remove "Scene " & from the macro.
Turn line numbers on, and you'll find the string on line 16 and 23.

Remove scene.png
Remove scene.png (49 KiB) Viewed 3084 times

Þorvarður
Posts: 277
Joined: 2012-12-19 05:02:52

Re: Automatic numbers lost in sort Table

Post by Þorvarður » 2019-07-10 06:16:46

One additional suggestion. One could create a column to the left of the numbers and fill it with the word "Scene"; then remove the right table cell boarder of that column by setting the Edge Option in the Table Cell Borders palette to None; and finally merge the two first cells of the first row. To influence the space between the word "Scene" and the numbers I used the additional padding options and entered 4 pts for the left. All this makes "Scene" and the following numbers look like just one column.

The sort order should be correct, and you can keep the word "Scene" without it interfering with the sorting.
Two columns.png
Two columns.png (44.52 KiB) Viewed 3079 times
And you can use the same macro, slightly altered, to fill the first column with the word "Scene".
Attachments
Enter %22Scene%22.nwm.zip
(9.63 KiB) Downloaded 53 times

withoutFeathers
Posts: 89
Joined: 2013-03-19 16:22:50

Re: Automatic numbers lost in sort Table

Post by withoutFeathers » 2019-07-10 08:34:52

Þorvarður wrote:
2019-07-10 05:19:27
withoutFeathers wrote:
2019-07-09 10:41:14
Can this macro be edited to produce numbers in a way that will sort in sequence in the table?
Yes, just remove "Scene " & from the macro.
Turn line numbers on, and you'll find the string on line 16 and 23.


Remove scene.png
Excellent. This works as you say, and solves my problem.

And I see how I can put "Scene" in front by having two columns, which is also nice, but as a working document I really only need to put the "Scene #" at the top to remind myself of what these numbers are for, with a note there to redo the macro when there are row changes. But might use that in future if I need to distinguish among columns.

Thanks!

wF

Þorvarður
Posts: 277
Joined: 2012-12-19 05:02:52

Re: Automatic numbers lost in sort Table

Post by Þorvarður » 2019-07-10 09:15:56

adryan wrote:
2019-07-09 23:15:28
In the present instance, you might transfer the word “Scene” from the beginning of the expression to the end of it before performing the sorting operation, then transfer it back again later. […] The whole procedure is very easily incorporated in a macro.

I like this idea, Adrian. :D

I was able to swap "Scene" and the numbers using Find and Replace and the following string as options argument: 'eSa'
The last macro line, however, containing the sorting command [Edit:Sort Paragraphs:Descending (Z-A)] was never carried out. I'm not sure why. It's as if the macro always stopped after Find and Replace.

How would you write such a macro?

PS
I found a swap Array Object Command in the Macro Language Reference, but I was unable to find any examples or further explanation of how to use it.
.swapValuesAtIndexes index1, index2

Can this command be used here? I guess I have to substitute index1 and index2 with numbers. But what numbers?
Can anyone shed light on this?

adryan
Posts: 305
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Automatic numbers lost in sort Table

Post by adryan » 2019-07-10 14:01:12

G’day, Þorvarður et al

I see that you are using the “S” option in the expectation that (as the Macro Language Reference implies) you will have something selected that the Sort command can work with. That doesn’t work for me, so I don’t know whether that’s a Nisus bug or just something I don’t understand properly.

The following macro code (using PowerFind Pro, hence the “E” option) works for me:–

Code: Select all

Find and Replace "Scene (.+)", @Text<\1 Scene>, 'Ea'
Select All
Sort Ascending (A-Z)
Find and Replace "(.+) Scene", @Text<Scene \1>, 'Ea'
It assumes it is operating on a whole file rather than on a selection therein.

I hope this helps.

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

Þorvarður
Posts: 277
Joined: 2012-12-19 05:02:52

Re: Automatic numbers lost in sort Table

Post by Þorvarður » 2019-07-12 23:32:51

This works well. Thank you Adrian.

adryan
Posts: 305
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Automatic numbers lost in sort Table

Post by adryan » 2019-07-13 16:22:15

G’day, all

For those (like myself) who may baulk at using the full Macro Language for such things, an easy and straightforward way to preserve selections during complicated Find/Replace operations is to use one or more Clipboards.

Select your chunk of text (eg, tab-delimited columns) in the original document, nominate a Clipboard to be the current one, Copy the selection to the nominated Clipboard, then invoke the Edit Current Clipboard command. Perform your text manipulations in that Clipboard document before Pasting its contents back into your original document, overwriting the original selection. Remember to reinstate your original Clipboard if necessary. This approach could be nested as often as required. Again, the whole procedure is readily incorporated into a macro by the addition of those few simple commands.

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

Post Reply