sch-rnd scripting example: quick attr (assisted attribute edit)

<-- back to the index of scripting examples

#### quick attr (assisted attribute edit)

Quick attribute dialog for choosing the value of the tolerance attribute from a list of a few predefined values (e.g. 1% or 5%) for assisted attribute editing.

##### Example implementation

quick_attr.fawk

##### Explanation, step by step

Creates a quick attribute edit for the "tolerance" attribute and lets the user select from a list of a few common values (0.1%, 1%, 5%, 10%) using a GUI.

Registers the action quick_attr_tolerance() - because of the name of the action, the property editor and attribute edit dialogs will call this action when the user clicks on assisted edit.

When quick_attr_tolerance() is called, it first queries the original tolerance value using propget() and checks if the value is present in the array of known tolerances. If so, it saves the index of the value, because the enum widget communicates in integer indices. The same for loop also builds a flat list of values in a string for initializing the enum.

Next the dialog box is created using the DAD API. The change callback of the enum is made to call our own action qa_tolerance_remember() which is used to remember the last selected value in a script-global variable. After running the dialog box in modal mode (which is required by the quick attr infrastructure), set the new value as symbol attribute using propset(). The return value of the function is as defined by the quick attr infrastructure.

How to test:

- load the script
- place a resistor symbol
- hover over it and type {a t}
- select tolerance value, click OK
- open the attribute editor using {a a} (or from the right click menu on the symbol), look at the tolerance attribute, select it, click the floater
- clicking the assisted edit button while the tolerance attribute is selected will invoke the script too