lib_set_mech_layers
Set, name, and enable mechanical layers in a specific library by path, with read-back verification to prevent edits from landing on the wrong library.
Instructions
Name, enable and kind the mechanical layers of one library.
WHY THIS EXISTS RATHER THAN THE pcb_* LAYER TOOLS. Those act on whichever board is current, and pointing them at a particular library depends on the focus actually moving. When it does not they operate on the previously focused library while reporting success: a sweep over twenty one libraries returned twenty one identical answers because every call had re-read the same file.
This takes the library by PATH and refuses unless the document that ended up focused is the one asked for. Acting on the wrong library is worse than not acting, because it looks like it worked.
Every change is READ BACK. A layer whose name, enable or kind did not take is reported against that layer rather than folded into an overall pass.
PAIRED KINDS. Any kind ending in Top or Bottom is held by the
layer PAIR rather than by either layer, under a shorter name with
the side dropped, so "Courtyard Top" is stored as the pair kind
"Courtyard". Assigning one therefore needs BOTH sides in the same
call: give the partner kind to another layer in layers and
the two are joined and the pair given the kind. Single kinds such
as "Fab Notes" need no partner.
Pair with lib_run_across to apply the same layer scheme to
many libraries in a single call.
Args:
layers: One dict per layer. Keys: layer (required, e.g.
"Mechanical13"), and any of name, enabled
(bool), kind (e.g. "Courtyard Top"). A layer with
none of the three is reported as nothing asked for.
library_path: The library to edit. Defaults to the focused
document, which is only safe for a single library.
tidy_pairs: Remove layer pairs no kind justifies. Altium
never drops a pair when a kind moves to other layers, so
a library reworked more than once accumulates pairs the
Layer Stack Manager still shows. A pair survives the
tidy only when its two layers carry kinds that are each
other's opposite side. Off by default, because it
REMOVES pairs and a caller renaming one layer should not
have the stack rearranged underneath.
timeout: Seconds.
Returns:
Dict with library, layers (each: layer, changed,
problem), changed, failed, kinds_displaced,
pairs_removed, pairs_tidied and pairs_scanned_to.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| layers | Yes | ||
| timeout | No | ||
| tidy_pairs | No | ||
| library_path | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||