Hi,
How can i change my tab selection by script way?
For example, in this image i have selected tab "a" and i want to select tab "c":
I need something like this:
var doc = getDocument("c");
var docIntfc = new RDocumentInterface(document);
But i dont know how it would correctly.
Many thanks.
Regards.
Tab selection
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Re: Tab selection
Code: Select all
// find out index of window to show (2 is an example here):
var index = 2;
var mdiArea = EAction.getMdiArea();
var windows = mdiArea.subWindowList();
mdiArea.setActiveSubWindow(windows[index]);
Re: Tab selection
Thanks for your answer, i need to program that in dinamically mode.
Is there a function to return current tab index? Example:
var index = getCurrentIndexTab;
//My code
var mdiArea = EAction.getMdiArea();
var windows = mdiArea.subWindowList();
mdiArea.setActiveSubWindow(windows[index]);
Regards.
Is there a function to return current tab index? Example:
var index = getCurrentIndexTab;
//My code
var mdiArea = EAction.getMdiArea();
var windows = mdiArea.subWindowList();
mdiArea.setActiveSubWindow(windows[index]);
Regards.
Re: Tab selection
You can get the current tab index using QTabBar:
Code: Select all
var appWin = RMainWindowQt.getMainWindow();
var tabBar = appWin.getTabBar();
var idx = tabBar.currentIndex;
Re: Tab selection
Hi, thank you, the code works. But in my application it doesn't close the exported file and it tries to close the initial tab.
I need to close (with CloseFile.js in my code) the exported file, it is not working correctly. If i omit the 3 last lines, it works ok.
Many thanks.
Code: Select all
include("../MyScripts.js");
// Constructor calls base class constructor:
function Extraer(guiAction) {
MyScripts.call(this, guiAction);
}
Extraer.prototype = new MyScripts();
Extraer.prototype.beginEvent = function() {
MyScripts.prototype.beginEvent.call(this);
var appWin = RMainWindowQt.getMainWindow();
var tabBar = appWin.getTabBar();
var idx = tabBar.currentIndex;
var action = RGuiAction.getByScriptFile("scripts/Edit/Cut/Cut.js");
if (!isNull(action)) {
action.slotTrigger();
}
var action = RGuiAction.getByScriptFile("scripts/File/NewFile/NewFile.js");
if (!isNull(action)) {
action.slotTrigger();
}
var di = EAction.getDocumentInterface();
var document = di.getDocument();
var op = new RPasteOperation(RDocument.getClipboard());
op.setOffset(new RVector(0,0));
op.setRotation(0.0);
op.setScale(1.0);
op.setFlipHorizontal(false);
op.setFlipVertical(false);
op.setToCurrentLayer(true);
op.setOverwriteBlocks(true);
//op.setCopyEmptyBlocks(true);
di.applyOperation(op);
di.autoZoom();
var file = new QFile("C:/Planning/Oferta.txt");
var flags = new QIODevice.OpenMode(QIODevice.ReadOnly | QIODevice.Text);
if (!file.open(flags)) {
this.terminate();
return;
}
var ts = new QTextStream(file);
ts.setCodec("UTF-8");
var line;
line = ts.readLine(); //Sólo necesito la linea 1.
file.close();
di.exportFile("O:/" + line + "/Temp/" + line + ".dxf", "DXF 2000");
var action = RGuiAction.getByScriptFile("scripts/File/CloseFile/CloseFile.js");
if (!isNull(action)) {
action.slotTrigger();
}
var mdiArea = EAction.getMdiArea();
var windows = mdiArea.subWindowList();
mdiArea.setActiveSubWindow(windows[idx]);
this.terminate();
};
Extraer.init = function(basePath) {
var action = new RGuiAction(qsTr("Extraer"), RMainWindowQt.getMainWindow());
action.setRequiresDocument(true);
action.setScriptFile(basePath + "/Extraer.js");
action.setIcon(basePath + "/Extraer.svg");
action.setStatusTip(qsTr("Extraer"));
action.setDefaultShortcut(new QKeySequence("z,z"));
action.setDefaultCommands(["extraer"]);
action.setGroupSortOrder(73100);
action.setSortOrder(400);
action.setWidgetNames(["MyScriptsMenu"]);
};
Many thanks.