Tinderbox Forum

Can Text collect children names and my notes?

I’d like to use collect(children,$Name).format("\n"); and include any notes I make in the text. Is this possible?

I’m currently using a rule on a prototype $Text=collect(children,$Name).format("\n");

When I try to append a note above or below the collected text it gets replaced, which makes sense given the above rule.

I assume you mean you are trying to edit the text ($Text) of a note whose $Text is already being set via a Rule.

No really. Every time the rule runs it adds the list of notes. You could have note where the text is you notes and a template added the child $Name into at the end in preview mode.

But, step back. What are you trying to achieve here? Often this scenario arises because we want to 'just" do one more thing and that feels like less work than starting over.

For a start, unless the child notes change a lot (e.g. by the minute) a rule is overkill and I’d move the code to an edict. Now it runs less often but still overwrites $Text. The problem is you want—I think—to keep your existing notes but add an updated list.

One solution. Plan to make your manual text editions at the top of text above and before a special delimiter which is a line (only) of characters . For sake of argument, we’ll use 8 hashes with a line break before after ######## , to give an easily seen boundary and a string of characters that should be unique with the overall $Text content.

Now our code can save the existing text (above the marker, add back the marker and add an updated child list. Like so (tested in v9.0.0):

$Text = $Text.split("########").at(0);
$Text = $Text + "\n\n########\n\n" +collect(children,$Name).format("\n");

The first action in the code saves the ‘text’. The second adds back the delimiter with a blank line before/after, and then a fresh extraction of child names is added.

If changes to children occur very infrequently you might also consider moving the code to a stamp and running it manual as/if/when required.

The key step here is having the special string of characters so the existing annotation test can be found and preserved and then re-united with an updated listing.

Does that help?

1 Like

Yes, you could to `$Text=$Text+collect(children.name).format("\n"). This will take your existing text and add the children beneath it.

1 Like

Note a problem with your approach is it just keeps adding a new list every time the rule fires, rather than preserving the text/annotation part of $Text and refreshing the list of children. After 50 runs of the rule. the note will have some text and 50 lists of child names. :wink:

1 Like

Thank you both! @mwra your example works quite well for my use case. I’m going to replace the hashes with a markdown rule --- and use it as a quickstamp for a few days, if it works well I’ll try it as an edict.

If you’re interested in my use case… Lately I’ve been writing my daily notes in a combination of outlines and in the text field. But I realized when I use the attribute browser to review it would be nice to see an overview of both at a high level (in this case parent note).

Not to be off topic but do either of you know if collect children can work recursively? (i.e., collect children of children) Perhaps I’m being greedy :wink:

1 Like

Have the children collect their children?

Or, collect(descendants,$Name) might be what you want!

1 Like

This worked splendidly, thank you!