This button lets you cycle through the layouts defined in Preferences / Layouts and Styles / Layouts. It shows the current layout as the label and the next and previous layout from the list as the tooltip. Layouts that sit in folders will be ignored.
Click the button to call the next layout. Hold Shift while clicking to open the previous layout.
The button for Opus 12 has the same functionality but lacks the dynamic info.
The script that runs in the background and supplies the layout info will work for all versions.
// For reference only. Get the fully functional button from below
// ** Opus 12 **
@keydown:none
Prefs LAYOUT="{$lst:nextLayout}"
@keydown:shift
Prefs LAYOUT="{$lst:prevLayout}"
// ** Opus 13 **
@label:cL=Val("$lst:currLayout");Format(original_label, (cL=="" ? "<none>" : cL))
Prefs LAYOUT="{=KeyDown("shift") ? Val("$lst:prevLayout") : Val("$lst:nextLayout")=}"
How to set up and use
Save EventSaveLayoutsAsVars.js.txt toββββ
%appdata%\GPSoftware\Directory Opus\Script AddIns
Copy-paste the button to any toolbar
Opus 12
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Cycle Layouts</label>
<tip>Call next layout (Shift to call previous)</tip>
<icon1>#layoutlist</icon1>
<function type="normal">
<instruction>@keydown:none</instruction>
<instruction>Prefs LAYOUT="{$lst:nextLayout}"</instruction>
<instruction />
<instruction>@keydown:shift</instruction>
<instruction>Prefs LAYOUT="{$lst:prevLayout}"</instruction>
<instruction />
<instruction>// https://resource.dopus.com/t/cycle-through-layouts/51223</instruction>
</function>
</button>
Opus 13
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>%1</label>
<tip>=Val("$lst:nextLayout") + "\n" + Val("$lst:prevLayout") + " (Shift)"</tip>
<icon1>#layoutlist</icon1>
<function type="normal">
<instruction>@label:cL=Val("$lst:currLayout");Format(original_label, (cL=="" ? "<none>" : cL))</instruction>
<instruction>Prefs LAYOUT="{=KeyDown("shift") ? Val("$lst:prevLayout") : Val("$lst:nextLayout")=}"</instruction>
<instruction />
<instruction>// https://resource.dopus.com/t/cycle-through-layouts/51223</instruction>
</function>
</button>
Things you might enjoy reading
Inspired by Hide Layout Buttons
How to use buttons and scripts from this forum
The script's inner workings
JScript
function OnInit(initData) {
initData.name = 'SaveLayoutsAsVars';
initData.version = '2024-06-11';
initData.url = 'https://resource.dopus.com/t/cycle-through-layouts/51223';
initData.default_enable = true;
initData.min_version = '12.0';
}
function OnActivateLister(activateListerData) {
if (!activateListerData.active) return;
var cmd = DOpus.Create().Command();
var stt = DOpus.Create().StringTools();
var vec = DOpus.Create().Vector();
var fsu = DOpus.FSUtil();
var lst = activateListerData.lister;
var xmlOrder = fsu.GetItem(fsu.Resolve('/dopusdata\\Layouts\\order.xml'));
if (!fsu.Exists(xmlOrder)) return;
var arr = stt.Decode(xmlOrder.Open().Read(), 'utf8').split('\r\n');
var re = /.*<layout name="(.*)" \/>.*/;
for (var i = 0; i < arr.length; i++) {
var tmp = arr[i].match(re);
if (!tmp) continue;
if (tmp.length != 2) continue;
var layoutName = tmp[1];
if (!fsu.Exists('/dopusdata\\Layouts\\' + layoutName + '.oll')) continue;
vec.push_back(layoutName);
}
if (vec.empty) return;
var currLayout = lst.layout;
var k = 0;
for (var i = 0; i < vec.length; i++) {
if (vec[i] != currLayout) continue;
k = i;
break;
}
var prev = k - 1;
if (prev < 0) prev = vec.length - 1;
var next = k + 1;
if (next == vec.length) next = 0;
lst.vars.Set('prevLayout', vec[prev]);
lst.vars.Set('currLayout', currLayout);
lst.vars.Set('nextLayout', vec[next]);
cmd.UpdateToggle();
}