Tinderbox Forum

Code to reset all local values of a prototype

TL;DR: is there code to reset all local values of a prototype?


Problem: I have changed the local values of many local values of a prototype. I’ve read Mark’s excellent article here on attributes. In step 13.3 I learned that I could use “Inherited Value” by adding the attribute in this case $Color and $Width into a local note

Screen Shot 2020-03-17 at 6.26.50 AM

and now I change use inherited value

Screen Shot 2020-03-17 at 6.17.19 AM

In order to do so I need to add the attribute to the note and right click. Does anyone have code or a for a faster method? I have changed width, length, color, and other things. If I had code I could stamp the notes or create an agent to find everything and clean things up.

In an effort to NOT over engineer from the beginning I’m testing out different attributes on local notes. Sometimes I want to add them to the prototype so all of the other notes would change.

Thank you

A related post: Reapplying prototypes

I believe in most cases

$Attribute=;

as a stamp will reset attribute values in a note to the Default, or if the attribute is assigned a value in the prototype for that note, the value in the prototype.

Thanks Paul. It worked for $Color, but not for $Width. I’m looking for a command to blow out all local attributes.

It might be easiest for me to just start new notes. Thanks,

This isn’t an automated solution, but the Get Info pop-up (opt-cmd-i) lists all the attributes that have local values in bold. If you right click on a bolded attribute name you get a single-item contextual menu that lets you use the inherited/default value. It’s pretty easy and quick to scroll through the pop-up listings and restore everything to defaults this way.

Happily, Tinderbox has a useful action code operator for this very problem: hasLocalValue(). But there is also a way to purge local values down the inheritance chain:

First fix the prototype, as described above, so that it is showing/inheriting the values. Now give the prototype an edict. There may be a lot of notes but we only want to fix them once, so a rule or agent action is overkill. $Edict code (add to existing code if there is an edict already):

if($IsPrototype==false){
   if(hasLocalValue("KeyAttributes"){
      $KeyAttributes=;
   };
   $KeyAttributes.each(X){
      eval("$"+X)=;
   }
};

Grr, no go. It seems I can’t create an attribute reference on the fly. Perhaps AppleScript.. Solution, see post further below (here)

I appreciate all of the help. I think I need to go back into the shallow end and just change one note at a time.

I’d go with @PaulWalters earlier solution and just set each KA attribute to =; to ‘reset’ it. So, if the KA were Color, Pattern and Width, then this code will work as a agent action, stamp, etc.

$Color=;
$Pattern=;
$Width=;

obviously, just add extra attributes, one entry for KA. They don’t need to be on a line each, I’ve just put it that way for clarity here.

If I find a fix for a more automated route, i’ll add it here.

1 Like

Note, by the way, that a few special attributes, called intrinsic attributes, always have local values and don’t inherit from the prototype. $Container, for example, isn’t inherited; if it were, all instances of a prototype would move to the same container. $Xpos isn’t inherited; moving a prototype doesn’t move every instance.

I mention this because $Width is one of the intrinsic attributes.

1 Like

Again, love this community. I learned a new trick today. I don’t have a lot of attributes that I’ve changed, but the @PaulWalters trick confirmed by @mwra helps a lot particularly when combined with an agent action.

I believe that I’ve changed intrinsic attributes with a specific agent action such as $Width=“10”

Sure — you can change intrinsic attributes in all sorts of ways! But they aren’t inherited from prototypes.

1 Like

Thanks to a reminder from @eastgate, here is a Key Attributes reset action (I’ve confirmed this works in v8.6.2b452:

$KeyAttributes.each(X){
   action("$"+X+"=;");
}

So rather an an eval() call we use action(), albeit unusually within an action. Note that the action wraps a complete action: "$X=;", where X is a variable. If the action being instructed needed a string, use nested quotes.

For example, lets assume our KAs are all multi-value (i.e. list-based List or Set type) attributes and we want to add a string value of test for each of our KAs, the action would be:

action("$"+X+"=$"+X+"='test';");

or

action('$'+X+'=$'+X+'="test"=;');

I’ve done it to show two alternate. First, using double quotes to make the action string and single quotes for quoted strings within that. In the second case the reverse the role of the single and double quotes. Both work. Just make sure you close nested quotes and balance out your sets of quotes (i.e. they all have and open and a close).

I’ll add this into aTbRef in due course but wanted to note it here as I’d failed to make it work in an earlier post (up-thread)

2 Likes

I forgot to mention, the prototype/edict related part of the above. You can either run the KA reset action as the prototype’s edict, though if you’ve configured any KA table value in the prototype you’ll need to re-set them after the edict has been run and then removed.

Or, enclosed the code in a test so it doesn’t run in the prototype itself:

if($IsPrototype==false){
   $KeyAttributes.each(X){
      action("$"+X+"=;");
   }
}

For large numbers of effective notes, letting this run as a prototype edict and then deleting the (prototype’s) edict is probably a bit quicker than a stamp and less fiddly than setting up an agent. But as ever, there are multiple ways to effect the task. Pick one that suits your working style.

1 Like