Creating an auto-incrementing stamp

I created some attributes, $ChapOrdOrig, $ParagOrdOrig, $ChapOrdRev, and $ParagOrdRev, The purpose if to memorize the original order of my content and the second is to view paragraphs in a revised order. Creating the Chapter stamp was easy, but I cannot figure out the best way to auto-increment a selected group of notes, e.g., select 25 notes and have the stamp populate $$ParagOrdOrig automatically from 1-25. Suggestions? I’ll be changing doing this for each chapter set of $ParagOrdOrig.

Also, since I don’t want duplicates, I’m guessing I should make the number part of a set.

Thanks! – Bruce

Hey @bmgphd, without seeing the data structure, this can be a bit of a tricky answer to give. However, I’ve relied on $SibilingOrder when faced with similar needs and when my notes are all in one container. Before you move your notes around, you apply the sample $ChapOrdOrig=$SiblingOrder. Later, you can sort on $ChapOrdOrig, or you can revert back by applying the stamp $SiblingOrder=$ChapOrdOrig. Basically, you reverse the process.

Again, there are aways to automate this further. I’m not sure what you’re trying to do with …OrdRev.

If you can use $SiblingCount, that’s easiest.

But let’s suppose that the ~25 selected notes might not be siblings at all! Here’s one approach.

A Nook
You want a place where you can keep a number. I’m going to use a note /Config/Counter and its $MyNumber attribute. You could use a different note, or a different attribute.

The General Approach
When several notes are selected, the stamp is called on each note in turn. We’ll assign the value:

$ChapOrdOrig=$MyNumber(/Config/Counter);

and then we’ll increment the counter.

$MyNumber(/Config/Counter)=$MyNumber(/Config/Counter)+1;

Cleanup
I suppose that, if you apply the stamp several times, you want to start out at 0 (or 1?) every time, rather than continuing with bigger numbers. This is slightly tricky, because the stamp is called separately for each selected note. So we need to know when we’re at the end, and go back to zero if we are.

$MyNumber(/Config/Counter)=$MyNumber(/Config/Counter)+1;
if ($MyNumber(/Config/Counter)>=$SelectionCount-1) {
     $MyNumber(/Config/Counter)=0;
    }

Note that I’m ordering the 25 items with 0-24. You could start with 1-25, in which case you test for $MyNumber(/Config/Counter)>=$SelectionCount and reset the initial value to 1. In that case, you also need, on the first run, to detect that $MyNumber==0 and, if that’s true (meaning you’ve never used the stamp), set the value of $MyNumber to 1.

1 Like

Thanks Mark and Michael for the helpful suggestions. I’m going to play with both of them. I should have included more information. I’m trying to hard-code different view of my chapters and paragraphs, sorting by relevant attributes and then tracking the order. I made a short video that shows what I’m trying to accomplish.

And yes, I do want to be able to start the stamp over at 1.

Appreciate the suggestions.

Bruce

1 Like

Bruce, let’s review this on Friday in the Tinderbox 101 class. :slight_smile: