Load packages the script depends on:
-
[actions] for registering the new action;
-
[layout] for searching selected objects and moving objects.
Create a function ev_action that will be called when any of
the actions registered by the script is executed. The script registers
only one action, so it does not need to check which action caused
the function to be called.
When the action event is called, first set up:
- fetch event argument 0 and 1 using
[action_arg];
- resolve the conversion rate from mm to PCB's units using
[mm2pcb_multiplier];
- perform a search for all selected object using
[layout_search_selected] (return value is the number of objects found), name the resulting list "mv_search"
A loop then iterates over the objects on the list:
- resolve the Nth element of the list using
[layout_search_get], referecing the list by name ("mv_search") and specifying which element to get (the Nth); the result is an object pointer;
- move the object using
[layout_obj_move]; specify the object pointer, then which part of the object should be moved ("OC_OBJ" means the whole object) and relative offsets (dx and dy calculated earlier)
Finally the search list shall be destroyed to reclaim memory, using [layout_search_free].
In the "main" section of the script, bind event [ACTE_action] to
our local function ev_action - this gets ev_action to
be called when any of the actions registered by this script is executed.
Finally use [action_register] to register the action:
- first argument is the name of the action
- second is the xy query string; it is empty since this action won't need coordinates to operate on
- third is the description that shows up in dumps and helps
- fourth is the syntax description (also for helps)