Automate creating links to original's children within an agent map

I have a container of book notes, divided into Sections, like so:

I also have an agent which brings together all the notes descendedFrom the Notes container, so of course, the Sections and the notes are mingled together on the agent map, which is what I want.

In the map view of the agent, I can manually link each note’s alias to its aliased Section, like so:

But this gets tedious if there are many chapters and notes. I’d like to create a stamp which automates this: selecting a section alias would create the links to the aliases within this map, without affecting either the original sections or notes.

I’ve got as far as the simple stamp below, which creates links to the original, but of course that’s not what I want here.

$MyList=collect(children,$Name);
$MyList.each(X) {
linkTo(X)
}

Is there a way to amend this to create the links to the aliases within the agent, not to the original notes?

I assume it is possible, as I can do it manually, but I’m getting lost in the various permutations of alias-related actions…

Many thanks for any help!

I’d suggest this logic:

All section notes can be identified/filtered via a prototype.

Any note aliases in the agent map know that they don’t have the pSection prototype and that their section is the $Name of their original’s parent.

We need a link from each section TO each note of which it is a parent (in the outline)

For the stamp:

  • Add string attribute $Section. Add prototype ‘pSection’. Customise if you want, as it mainly marks sections distinct from non-section notes but give it OnAdd of : $SectionName=$Name(parent);
  • Set all Sections’ child notes to use prototype ‘pSection’. Promote/re-nest section’s child notes to fire the OnAdd. All notes part of a project now store their Section in $SectionName.
  • Agent query: descendedFrom(/Test/Notes) (no quotes as a literal path)
  • Make a list of $IDs all Non-section notes (could use a path but $ID avoids issues of two same-$Name notes:
    • var:list vList = collect_if(children,$Prototype!="pSection,$ID")
  • Iterate the list (list.each()) and use linkFrom() to make a link from [sic] the section alias to the in-loop currently processed alias.
    • The alias knows its section as it is $Name(parent(original)). Now we can match the sibling alias of that name as the source of the link

…but it turns out linkTo/From operators don’t operate as expected with aliases (or aliases inside agents). … omitting many things that didn’t work, assuming you set $SectionName as above, the stamp below works.

IMPORTANT: the stamp must be applied direct to the agent’s aliases and not via the agent. Why? This routes around a limitation of the existing linkTo(0/linkFrom() capability. The stamp is

if($Prototype!="pSection"){ // filter out section notes

   var:number vLinkSourceID;
   vLinkSourceID = collect_if(siblings,$Name==$SectionName(that),$ID);
   linkFrom(vLinkSourceID);

}

Result (on map with items manually arranged before stamp):

Tada!

In my demo doc linked below, I’ve now removed the links shown above. In the TBX ignore logs and stamps not recommended—I’ve burned loads of time to get to here so no time to prune testing extras. To try the code (in v10.1.2b710):

  • open the TBX
  • select all aliases inside the agent. IMPORTANT: don’t select the agent itself.
  • apply stamp “Link up sections 2” [sic] to the above selection.
  • switch to the map view tab of the document.

The TBX: alias-map.tbx (269.1 KB)

But I wanted to just stamp the agent!”. Indeed—well so did I, but to do that requires improvements to the current (v10.1.2) app. the above works today and selecting all the agent’s aliases isn’t such a big deal.

If I get some time I’ll address the linking limitations on the Backstage, so seasoned hands can check i’ve not missed something.

I’d envisaged a much simple—for the user—system not needing the prototype and user attribute and only needing to stamp the agent, but alas that needs functionality not currently in the app.

HTH. :slight_smile:

3 Likes

Hi Mark – thank you very much!

I’ve just got back in, so haven’t had time to look at it in detail, but I wanted to say thank you immediately – it looks like it took a lot of work to get there (and no wonder I got nowhere near!)

I’ll report back when I’ve had a chance to play.

Cheers!

1 Like

@mwra

Right, I’ve had a chance to dig into your solution and it works perfectly for what I need…

Thank you ever so much for spending the time to nail this down – I’ve learnt a lot and I really do appreciate your kindness!

1 Like

Happy to help. :slight_smile:

1 Like