Tinderbox Forum

Code to List and keep track of all my User Attributes much like a Registry?

I have always been hesitant of creating many user attributes. As my file has gotten older, I find the list growing. I currently, manually scroll the list, however this can be hit or miss.

Is there a more automated way using action code or workflow anyone has found to better keep track of their self created User Attribute list?

Thanks in advance
Tom

Actually, there is. You can run a stamp, $MyList = document["user-attributes"];. This will get you all the attributes in your document.

I don’t have time right now, but you could take this list, run another stamp that creates notes for each one and pulls in their type. You could then write a description in that newly crated not and they use yet another step to update the description of all your attributes, defaults, etc. I love where you’re going with this.

@satikusala has already mentioned document[" user-attributes"] to get a list of user attributes. We might then do ths in a new note (as it replaces existing $Text):

var vAttrList = document["user-attributes"];
$Text =;
$Text = "Number of user attributes: " + vAttrList.count + "\n";
var vAttrDetail = "";
vAttrList.each(anAttr){
   $Text = $Text + "\n" + anAttr + "\n";
   var vAttrKeys = attribute(anAttr);
   vAttrKeys.each(aSetting){
      $Text = $Text + "\t" + aSetting.replace(":",": ") + "\n";
   }
};

That just listed 70 user attribute in my current project (the first line of $Text is the count) with per attribute entries like this:

AltName
category: User
sequential:
default:
type: string
suggested:
description: This is used to store the $Name string where a suffix is needed in Tinderbox to ensure a unique $Path and $Name. IOW, $Name might be “Smith & Jones A” but in that case $AltName would be “Smith & Jones”. The AltName can be used when exporting data for other uses.

CitedCount
category: User
sequential:
default: 0
type: number
suggested:
description: Number of times a paper is cited (in conference).

Note that for reason’s I’ve not yet figured the ‘Suggested’ value item list prints one item per line.

See also:

HTH

1 Like

Wow…this was exactly what I was looking for MarkA and MichaelB.
Now the problem is understanding the code. I got lost when you began with the loop variables.
In addition, I assume “anAttr” is a self made name? I assume it can be named whatever you want?
Lost here:

var vAttrDetail = “”;
vAttrList.each(anAttr){
$Text = $Text + “\n” + anAttr + “\n”;
var vAttrKeys = attribute(anAttr);
vAttrKeys.each(aSetting){
$Text = $Text + “\t” + aSetting.replace(":",": ") + “\n”;
}
};

Will need to study
Thank you

Tom

One last question: I remember you mentioning on one of the meetups a methodology for automatically stopping an edict with code so that it only runs one time…much like a stamp. For some reason, I cannot find the code.

Thanks
Tom

At the last line of the $Edit put '$EdictDisabled=true;.

Thanks Michael. That helps. Trying to understand the MAGICAL MarkA code above.
Tom

OK, this is an annotated version of the above (from which I’ve deleted an unused variable declaration. Don’t run the version with annotation is (reason further below.)

I think where you are getting lost is the loop variable. It is just a name. I used ‘anAttr’ but it could be ‘x’ or "PlyerTwoHasLost’. It’s just a name you decide when you code the .each() loop. Thus in:

$MyList.each(blinken){

within the loop every case-sensitive use of the word ‘blinken’ (recall, it’s whatever you code), Tinderbox fetches the value of the current list item. so if the list is "ant;bee;cow’, on the first loop the value of blinken is ant, the loop iteration is it bee, etc. As the variable is case sensitive Blinken would hold no value as Tinderbox doesn’t know what that string is for. Remember you told Tinderbox that in this .each() loop that you wish are declaring blinken as the loop variable. You could have chosen x or HovercraftFullOfEels but you chose blinken, because you just did.

You may note that that I tend to use an ‘a’ or ‘an’ prefix to a word that indicates what the loop variable does.

The issue about not using the commented code is that the seem to be a few glitches where although the code colours correctly, Tinderbox is ‘seeing’ and acting on text in the comment. It will get reported. For now, I’d just keep commented and uncommented and run the latter!

Must dash, dinner guests arriving.

2 Likes

Very Helpful MarkA :wave: :pray: :smiley:

1 Like