Script variables¶
Eight names injected into every item script, describing the item that ran it.
The same reference is available inside the tool: the {} button in the script editor inserts any of them, and the header comment at the top of a new script lists them.
The list¶
| Name | What it is |
|---|---|
__CONTROLS__ |
The item's bound controls. Sets are returned as sets, not expanded |
__FLATCONTROLS__ |
The same, with sets expanded to their contents. Usually the one you want |
__NAMESPACE__ |
The picker's current namespace |
__SELF__ |
The PickerItem instance itself — colour, size, position, flags |
__UUID__ |
This item's id, the same string saved as item_uuid |
__ITEM__ |
Item helper — find and change other items |
__LAYER__ |
Layer helper — Am_Picker's own layers, not Maya display layers |
__INIT__ |
True while the picker is being built. Guard side effects with if not __INIT__: |
__CONTROLS__ and __FLATCONTROLS__¶
The difference matters when an item is bound to a Maya set:
# Item bound to "faceControls_set", which contains 40 controls.
__CONTROLS__ # ['kamal:faceControls_set']
__FLATCONTROLS__ # ['kamal:L_brow_ctrl', 'kamal:R_brow_ctrl', ...]
Both arrive with the namespace already applied, so you can pass them straight to
cmds without any further work.
Reach for __FLATCONTROLS__ unless you specifically want to operate on the set
object itself.
__SELF__ and __ITEM__¶
__SELF__ is the item running the script. __ITEM__ is a helper for reaching
other items, and __ITEM__.current is the same object as __SELF__.
| Call | Does |
|---|---|
__ITEM__.current |
This item — identical to __SELF__ |
__ITEM__.by_uuid("a1b2c3d4-…") |
Find an item by its id |
__ITEM__.all_pickers() |
Every item on the canvas |
__ITEM__.set_visible(target, on) |
Show or hide an item |
__ITEM__.is_visible(target) |
Query it |
The returned PickerItem exposes the same things the
Channel Box edits — colour, text, scale,
selectable, movable, z-depth, position, rotation:
# A button that hides a whole sub-board when clicked.
if not __INIT__:
board = __ITEM__.by_uuid("a1b2c3d4-5e6f-7890-abcd-ef1234567890")
__ITEM__.set_visible(board, not __ITEM__.is_visible(board))
# Make this item non-selectable once it has been used.
__ITEM__.current.set_selectable(False)
Getting a UUID
Select the item and press Ctrl+Shift+C — Copy UUIDs — then paste it into your script. Do not type them out.
__LAYER__¶
Am_Picker's own layers, as seen in the Picker Outliner. Nothing to do with Maya display layers.
| Call | Does |
|---|---|
__LAYER__.current |
The layer this item is on |
__LAYER__.names() |
Every layer name in the tab |
__LAYER__.set_visible(name, on) |
Show or hide a layer |
__LAYER__.is_visible(name) |
Query it |
# One button that turns the detail controls on and off.
if not __INIT__:
__LAYER__.set_visible("Tweakers", not __LAYER__.is_visible("Tweakers"))
This is a good pattern: a visible button on the canvas is far more discoverable than the right-click Layers menu, especially for a layer people toggle constantly.
__INIT__¶
True while the item is being created, false on a real click.
Its purpose is to stop a script from firing at build time. Without it, a script that resets a limb can run while the picker is loading:
Anything with a side effect belongs inside the guard. Reads and appearance changes generally do not need it.
__NAMESPACE__¶
The picker's current namespace, including its trailing colon when there is one, and an empty string when there is not — so it concatenates cleanly:
Use this rather than hard-coding a namespace. It is what lets the picker follow whichever copy of the rig the animator is working on.
MEL¶
MEL scripts get the same information. Choose MEL in the editor and the variables are made available in MEL's syntax.
For anything beyond a one-line command, Python is the better choice — the completion, the error messages and the variable helpers are all richer there.