Creating a "generic" agent to count notes with attribute various values

Hello,
My context is this: I have a script with scenes and each scene has a location.

I want to get a status of all occurrences of all locations:
3 scenes occur in Loc A, 2 scenes occur in Loc B…

Currently I do that “manually” by creating one agent per Location:
Agent Loc A = descendedFrom(“/Scenes”)&$MyLocation.contains(“Loc A”);
Agent Loc B = descendedFrom(“/Scenes”)&$MyLocation.contains(“Loc B”);

These agents are in a container so I can plot them or sort their displayValue by childCount.

It is not that painful but I don’t know all of my locations yet and I could need this process for attributes with many more values.

I tried the following code - it does not work and does not feel right as it should first create a Note with the Location Name then link the necessary notes in it.

Then again what would happen to those notes on the next run if, for example, a location were renamed?

(db enclosed).
TestLocations.tbx (103.1 KB)

if(descendedFrom(“/Scenes”)&!$MyLocation.empty;) {
var: string res = $MyLocation;
$MyLocation.contains(res); //
}

Any pointer most welcome.
Regards,
Philippe

I think a simpler way is here: TestLocations2.tbx (155.9 KB)

Give both locations and scenes a prototype. this makes it easy to find them (by $Prototype value) and to set rule, edicts, etc for them.

Now we give the ‘pLocation’ prototype this edict:

$Scenes = collect(find($Prototype=="pScene"&$Locations.contains($Name(that))),$Name);

This finds the $Name of any scene (and only scenes) whose $Location’s values match the $Name of this location note.

Just as you don’t want 00s of agents, the same applies to rules. Edicts generally run when needed and can be refreshed on demand. as the code above is in the prototype, any new location note gets this edict so there is no configuration to do.

Another approach is to link scenes to all the location(s) they use and get the edict to check for links of the appropriate type and source…

2 Likes

Another approach might be to use attribute browser, looking inside /Scenes and browsing $MyLocation

1 Like

Yes, this is a good approach, but you could also consider leveraging linking, specifically .link operators. This would enable you to populate locations every time you linked them to a scene. Also, once you have the links, you can leverage the hyperbolic view and map view to create visual associations. If this is of any interest, we can explore this angel, but what @mwrw has suggested works great as well.

1 Like

@satikusala - thank you - need to study linking.

@mwra - many thanks for the help and db - will definitely try that.

@eastgate - thank you - I have not spent any time with the attribute browser but certainly will change that.

We can include this as an exercise to go through during this Study’s meetup. :slight_smile:

1 Like

I’ll join if I can.

Great. It will be recorded, so you could watch it later too. :slight_smile:

1 Like

Yes, useful to explore as this is a useful view still a mystery to many (in part because it yields most from deliberate use of (typed) links).

2 Likes