<-- back to the index of scripting examples

#### Auto-place missing labels

Place text objects (dyntext floaters) displaying the name of wire-nets and symbols if they don't have it already.

##### Example implementation

autolabel.fawk

##### Explanation, step by step

Place text objects (dyntext floaters) displaying the name of wire-nets and symbols if they don't have it already.

The action creates a list of objects using query(), including only selected or all objects, depending on scope. This list is then searched through for:

- a group with role=symbol or role=wire-net
- else any object whose parent is such a group

Matching groups are collected in GRPS[] by their idpath. When child objects are found, they are checked for two things:

- when text: if it's a dyntext printing the name of the group, this is noted in the GRPS[] array (value 1) so a redundant label is not auto-created
- when line: the center point of the longest line is remembered per group in LINE[]; this is where a wire-net label is placed

At the end of the action a second loop iterates over the collected GRPS[] and calls the helper function autolabel_grp() on the ones that need a label. The helper function then will create the text object for the label. The new text object is created within the (symbol or wirenet) group.

How to test:

- load the script
- place a few symbols, delete theyr labels
- draw a few nets, name them, but do not place floaters on the name
- select nets and symbols
- invoke the script from menu or with hotkey {p s a} or using action AutoLabel(selected)
- labels are placed on wires and symbols that did not have floaters with their name attribute