Right - I had action.setRequiresDocument(false), but the script specified in RGuiAction.getByScriptFile() would still only run on the final window.
Adding QCoreApplication.sendPostedEvents(appWin) inside the for loop forces the execution of the action on the proper sub window.
I've reverted back to action.setRequiresDocument(true) because the script shouldn't be run without at least one document open.
Changing scriptFile allows you to run a different script on each open drawing.
include("../BCS.js");
// Constructor calls base class constructor:
function TestAction(guiAction) {
BCS.call(this, guiAction);
}
TestAction.prototype = new BCS();
TestAction.prototype.beginEvent = function() {
BCS.prototype.beginEvent.call(this);
var appWin = EAction.getMainWindow();
var mdiArea = EAction.getMdiArea();
var windows = mdiArea.subWindowList();
for (var i=0; i<windows.length; i++) {
var window = windows;
var file = window.getDocument().getFileName();
window.showMaximized();
mdiArea.setActiveSubWindow(window);
//~ var scriptFile = "C:/Program Files/QCAD/scripts/BCS/DrawOneLine/DrawOneLine.js";
var scriptFile = "C:/Program Files/QCAD/scripts/File/CloseFile/CloseFile.js"
var action = RGuiAction.getByScriptFile(scriptFile);
if (!isNull(action)) {
action.slotTrigger();
QCoreApplication.sendPostedEvents(appWin);
EAction.handleUserMessage("closing: " + file);
}
}
}
TestAction.init = function(basePath) {
var action = new RGuiAction("&TestAction", RMainWindowQt.getMainWindow());
action.setRequiresDocument(true);
action.setScriptFile(basePath + "/TestAction.js");
action.setDefaultCommands(["TestAction"]);
action.setGroupSortOrder(80100);
action.setSortOrder(200);
action.setWidgetNames(["BCS"]);
};